Simple DIVIDE Example


Scenario - Divide one variable with other.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-VAR1      PIC 9(03) VALUE 50.
          05 WS-VAR2      PIC 9(03) VALUE 5. 

       PROCEDURE DIVISION.
           DIVIDE WS-VAR1 INTO WS-VAR2 
           DISPLAY "Result: " WS-VAR2.

           STOP RUN.

Output -

Result: 10

Explaining Example -

In the above example:

  • It declares two variables, WS-VAR1 and WS-VAR2, each capable of holding a 3-digit numeric value.
  • WS-VAR1 is initialized with the value 50, and WS-VAR2 is initialized with the value 5.
  • It divides the value of WS-VAR1 by the value of WS-VAR2 using the DIVIDE statement and stores the result in WS-VAR2.
  • Then, it displays the result with the message "RESULT: " followed by the content of WS-VAR2. So, the output will be "RESULT: 10".