Home | IBM Manuals Direct | iBytes Library | Links | About | Book Store | On-Line Code |
iByte Subject – Using built in function %LEN to determine the length of a string Using %LEN to find data length. In iByte #6 we talked about using the CHECKR command to find the length of data in a field. In iByte #7 we’ll explore using the built in function %LEN. We can use %LEN combined with other built in functions for more versatile code. Looking at the CHECKR example we see that the data in field HOLIDAY has a length of 28. DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++ D @SIZE S 3 0 INZ(000) D Holiday S 50 CL0N01Factor1+++++++Opcode&ExtExtended-factor2+++++++++++++++++++ C ' ' CHECKR Holiday @SIZE
12345678901234567890123456789012345678901234567890 'Festivus for the rest of us! ' @SIZE would be returned with a value of 28.
%LEN Now let’s look at this a little differently. Say the field HOLIDAY contained (notice the blanks to the right).... 12345678901234567890123456789012345678901234567890 ' Festivus for the rest of us! ’ Although the actual length of the string is 28, CHECKR would return a value of 38. This is because CHECKR will return the first non blank position moving from right to left in the example above. Using %LEN and %TRIM we can account for the blanks on the right and left of the data. The example below would return the data length desired - 28. CL0N01Factor1+++++++Opcode&ExtExtended-factor2+++++++++++++++++++ C EVAL @SIZE = %LEN(%TRIM(HOLIDAY)) |