DIVIDE Giving
DIVIDE Giving Example
Scenario - Divide one variable with other and result into another variable.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. DIVGIVIN.
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.
05 WS-RESULT PIC 9(03).
PROCEDURE DIVISION.
DIVIDE WS-VAR1 BY WS-VAR2
GIVING WS-RESULT.
DISPLAY "Result: " WS-RESULT.
STOP RUN.
Output -
Result: 10
Explaining Example -
In the above example:
- This COBOL code declares three variables: WS-VAR1, WS-VAR2, and WS-RESULT, each capable of holding a 3-digit numeric value.
- WS-VAR1 is initialized with the value 50, WS-VAR2 is initialized with the value 5, and WS-RESULT is left uninitialized.
- It divides the value of WS-VAR1 by the value of WS-VAR2 using the DIVIDE statement and stores the result in WS-RESULT.
- Then, it displays the result with the message "Result: " followed by the content of WS-RESULT. So, the output will be "Result: 10".