Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
Is there really any difference in performance when you use the second "If" test below?
The length of FIELD is char(20).
I'm beginning to see the second version being used a lot and am wondering if the operation is really useful.
Thanks
GF
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'...
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.
GF
George, then what you are seeing (your JAVA ref) is programs who think "XXX " is different from "XXX".
In Java and C, it is, in RPG it is not.