Skip to content

Reference Modification

Reference Modification provides syntax for referencing a portion of the memory allocated by a data item.

General Format:

  [data-name] ( starting-offset : [ number-of-bytes ] )

Syntax:

  1. Data-name is a data-item declared in the Data Division.
  2. Starting-offset is a numeric literal, or data-item.

General Rules:

  1. Starting-offset corresponds to the location in data name where bytes start to be referenced. A value of 1 corresponds to the first byte.
  2. Number-of-bytes is a numeric literal, or data item. Number-of-bytes corresponds to the number of bytes that are to be referenced beginning at starting-offset.
  3. Number-of-bytes must be less than [length-of-data-name] [starting-offset] + 1.
  4. Number-of-bytes is optional. If number-of-bytes is not included in the reference modification phrase, then it is implied that the data referenced begins at starting-offset, and continues to the last byte in data-name.
  5. The substring identified by reference modification is treated as an alphanumeric data item, and a reference modification can be used anywhere that an alphanumeric literal or data item may be used.

Examples:

For the string:

       77 white-house-address PIC X(21) VALUE 1600 Pennsylvania Ave.

       White-house-address(1:4) returns 1600.
       White-house-address(19: ) returns Ave.

Reference modification can be applied to the output of an intrinsic function:

FUNCTION CURRENT-DATE (5:2) returns the current month.

Back to top