Compare these two assignments using a fixed-length field and a varying-length field. If fixbuffer and varbuffer both start out with 'start value', they both end up with 'start value more data', but the assignment using fixbuffer takes much longer.
D varbuffer s 65535a varying
fixbuffer = %trim(fixbuffer) + ' more data';
varbuffer = varbuffer + ' more data';
The operation of %TRIM requires searching from the end of the string for a non-blank character. If your variable is long, this search can take a fair amount of time when the data is short. Since the varying-length field keeps the current length of the data in the first two bytes of the variable, you don't need to do the %TRIM to locate the end of the string.
I did a little casual test where I did the following 100 times: start with an empty 65535A string and append 'a' 100 times. Using a fixed-length string, it took 40 seconds. Using a varying-length string, it took less than .01 second.
To make a more typical test, I reduced the length of the variable to 1000 and increased the length of the string being appended to 80; to get a reasonably long run, I did 100,000 iterations. Using a fixed-length string, it took 36 seconds. Using a varying-length string, it took 1 second.
Barbara Morris joined IBM in 1989 after graduating from the University of Alberta with a degree in computing science. Within IBM, she has always worked on the RPG Compiler team. You can contact Barbara at This email address is being protected from spambots. You need JavaScript enabled to view it..
LATEST COMMENTS
MC Press Online