Summary -

In this topic, we described about the DIVIDE Statement with detailed example.

The DIVIDE statement divides one numeric data item into or by others. DIVIDE statement sets the output values that are equal to the quotient and remainder to the data item. DIVIDE statement has below different formats based on phrases specified -

  • Simple DIVIDE statement
  • DIVIDE statement with INTO and GIVING phrases
  • DIVIDE statement with BY and GIVING phrases
  • DIVIDE statement with INTO and REMAINDER phrases
  • DIVIDE statement with BY and REMAINDER phrases

Format-1: DIVIDE statement

In the below format, the value of identifier-1 or literal-1 is divided by the value of identifier-2 and the quotient is stored in identifier-2.

Syntax -

DIVIDE Syntax

Format-2: DIVIDE statement with INTO and GIVING phrases

In below syntax, the value of identifier-1 or literal-1 is divided into the value of identifier-2 or literal-2. The value of the quotient is stored in data item referenced by identifier-3.

Syntax -

DIVIDE Statement with INTO and GIVING phrases

Format-3: DIVIDE statement with BY and GIVING phrases

In the below syntax, the value of identifier-1 or literal-1 is divided by the value of identifier-2 or literal-2. The value of the quotient is stored in data item referenced by identifier-3.

Syntax -

DIVIDE Statement with BY and GIVING phrases

Format-4: DIVIDE statement with INTO and REMAINDER phrases

In the below syntax, the value of identifier-1 or literal-1 is divided into identifier-2 or literal-2. The value of the quotient is stored in identifier-3 and the value of the remainder is stored in identifier-4.

Syntax -

DIVIDE Statement with INTO and REMAINDER phrases

Format-5: DIVIDE statement with BY and REMAINDER phrases

In the below syntax, the value of identifier-1 or literal-1 is divided by identifier-2 or literal-2. The value of the quotient is stored in identifier-3 and the value of the remainder is stored in identifier-4.

Syntax -

DIVIDE Statement with BY and REMAINDER phrases

identifier-1, identifier-2 -

Must name an elementary numeric data item. identifier-1 and identifier-2 cannot be date fields.

identifier-3, identifier-4 -

Must name an elementary numeric or numeric-edited item.

literal-1, literal-2 -

Must be a numeric literal. In formats 1, 2 and 3, floating-point data items/literals can be used anywhere that a numeric data item/literal can be specified. In formats 4 and 5, floating-point data items/literals can't be used. ROUNDED phrase

For formats 1, 2 and 3, ROUNDED phrase applies. For formats 4 and 5, the quotient value truncated rather than rounded.

REMAINDER phrase -

REMAINDER phrase used to store the remainder value left to identifier-4. The REMAINDER phrase is valid if the receiver or any of the operands are numeric or numeric-edited items.

The REMAINDER phrase is invalid if the receiver or any of the operands is a floating-point item. SIZE ERROR phrase

For formats 1, 2 and 3, SIZE ERROR phrase applies. For formats 4 and 5, if a size error occurs in the quotient, the contents of the quotient field (identifier-3) and the remainder field (identifier-4) are unchanged.

If size error occurs in the remainder, the contents of the remainder field (identifier-4) are unchanged. In the above two cases, the results must be analysed to determine which situation has occurred.

END-DIVIDE phrase -

The END-DIVIDE used to end the scope of the DIVIDE statement. END-DIVIDE is not required when DIVIDE statement ended with period.