


Reference modification is akin to substringing in other programming languages. Reference modification is very useful for referencing a component part of a composite string. For example, it might be used to reference the area code digits of a 10-character string containing a phone number (area code + seven digits):
01 PHONE-NUMBER PIC 9(10) VALUE 3017728134.
{ . . . }
PHONE-NUMBER (1:3).
*The reference modification begins at position 1
*of string PHONE-NUMBER and has a length of 3.
*The reference modification value = "301"
For the following code examples, assume these data items:
01 ACCOUNT-CODE PIC X(20) VALUE "AB700648xSMITHxxCLA1". 01 ACCOUNT-NAME PIC X(6) VALUE ALL SPACES. 01 ACCT-CLASS-1 PIC X(4) VALUE "CLA1".
Code example 1:
MOVE ACCOUNT-CODE (10:6) TO ACCOUNT-NAME. *This reference modification selects the *characters that form the name portion of *ACCOUNT-CODE. The reference starts at position *10 and has a length of 6 characters. *The ACCOUNT-CODE substring = "SMITHx"
Code example 2:
IF ACCOUNT-CODE (17:) = ACCT-CLASS-1 THEN *When the reference modification does not *include a length, the reference begins at the *value specified and extends to the end of the *data item. *The ACCOUNT-CODE substring = "CLA1"