Subtract with Giving
Subtract with Giving Example
Scenario - Subtract one variable from other and placing result into third.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBTGIVN.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-A PIC 9(03) VALUE 20.
05 WS-B PIC 9(03) VALUE 30.
05 WS-C PIC 9(03).
PROCEDURE DIVISION.
SUBTRACT WS-A FROM WS-B GIVING WS-C.
DISPLAY "WS-C: " WS-C.
STOP RUN.
Output -
WS-C: 010
Explaining Example -
In the above example:
- It defines three numeric variables: WS-A, WS-B, and WS-C, all of size 3.
- WS-A is initialized with a value of 20, WS-B with a value of 30, and WS-C is left uninitialized.
- Then, it subtracts the value of WS-A from WS-B and stores the result in WS-C. Finally, it displays the value of WS-C, which should be the result of the subtraction, i.e., 10.