Simple ADD Example


Scenario - Adding number to the value in variable.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SIMPADD.
       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.
           ADD 10, WS-A TO WS-B.
           DISPLAY "RESULT: " WS-B.

           STOP RUN.

Output -

Result: 60

Explaining Example -

In the above example:

  • It initializes two variables, WS-A with a value of 20 and WS-B with a value of 30.
  • Then, it adds 10 to the value of WS-A, WS-B and assigns the result to WS-B.
  • Finally, it displays the result stored in WS-B and terminates the program.