Move Reference Modification Example


Scenario - Formatting full phone number from three different sources.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. MOVEREF.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-COUNTRY-CODE        PIC 9(02)  VALUE 91.
       01 WS-AREA-CODE           PIC 9(03)  VALUE 999.
       01 WS-PHONE-NBR           PIC 9(08)  VALUE 87654321.
       01 WS-FULL-PHN-NBR        PIC 9(13).

       PROCEDURE DIVISION.
           MOVE WS-COUNTRY-CODE  TO WS-FULL-PHN-NBR(1:2).
           MOVE WS-AREA-CODE     TO WS-FULL-PHN-NBR(3:2).
           MOVE WS-PHONE-NBR     TO WS-FULL-PHN-NBR(5:8).

           DISPLAY 'FULL PHONE NUMBER:  ' WS-FULL-PHN-NBR.
           STOP RUN.

Output -

FULL PHONE NUMBER:  919987654321

Explaining Example -

In the above example:

  • WS-COUNTRY-CODE value moved to first 2 bytes of WS-FULL-PHN-NBR.
  • WS-AREA-CODE value moved to 3rd and 4th positions of WS-FULL-PHN-NBR.
  • WS-PHONE-NBR value moved to WS-FULL-PHN-NBR from 5th position to 8 bytes.