CORRESPONDING Phrase


The CORRESPONDING phrase is used to perform the ADD, SUBTRACT, and MOVE operations on the same named elementary variables under two different groups.

Syntax -

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

Rules -

  • Elementary variables should be declared as numeric for ADD and SUBTRACT statements. Other types are ignored.
  • The elementary variables under two groups should have the same name and the same type or compatible type.
  • Neither group-variable1 nor group-variable2 are defined as a level 66, 77, or 88 variables.
  • The elementary variables should not have REDEFINES, RENAMES, or OCCURS in their definitions. But group-variable1 and group-variable2 themselves can be defined 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.