DIVIDE Statement

The DIVIDE statement performs arithmetic division.

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.

Format 1 General Rules

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

Format 2 and 3 General Rules

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

Format 4 and 5 General Rules

  1. The divisor is divided into the dividend, the quotient is stored in result, and the remainder is stored in remainder.
  2. If the ROUNDED phrase is not specified, the quotient is truncated to fit into the result and the remainder is computed by subtracting the product of the truncated quotient and divisor from the dividend. If the ROUNDED phrase is specified, the quotient is rounded to fit the result, but the remainder is still computed by subtracting the product of the truncated quotient and the divisor from the dividend.
  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.
    Note: In division operations, the remainder is calculated before the quotient is moved to the destination item(s).

    The remainder will almost always be 0 if the dividend or divisor is floating-point. This is because all of the arithmetic is performed using floating-point variables. The remainder will be non-zero only if precision is lost during the calculation.

  4. Additional information can be found in Arithmetic Operations, Multiple Receiving Fields, the ROUNDED Option, and the SIZE ERROR Option.