ANS85 

The LENGTH Function

The LENGTH function returns an integer equal to the length of the argument in alphanumericENTMF , national or UTF-8 character positions, depending on the class of the argument.

The type of this function is integer.

General Format


Syntax for General Format for the LENGTH function

Arguments

  1. Argument-1 can be an alphanumeric

    ENTMF , national, or UTF-8

    literal or a data item of any class or category.
  2. 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.

Returned Values

  1. If argument-1 is an alphanumeric literal, or is an elementary data item of class other than national or is 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 alphanumeric character positions.

    MF If argument-1 is an elementary data item of the class national or is a national literal, the returned value is an integer equal to the length of argument-1 in national character positions.

  2. If argument-1 is a group data item containing a variable occurrence data item, the returned value is an integer determined by evaluation of the data item specified in the DEPENDING phrase of the OCCURS clause for that variable occurrence data item. This evaluation is accomplished according to the rules in the OCCURS clause dealing with the data item as a sending data item. See the section The OCCURS Clause in the chapter Data Division - File and Data Description.
  3. The returned value includes implicit FILLER characters, if any.
  4. ENTMF If argument-1 is a UTF-8 literal or an elementary data item of usage UTF-8, the return value gives the length of argument-1 in UTF-8 character positions. For example, if argument-1 is defined as PIC U(n), the returned value is always n, even though the storage size of the argument is 4*n bytes and the actual number of bytes used by the item varies depending on the actual data in the item.
  5. ENTMF If argument-1 is a UTF-8 group item or a UTF-8 elementary item containing a BYTE-LENGTH clause, the return value gives the length of argument-1 in UTF-8 character positions. Character length is computed at run time by examining the data in the item or group. If argument-1 is a group with a subordinate data item described with the DEPENDING phrase of the OCCURS clause, the length of argument-1 is determined using the contents of the data item specified in the DEPENDING phrase. This evaluation is accomplished according to the rules of the OCCURS clause for a sending data item.