Enterprise COBOL for z/OS, V4.2, Language Reference

Reference modification

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

Read syntax diagramSkip visual syntax diagram
Format: reference modification

>>-+-data-name-1-----------------------------------------+------>
   '-FUNCTION--function-name-1--+----------------------+-'   
                                |    .------------.    |     
                                |    V            |    |     
                                '-(----argument-1-+--)-'     

>--(--leftmost-character-position--:--+--------+--)------------><
                                      '-length-'      

data-name-1
Must reference a data item described explicitly or implicitly with usage DISPLAY, DISPLAY-1, or NATIONAL. 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 windowed date field.

function-name-1
Must reference an alphanumeric or national function.
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.

The evaluation of leftmost-character-position must not result in a windowed date field.

length
Must be an arithmetic expression.

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

The evaluation of length must not result in a windowed date field.

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.

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.

If data-name-1 is an expanded date field, then the result of reference modification is a nondate.

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 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 following statement transfers 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).
...
    MOVE WHOLE-NAME(1:10) 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.


Rate this page

[ Index | Table of contents ]