Difference between VARYING and *VARSIZE IN RPGLE
This document describes the difference between VARYING and *VARSIZE in RPGLE.
Resolving the problem
VARYING is used on the D-Specs with character, graphic, and UCS2 fields to define them as having a variable-length format. This means that the field defined will have a 2-byte integer field appended to the beginning of it that will contain the length of the data that is valid in the data portion of the field. For example:
D Chr1 s 10A varying inz('ABCDEFGHIJ')
In storage, the contents of the variable might look similar to the following: 000AC1C2C3C4C5C6C7C8C9D1
The 000A is the hex representation of the integer value for decimal 10 that represents the length of the valid data in the data portion of the field. The C1 to D1 is the hex representation of the characters A to J. Now, if on the C-Specs we did an assignment as follows:
C Eval Chr1 = 'xyz'
In storage, the contents of the variable might look similar to the following: 0003A7A8A9C4C5C6C7C8C9D1
Moving field Chr1 to another character field defined as 10 characters would result in the field containing the following in storage A7A8A940404040404040.
*VARSIZE is used to describe the type of parameter that is allowed to be passed to a prototyped procedure. It can be used only with character, graphic, or UCS2 parameters that are passed by reference or read-only-reference (CONST). If the prototype of the parameter specifies a length of 10, on the call to that procedure you may pass a variable or expression that results in a length greater than, equal to, or less than the specified length of 10 when *VARSIZE is also specified on the prototype of the parameter. If *VARSIZE was not specified on the prototype of the parameter and the variable or expression length used on the call to the procedure was not equal to prototyped length, a compile time error message is issued.
* This prototype for QCMDESC defines three parameters:
* 1- a character field that may be shorter in length
* than expected
* 2- any numeric field
* 3- an optional character field
D qcmdesc PR EXTPGM('QCMDEXC')
D cmd 3000A OPTIONS(*VARSIZE) CONST
D cmdlen 15P 5 CONST
D 3A CONST OPTIONS(*NOPASS)
More support for:
Programming (Languages- compilers- tools)
Software version: 5.3.0, 5.3.5, 5.4.0, 5.4.5, 6.1.0, 7.1.0
Operating system(s): IBM i
Reference #: N1016816
Modified date: 2012-04-23