ContentsIndexPreviousNext

DIVIDE Statement

The DIVIDE statement performs arithmetic division.

General Format

Format 1

DIVIDE divisor INTO { result [ROUNDED] } ...

   [ ON SIZE ERROR statement ]

   [ NOT ON SIZE ERROR statement ]

   [ END-DIVIDE ]

Format 2

DIVIDE divisor INTO dividend

     GIVING { result [ROUNDED] } ...

   [ ON SIZE ERROR statement ]

   [ NOT ON SIZE ERROR statement ]

   [ END-DIVIDE ]

Format 3

DIVIDE dividend BY divisor

     GIVING { result [ROUNDED] } ...

   [ ON SIZE ERROR statement ]

   [ NOT ON SIZE ERROR statement ]

   [ END-DIVIDE ]

Format 4

DIVIDE divisor INTO dividend GIVING result [ROUNDED]

     REMAINDER remainder

   [ ON SIZE ERROR statement ]

   [ NOT ON SIZE ERROR statement ]

   [ END-DIVIDE ]

Format 5

DIVIDE dividend BY divisor GIVING result [ROUNDED]

     REMAINDER remainder

   [ ON SIZE ERROR statement ]

   [ NOT ON SIZE ERROR statement ]

   [ END-DIVIDE ]

Syntax Rules

1. Divisor is a numeric literal or numeric data item. It represents the number to be divided by.

2. Dividend is a numeric literal or numeric data item. It represents the number to be divided into.

3. Result is a numeric or numeric-edited data item. In Format 1, result must be a numeric data item.

4. Remainder is a numeric or numeric-edited data item.

5. Statement is an imperative statement.

6. The REMAINDER phrase may not be used if any operand or result is an external floating-point data type.


Note: Avoid mixing external floating-point types with other numeric types in DIVIDE statements, because mixed-type DIVIDE operations are not completely reliable.
General Rules

Format 1

1. The divisor is individually divided into each result and the quotient stored there.

Format 2 and 3

1. The divisor is divided into the dividend. The quotient is stored in each result.

Format 4 and 5

1. The divisor is divided into the dividend and the quotient is stored in result. The remainder after the division is stored in remainder. The remainder is computed by subtracting result times divisor from dividend.

2. If the ROUNDED phrase is specified, the remainder is computed with a truncated quotient instead of a rounded one.

3. If the SIZE ERROR clause is specified, and a size error occurs during the computation of the quotient, the remainder is not computed and remainder remains unchanged. If a size error occurs during the computation of the remainder, the result is updated, but the remainder is left unchanged. The SIZE ERROR statement executes in either case.

4. Additional information can be found in the sections covering Arithmetic Operations (6.4.1), Multiple Receiving Fields (6.4.2), the ROUNDED option (6.4.3), and the SIZE ERROR option (6.4.4).