MOVE Reference Modification
MOVE Reference Modification
MOVE reference modification is used for a special purpose to move part of data from the sending item to the receiving item. This is mainly useful when dealing with strings, where we might want to handle only a specific part of the data item.
Syntax -
variable (start-position [: length])
Parameters -
- variable - The name of the variable we're working with..
- start-position - The position in the variable where the substring begins. The first character is at position 1.
- length - Specifies the number of bytes from the starting position. If not provided, the substring includes all characters from the start-position to the end.
Notes -
- The sending item can be an alphanumeric elementary item, a group item, or a literal or figurative constant.
- The receiving item should be an alphanumeric elementary item or group item but not a literal or figurative constant.
- MOVE statement can have one or more receiving items.
Practical Example -
Scenario - Formatting full phone number from three different sources.
Code -
----+----1----+----2----+----3----+----4----+----5----+
...
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.
...
Output -
FULL PHONE NUMBER: 919987654321