Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

LENGTH - Number of characters

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

  1. argument-1 may be a non-numeric literal or a data item of any class or category or a type name.

  2. 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

  1. 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.

  2. 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.

  3. 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