Divide Verb in COBOL

Divide Verb

Divide verb is used to divide one number by the another and store the result.

Following is the syntax of division operations:
DIVIDE A INTO B ----- syntax 1

DIVIDE A BY B GIVING C REMAINDER R   ----- syntax 2

In syntax 1, B is divided by A and the result is stored in B. i.e B=B/A.

In syntax 2, A is divided by B and the result is stored in C. i.e C= A/B and remainder is stored in R.

Example : Demonstration of Divide verb

IDENTIFICATION DIVISION.
PROGRAM-ID. DV.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-N1 PIC 9(4) VALUE 15.
   01 WS-N2 PIC 9(3) VALUE 150.
   01 WS-NA PIC 9(3) VALUE 93.
   01 WS-NB PIC 9(3) VALUE 18.
   01 WS-NC PIC 9(4).
   01 WS-REM PIC 9(3).

PROCEDURE DIVISION.
   DIVIDE WS-N1 INTO WS-N2.
   DIVIDE WS-NA BY WS-NB GIVING WS-NC REMAINDER WS-REM.
   DISPLAY "WS-NUMBER-1     : " WS-N1
   DISPLAY "WS-NUMBER-2     : " WS-N2
   DISPLAY "WS-NUMBER-A     : " WS-NA
   DISPLAY "WS-NUMBER-B     : " WS-NB
   DISPLAY "WS-NUMBER-C     : " WS-NC
   DISPLAY "WS-REM               : " WS-REM
   
STOP RUN.


Output:
WS-NUMBER-1     : 0015
WS-NUMBER-2     : 010
WS-NUMBER-A     : 093
WS-NUMBER-B     : 018
WS-NUMBER-C     : 0005
WS-REM               : 003