Character fields of unequal length are aligned to their leftmost character, then the shorter field is padded with spaces to equal the length of the longer field. Then the (now) equal length strings are compared.
You normally wouldn't trim a literal; just change the literal. But if you %trimR(FIELD), that could cost more in many cases. If you have %trimR(FIELD) = 'CORPORATE'...
FIELD contains 'CORPORATE'; trim does nothing, they're equal length, so no padding; they're equal
FIELD contains 'CORPORAT'; trim does nothing, FIELD gets padded to 'CORPORAT ' because it's shorter; they're not equal
FIELD contains 'CORPORATE '; FIELD is trimmed to 'CORPORATE', they're equal length, so no padding; they're equal
FIELD contains 'CORPORATEX'; trim does nothing, the literal gets padded to 'CORPORATE '; they're not equal
FIELD contains 'CORPORATEX '; FIELD is trimmed to 'CORPORATEX', the literal gets padded to 'CORPORATE '; they're not equal
Even with the trim, there's still going to be padding before comparison in many cases. I guess it could cut down on how much padding is needed, but I'll posit that adding the extra padding is probably less expensive than doing the up front trim.
Fixed length vs. variable length FIELD shouldn't make any significant difference. Instead of padding to the fixed length, it pads to the current length.
In addition to what Dale said, I have to ask: Are you really seeing code like that? Or is this just an ad hoc example meaning you see a lot of %TRIM(....) in code and wonder if it make any difference.
In general, each %TRIMx causes the compiler to generate code that removes the trailing characters and copies the result to a work field. So yes, it is slower to use %TRIMx than to not use it.
I am seeing code like this in some new development that we are doing. Other programmers are using it. I do not and agree that it is not necessary and CPU expensive. Testing for the value of 'CORPORATE' in a char(20) will succeed w/o a need to %trim it. It seems to be used by programmers who also code in Java.
I just thought it seemed unnecessary and weird to the eye to see it.
Thanks gentlemen for your help and input.
George, then what you are seeing (your JAVA ref) is programs who think "XXX " is different from "XXX".