The LENGTH function returns an integer equal to the length of argument-1 in character positions.
The type of this function is integer.
Format
FUNCTION
LENGTH
(argument-1)
Arguments
argument-1 may be a non-numeric literal or a data item of any class or category or a type name.
If any data item subordinate to argument-1 is described with the DEPENDING phrase of the OCCURS clause, the contents of the DEPENDING data item are used at the time the LENGTH function is evaluated.
Returned values
If argument-1 is a non-numeric literal or 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 an object reference then the length of the object reference and not the size of the object itself is returned.
If argument-1 is a group item to which a variable-length data item is subordinated, the return value is the length of argument-1 in bytes. It is calculated in accordance with the rules for a sending item with OCCURS clause.
The return value takes into account any implicit FILLER characters which occur in argument-1.
Example 9-20
... DATA DIVISION. WORKING-STORAGE SECTION. 01 RES PIC 9(3). PROCEDURE DIVISION. MAIN. COMPUTE RES = FUNCTION LENGTH ("Rats live on no evil star"). DISPLAY RES UPON T. STOP RUN.
Result: 025