Simple SUBTRACT
Simple SUBTRACT Example
Scenario - Subtract one variable from other.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMPSUBT.
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.
PROCEDURE DIVISION.
SUBTRACT WS-A FROM WS-B.
DISPLAY "WS-B: " WS-B.
STOP RUN.
Output -
WS-B: 010
Explaining Example -
In the above example:
- It initializes two numeric variables, WS-A with a value of 20 and WS-B with a value of 30, both of size 3.
- Then it subtracts WS-A from WS-B, effectively subtracting 20 from 30, resulting in 10 and stored it in WS-B.
- Finally, it displays the value of WS-B, which should now be 10.