Module 6: Procedure Division
MOVE CORRESPONDING
- When we want to move multiple data items of one group to some other data items in another group, then in such case multiple move statements will be needed if data names are distinct. However, if the corresponding data items of the two groups have identical names, then instead of using separate MOVE statement, just one MOVE statement with the CORRESPONDING option can be used.
- Basic syntax:-
MOVE {CORRESPONDING | CORR} identifier-1 to identifier-2
- Example:-
- Let’s assume data declaration in DATA DIVISION is,
01 EMP-REC-1. 05 E1 PIC 999. 05 E2 PIC 999V9. 05 E3 PIC XXXXXX. 05 E4 PIC 999. 01 EMP-REC-2. 05 E1 PIC ZZZ. 05 D1 PIC 999.9. 05 E3 PIC XXXBXX. 05 D4 PIC ZZZ.
- Assume currently data in EMP-REC-1 and EMP-REC-2 is as follows
- In this case if I want to move content of E1, E3 of EMP-REC-1 to E1,E3 of EMP-REC-2, below will serve the purpose:-
MOVE E1 OF EMP-REC-1 TO E1 OF EMP-REC-2 MOVE E3 OF EMP-REC-1 TO E3 OF EMP-REC-2However, since both the records have same names of the concerned data item, the following statement,MOVE CORRESPONDING EMP-REC-1 TO REMP-REC-2.will have same effect.Also, it is not necessary that the corresponding data names in the two records should appear in same order.After execution of above statement, content of EMP-REC-2:-
- Let’s assume data declaration in DATA DIVISION is,