Simple MULTIPLY Example


Scenario - Multiplying two variables.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SIMPMULT.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-V1         PIC 9(02) VALUE 20.
          05 WS-V2         PIC 9(03) VALUE 30.

       PROCEDURE DIVISION.

      *    Simple MULTIPLY
           MULTIPLY WS-V1   BY WS-V2.
           DISPLAY "Result: " WS-V2.

           STOP RUN.

Output -

Result: 600

Explaining Example -

In the above example:

  • It declares two variables WS-V1 and WS-V2 and assigns initial values to them.
  • Then, it performs a multiplication operation on WS-V1 and WS-V2 using the MULTIPLY statement and stores the result in WS-V2.
  • Finally, it displays the result of the result WS-V2.