Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

DIVIDE statement

Function

The DIVIDE statement is used to divide one numeric operand by another and store the result.

Format 1

of the DIVIDE statement stores the quotient in the dividend item.

Format 2

of the DIVIDE statement stores the quotient in more than one separate result item.

Format 3

of the DIVIDE statement uses the GIVING phrase for storing the quotient and generates
the division remainder by
means of the REMAINDER phrase.

Format 1


DIVIDE { identifier-1 | literal-1 } INTO {identifier-2 [ROUNDED]}...

    [ON SIZE ERROR imperative-statement-1]

    [NOT ON SIZE ERROR imperative-statement-2]

    [END-DIVIDE]


Syntax rules

  1. Each identifier must refer to an elementary numeric item.

  2. The value of identifier-2 is divided by the value of identifier-1 or literal-1. The quotient then replaces the current value of identifier-2 and so on.

  3. The maximum size of the quotient is 31 decimal digits.

  4. Division by zero always results in overflow (SIZE ERROR).

  5. In the case of division with ON SIZE ERROR, it is still possible for a DIVIDE-ERROR to occur since no test is made for quotient overflow (only for division by zero).

Additional rules are given under "Phrases in statements", where the ROUNDED, (NOT) ON SIZE ERROR, and GIVING phrases are described.

Example 8-33

Statement

PICTURE of result item

Calculation

DIVIDE A INTO B

9(4)V9(2)

B / A stored as nnnnVnn in B

Format 2


DIVIDE {identifier-1 | literal-1} {INTO | BY} {identifier-2 | literal-2}

        GIVING {identifier-3 [ROUNDED]}...

       [ON SIZE ERROR imperative-statement-1]

       [NOT ON SIZE ERROR imperative-statement-2]

       [END-DIVIDE]


Syntax rules

  1. identifier-1 or identifier-2 must refer to an elementary data item.

  2. identifier-3... may refer to an elementary numeric item or to an elementary numericedited item.

  3. When the INTO phrase is used, the value of identifier-2 or literal-2 is divided by the value of identifier-1 or literal-1; when the BY phrase is used, the value of identifier-1 or literal-1 is divided by the value of identifier-2 or literal-2. The quotient is stored in identifier-3... .

  4. The maximum size of the quotient is 31 decimal digits.

  5. Division by zero always results in overflow (SIZE ERROR).

  6. In the case of division with ON SIZE ERROR, it is still possible for a divide error to occur since no test is made for quotient overflow (only for division by zero).

Additional rules are given under "Phrases in statements" where the ROUNDED, (NOT) ON SIZE ERROR, and GIVING phrases are described.

Example 8-34

Statement

PICTURE IS of result item (C):

Calculation

DIVIDE A INTO B
GIVING C ROUNDED

S999V99 for C

B / A stored in C as nnnVnn after rounding, if necessary

DIVIDE A BY B,
GIVING C, D
ROUNDED

9(5) for C
9(4) for D

A / B stored in C as nnnnn, in D as nnnn, after rounding the rightmost character,if necessary.

Format 3


DIVIDE {identifier-1 | literal-1} {INTO | BY} {identifier-2 | literal-2} GIVING identifier-3 [ROUNDED]

        REMAINDER identifier-4

       [ON SIZE ERROR imperative-statement-1]

       [NOT ON SIZE ERROR imperative-statement-2]

       [END-DIVIDE]


Syntax rules

  1. identifier-1 or identifier-2 must refer to an elementary numeric data item.

  2. identifier-3 or identifier-4 may refer to an elementary numeric data item or to an elementary numeric-edited data item.

  3. When INTO is used, the value of identifier-2 or literal-2 is divided by the value of identifier-a or literal-1. When the BY phrase is used, the value of identifier-1 or literal-1 is divided by the value of identifier-2 or literal-2. The quotient is stored in identifier-3.

  4. When the REMAINDER phrase is used, the remainder of the division is stored in identifier-4.
    The remainder is calculated by subtracting the product of the quotient and the divisor from the dividend.
    If identifier-3 is defined as an elementary numeric-edited item, then the remainder is calculated by using an intermediate item for the quotient, containing the value in an unedited format.
    If both the ROUNDED and the REMAINDER phrases are supplied, then the remainder is calculated by using an intermediate item for the quotient, containing the quotient of the DIVIDE statement in a truncated rather than rounded format.

  5. If ON SIZE ERROR is specified, and overflow occurs in the quotient, then the remainder will not be calculated. In this case, the contents of the data items referenced by identifier-3 and identifier-4 are therefore unchanged.
    If overflow occurs in the remainder, the value of the data item referenced by identifier4 is not changed.

  6. The precision of the data item required for the REMAINDER phrase (identifier-4) is determined by the calculations described above. Appropriate decimal point alignment and truncation (rather than rounding) are performed as necessary for the contents of the data item referenced by identifier-4.

  7. The maximum size of the quotient is 31 decimal digits.

  8. Division by zero always results in overflow (SIZE ERROR).

Additional rules are given under "Phrases in statements", where the ROUNDED, (NOT) ON SIZE ERROR, and GIVING phrases are described.

Example 8-35

Statement

Result item (C)PICTURE IS:

Calculation

DIVIDE A BY B,
GIVING C REMAINDER D

9(5) for C9(2) for D

A / B stored in C as nnnnn, the remainder, e.g. A - C * B, stored in D as nn.