CORRESPONDING Phrase


CORRESPONDING phrase performs the ADD, SUBTRACT, and MOVE operations on the same named elementary variables under two different groups.

Syntax -

           ADD [CORRESPONDING|CORR]
		        group1
			TO  group2
		   [END-ADD].
           SUBTRACT [CORRESPONDING|CORR]
		        group1
			TO  group2
		   [END-SUBTRACT].
           MOVE [CORRESPONDING|CORR]
		        group1
			TO  group2.
  • group1 - Refers the sending or source group.
  • group2 - Refers the receiving or target group.

Rules to Remember -

  • Elementary variables under two groups should declare with the same name and the same type or compatible type.
  • All elementary variables in two groups should declare as numeric for ADD and SUBTRACT operations.
  • Neither group1 nor group2 should not have level 66, 77, or 88 variables.
  • Elementary variables of two groups shouldn't declare with REDEFINES, RENAMES, or OCCURS in their definitions. However, group1 and group2 themselves can declare with REDEFINES or OCCURS.

Examples -


Scenario1 - ADD CORRESPONDING

Input-        WS-VAR1, WS-VAR2
Declaration-  01 WS-VAR1.                             
                 05 WS-A          PIC 9(02) VALUE 20.
                 05 WS-B          PIC 9(02) VALUE 30.
              01 WS-VAR2.                            
                 05 WS-A          PIC 9(02) VALUE 10.
                 05 WS-B          PIC 9(02) VALUE 10.
				 
Code-         ADD CORR WS-VAR1   TO WS-VAR2.
				
Result-       WS-A OF WS-VAR2 = 30, WS-B OF WS-VAR2 = 40

WS-A of WS-VAR1 is added to WS-A of WS-VAR2 and stores the result in WS-A of WS-VAR2, similarly for WS-B.

Scenario2 - SUBTRACT CORRESPONDING

Input-        WS-VAR1, WS-VAR2

Declaration-  01 WS-VAR1.                             
                 05 WS-A          PIC 9(02) VALUE 10.
                 05 WS-B          PIC 9(02) VALUE 10.
              01 WS-VAR2.                            
                 05 WS-A          PIC 9(02) VALUE 20.
                 05 WS-B          PIC 9(02) VALUE 30.
				 
Code-         SUBTRACT CORR WS-VAR1   FROM WS-VAR2.
				
Result-       WS-A OF WS-VAR2 = 10, WS-B OF WS-VAR2 = 20

WS-A of WS-VAR1 is subtracted from WS-A of WS-VAR2 and stores the result in WS-A of WS-VAR2, similarly for WS-B.

Scenario3 - MOVE CORRESPONDING

Input-        WS-VAR1

Declaration-  01 WS-VAR1.                             
                 05 WS-A          PIC 9(02) VALUE 10.
                 05 WS-B          PIC 9(02) VALUE 10.
              01 WS-VAR2.                            
                 05 WS-A          PIC 9(02).
                 05 WS-B          PIC 9(02).
				 
Code-         MOVE CORR WS-VAR1   FROM WS-VAR2.
				
Result-       WS-A OF WS-VAR2 = 10, WS-B OF WS-VAR2 = 10

WS-A of WS-VAR1 is moved to WS-A of WS-VAR2. Similarly, for WS-B.