ADD CORRESPONDING Example


Scenario - Adding corresponding variables from two groups.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ADDCORRS. 
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       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.

       PROCEDURE DIVISION.
           ADD CORR WS-VAR1   TO WS-VAR2.
           DISPLAY "WS-A: " WS-A OF WS-VAR2. 
           DISPLAY "WS-B: " WS-B OF WS-VAR2. 

           STOP RUN.

Output -

WS-A: 30
WS-B: 40

Explaining Example -

In the above example:

  • It performs correlated addition between two groups of variables, WS-VAR1 and WS-VAR2.
  • WS-A of WS-VAR2 will be 20 (initial value) + 10 (value of WS-A of WS-VAR1) = 30.
  • WS-B of WS-VAR2 will be 30 (initial value) + 10 (value of WS-B of WS-VAR1) = 40.