Reference modification

Reference modification defines a data item by specifying a leftmost character and optional length for the data item.

Format: reference modification

Read syntax diagramSkip visual syntax diagramdata-name-1FUNCTIONfunction-name-1(argument-1)(leftmost-character-position:length)
data-name-1
Must reference a data item described explicitly or implicitly with usage DISPLAY, DISPLAY-1, NATIONAL, or UTF-8. A national group item is processed as an elementary data item of category national.

data-name-1 can be qualified or subscripted.

data-name-1 cannot be a dynamic-length group item. If data-name-1 is a dynamic-length elementary item, it is treated as though it were a fixed-length item whose length is the same as the current length of the dynamic-length elementary item. When used as a reference modified receiver in a PROCEDURE DIVISION statement, the current length of the dynamic-length elementary item is not modified.

leftmost-character-position
Must be an arithmetic expression. The evaluation of leftmost-character-position must result in a positive nonzero integer that is less than or equal to the number of characters in the data item referenced by data-name-1.
length
Must be an arithmetic expression.

The evaluation of length must result in a positive nonzero integer.

The sum of leftmost-character-position and length minus the value 1 must be less than or equal to the number of character positions in data-name-1. If length is omitted, the length used will be equal to the number of character positions in data-name-1 plus 1, minus leftmost-character-position.

function-name-1
Must reference an alphanumeric or national function.

For usages DISPLAY-1 and NATIONAL, each character position occupies 2 bytes. Reference modification operates on whole character positions and not on the individual bytes of the characters in usages DISPLAY-1 and NATIONAL. For usage DISPLAY, reference modification operates as though each character were a single-byte character.

Unless otherwise specified, reference modification is allowed anywhere an identifier or function-identifier that references a data item or function with the same usage as the reference-modified data item is permitted.

Each character position referenced by data-name-1 or function-name-1 is assigned an ordinal number incrementing by one from the leftmost position to the rightmost position. The leftmost position is assigned the ordinal number one. If the data description entry for data-name-1 contains a SIGN IS SEPARATE clause, the sign position is assigned an ordinal number within that data item.

If data-name-1 is described with usage DISPLAY and category numeric, numeric-edited, alphabetic, alphanumeric-edited, or external floating-point, data-name-1 is operated upon for purposes of reference modification as if it were redefined as a data item of category alphanumeric with the same size as the data item referenced by data-name-1.

If data-name-1 is described with usage NATIONAL and category numeric, numeric-edited, national-edited, or external floating-point, data-name-1 is operated upon for purposes of reference modification as if it were redefined as a data item of category national with the same size as the data item referenced by data-name-1.

If data-name-1 is a national group item, data-name-1 is processed as an elementary data item of category national.

Reference modification creates a unique data item that is a subset of data-name-1 or a subset of the value referenced by function-name-1 and its arguments, if any. This unique data item is considered an elementary data item without the JUSTIFIED clause.

When a function is reference-modified, the unique data item has class, category, and usage national if the type of the function is national; otherwise, it has class and category alphanumeric and usage display.

When data-name-1 is reference-modified, the unique data item has the same class, category, and usage as that defined for the data item referenced by data-name-1 except that:

  • If data-name-1 has category national-edited, the unique data item has category national.
  • If data-name-1 has usage NATIONAL and category numeric-edited, numeric, or external floating-point, the unique data item has category national.
  • If data-name-1 has usage DISPLAY, and category numeric-edited, alphanumeric-edited, numeric, or external floating-point, the unique data item has category alphanumeric.
  • If data-name-1 references an alphanumeric group item, the unique data item is considered to have usage DISPLAY and category alphanumeric.
  • If data-name-1 references a national group item, the unique data item has usage NATIONAL and category national.

If length is not specified, the unique data item created extends from and includes the character position identified by leftmost-character-position up to and including the rightmost character position of the data item referenced by data-name-1.

Evaluation of operands

Reference modification for an operand is evaluated as follows:

  • If subscripting is specified for the operand, the reference modification is evaluated immediately after evaluation of the subscript.
  • If subscripting is not specified for the operand, the reference modification is evaluated at the time subscripting would be evaluated if subscripts had been specified.

Reference modification examples

The statements in the examples transfer the first 10 characters of the data-item referenced by WHOLE-NAME to the data-item referenced by FIRST-NAME.


77  WHOLE-NAME  PIC X(25).
77  FIRST-NAME  PIC X(10).

77  START-P     PIC 9(4) BINARY VALUE 1.
77  STR-LENGTH  PIC 9(4) BINARY VALUE 10.    

...
    MOVE WHOLE-NAME(1:10) TO FIRST-NAME.
    MOVE WHOLE-NAME(START-P:STR-LENGTH) TO FIRST-NAME.	

The following statement transfers the last 15 characters of the data-item referenced by WHOLE-NAME to the data-item referenced by LAST-NAME.


77  WHOLE-NAME  PIC X(25).
77  LAST-NAME   PIC X(15).
...
    MOVE WHOLE-NAME(11:) TO LAST-NAME.

The following statement transfers the fourth and fifth characters of the third occurrence of TAB to the variable SUFFIX.


01  TABLE-1.
    02  TAB  OCCURS 10 TIMES  PICTURE X(5).
77  SUFFIX                    PICTURE X(2).
...
    MOVE TAB OF TABLE-1 (3) (4:2) TO SUFFIX.