Explain the use of varying
keyword in rpgle. How does this affect the declaration of character variables in the RPGLE program in the AS400 system?
Please provide an example of using the VARYING keyword in the RPG program and what are the benefits of using the VARYING keyword.
Varying keywords are used in D specs with character, graphic, and UCS-2 fields to make them variable-length fields. A 2-byte integer field gets added at the start of the field using the VARYING keyword. That 2-byte integer contains the length of the data in the varying field. For example,
In storage, the data in hex format would look like 0004E3C5E2E3404040404040. Here, 0004 is the hex value for decimal 4 that represents the length of data in the fld1. Hex value E3 is character ‘T’, C5 is ‘E’ and E2 is ‘S’, and 40 is space.