COBOL ADD GIVING Example
Scenario - Adding two variables and stored the result into another variable.
Code -
----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ADDGIVIN.
       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 60.
          05 WS-C      PIC 9(03).
       PROCEDURE DIVISION.
           ADD WS-A TO WS-B GIVING WS-C.
           DISPLAY "WS-C:  " WS-C.
           STOP RUN.Output -
WS-C: 80
Explaining Example -
In the above example:
- It performs addition operation between WS-A and WS-B, storing the result in WS-C using the "GIVING" phrase.
- Initially, WS-A holds a value of 20 and WS-B holds a value of 60. After the addition operation, it displays "WS-C: 80" and terminates the program.
