Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

VARYING, VARYINGZ, and NONVARYING attributes

The VARYING and VARYINGZ attributes specify that a variable can have a length varying from 0 to the declared maximum length. NONVARYING specifies that a variable always has a length equal to the declared length.

The storage allocated for VARYING strings is 2 bytes longer than the declared length. The leftmost 2 bytes hold the string’s current length.

The storage allocated for a VARYINGZ character string is 1 byte longer than the declared length. The current length of the string is equal to the number of bytes before the first '00'x in the storage allocated to it.

The storage allocated for a VARYINGZ GRAPHIC string is 2 bytes longer than the declared length. The current length of the string is equal to half the number of bytes before the first '0000'gx in the storage allocated to it.

The storage allocated for a VARYINGZ WIDECHAR string is 2 bytes longer than the declared length. The current length of the string is equal to half the number of bytes before the first '0000'wx in the storage allocated to it.

The VARYINGZ attribute is not allowed with BIT strings.

In the following DECLARE statements, both User and Zuser represent varying-length character data with a maximum length of 15. However, unlike User, Zuser is null-terminated. The storage allocated is 17 bytes for User and 16 bytes for Zuser.

  declare User character (15) varying;
  declare Zuser character (15) varyingz;

The length for User and Zuser at any time is the length of the data item assigned to it at that time. You can determine the declared and the current length by using the MAXLENGTH and LENGTH built-in functions, respectively.

The null terminator held in a VARYINGZ string is not used in comparisons or assignments, other than to determine the length of the string. Consequently, although the strings in the following declarations have the same internal hex representation, they do not compare as being equal:

  declare A char(4) nonvarying init( ('abc' || '00'x) );
  declare B char(3) varyingz   init( 'abc' );

To the contrary, Z and C in this example do compare as equal:

  dcl Z char(3) nonvarying init('abc');
  dcl C char(3) varyingz init('abc');

The VARYING and VARYINGZ strings can be passed and received as parameters with * length. They can be passed without a descriptor if they have the NONASSIGNABLE attribute.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)