Module 6: Procedure Division
CORRESPONDING option for ADD and SUBTRACT
- CORRESPONDING option for MOVE statement is already explained in < link to CORRESPONDING : MOVE>
- CORRESPONDING option can also be used with the ADD and SUBTRACT.
- Basic syntax:-
ADD CORRESPONDING identifier-1 TO identifier-2.SUBTRACT CORRESPONDING identifier-1 FROM identifier-2.
- identifier-1 and identifier-2 are group items
- CORR can also be used in place of CORRESPONDING
- In above case, during ADD operation the numeric elementary items belonging to group item “identifier-1” will be added to the corresponding matching elementary items belonging to group item “identifier-2”
- Similarly, In SUBTRACT operation, elementary items belonging to group item “identifier-1” will be subtracted from corresponding matching elementary items belonging to group item “identifier-2”
- Example:-
In DATA DIVISION,01 DATA-1. 05 A PIC 9(7). 05 B PIC 9(7). 05 C PIC 9(7). 01 DATA-2. 05 A PIC 9(7). 05 B PIC 9(7). 05 D PIC 9(7).In PROCEDURE DIVISION,ADD CORRESPNDING DATA-1 TO DATA-2.In above example, ADD CORRESPNDING option will add elementary data items A & B of DATA-1 to A & B of DATA-2 respectively. Note: C will not be added to D since they do not have matching data name.
- Important points to be considered while using CORRESPONDING:-
- It can be used only with ADD, SUBTRACT and MOVE
- Identifier-1 and identifier-2 must be group data items
- Only those elementary data items belonging to identifier-1 & identifier-2 can take part in operation which shares same data name and same qualifiers
- When used with ADD and SUBTRACT, only numeric data items participates in operation
- Elementary data items belonging to identifier-1 and identifier-2 cannot participate if it is defined with 66, 88, REDEFINES or OCCURS. However, identifier-1 and identifier-2 itself can have a REDEFINES or OCCURS clause or may belong to the data item having a REDEFINES or OCCURS clause
- FILLER data items are ignored
- Different PICTURE size allowed for elementary data items of identifier-1 and identifier-2