ILE COBOL Language Reference

+-------------------------------IBM Extension--------------------------------+

LENGTH OF Special Register

The LENGTH OF phrase creates an implicit special register whose contents equal the current length, in bytes, of the data item referenced by the identifier.

The LENGTH OF special register has the implicit definition:

USAGE IS BINARY, PICTURE 9(9)

You can use it anywhere in the Procedure Division where you can use a numeric data item having the same definition as the implied definition of the LENGTH OF special register.

It can appear in the starting position or length expression of a reference modifier. However, the LENGTH OF special register cannot be applied to any operand that is reference modified.

The LENGTH OF operand may not be a function, but the LENGTH OF special register will be allowed in a function where an integer parameter is allowed.

If the LENGTH OF special register is used as the argument to the LENGTH function, the result will always be 4, independent of the argument specified for LENGTH OF.

It cannot be either of the following:

You can use LENGTH OF in the BY CONTENT phrase of the CALL statement.

A date-time data item can be used in expressions using the LENGTH OF special register. The identifier may also be a type-name, or an item that is subordinate to a type-name.

For a table element, the LENGTH OF special register contains the length, in bytes, of one occurrence. To refer to a table element in this case, you do not need to use a subscript.

For a variable-length element, the LENGTH OF special register contains the length based on the current contents of the occurs depending on (ODO) variable.

The register returns a value for any identifier whose length can be determined, even if the area referenced by the identifier is currently not available to the program. For example, an identifier that is part of a 01-level record in a File Definition is not available until the corresponding file is open; however, the LENGTH OF such an identifier can be determined before the file is open.

If, for a variable-length item, the contents of the ODO variable are not available, the LENGTH OF special register is undefined. For example, if an ODO variable is defined in the 01-level record of a file that is not open, no LENGTH OF value exists, and an error results.

A separate LENGTH OF special register exists for each identifier referenced with the LENGTH OF phrase.

For example:

MOVE LENGTH OF A TO B
DISPLAY LENGTH OF A, A
ADD LENGTH OF A TO B
CALL "PROGX" USING BY REFERENCE A BY CONTENT LENGTH OF A
Note:
The number of bytes occupied by a COBOL item is also accessible through the intrinsic function LENGTH (see LENGTH). LENGTH supports nonnumeric literals in addition to data names.

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]