Subtract with Corresponding
Subtract with Corresponding Example
Scenario - Subtracting corresponding variables in two groups.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBTCORR.
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.
SUBTRACT CORR WS-VAR1 FROM WS-VAR2.
DISPLAY "WS-A OF WS-VAR2: " WS-A OF WS-VAR2.
DISPLAY "WS-B OF WS-VAR2: " WS-B OF WS-VAR2.
STOP RUN.
Output -
WS-A OF WS-VAR2: 10 WS-B OF WS-VAR2: 20
Explaining Example -
In the above example:
- It defines two sets of numeric variables, WS-VAR1 and WS-VAR2, each containing two fields WS-A and WS-B.
- WS-A is initialized to 10 for WS-VAR1 and 20 for WS-VAR2, while WS-B is initialized to 10 for WS-VAR1 and 30 for WS-VAR2.
- It subtracts the corresponding fields of WS-VAR1 from WS-VAR2 and displays the resulting values of WS-A and WS-B of WS-VAR2.