LENGTH
The LENGTH function returns an integer equal to the length of the argument in bytes. The function type is integer.
The function result is a nine-digit integer.
- argument-1
- Can be a nonnumeric, boolean, or DBCS literal; a data item of any class
or category.
If argument-1, or any data item subordinate to argument-1, is described with the DEPENDING phrase of the OCCURS clause, the contents of the data item referenced by the data-name specified in the DEPENDING phrase are used at the time the LENGTH function is evaluated.
Argument-1 can be a type-name, or an item that is subordinate to a type-name.
A data item described with USAGE IS POINTER or USAGE IS PROCEDURE-POINTER can be used as argument-1 to the LENGTH function. The result will always be 16.
The ADDRESS OF special register, or the LENGTH OF special register, can be used as argument-1 to the LENGTH function. The result will always be 16 or 4 respectively, independent of the ADDRESS OF or LENGTH OF object.
If argument-1 is a nonnumeric literal, an elementary data item, or a group data item that does not contain a variable occurrence data item, the value returned is an integer equal to the length of argument-1 in character positions.
If argument-1 is a null-terminated nonnumeric literal, the returned value is equal to the number of alphanumeric character positions in the literal excluding the null character at the end of the literal. The length of a null-terminated nonnumeric literal containing a mix of single-byte and double-byte characters is counted as though each byte were a single-byte character.
IBM Extension If argument-1 is a DBCS or national data item or literal, the returned value is the length of the argument in DBCS or national character positions. For example, FUNCTION LENGTH (G"D1D2") will return the value 2, not 4. End of IBM Extension
The returned value includes implicit FILLER characters, if any.
