DIVIDE statement

The DIVIDE statement divides one numeric data item into or by others and sets the values of data items equal to the quotient and remainder.

Format 1: DIVIDE statement

Read syntax diagramSkip visual syntax diagramDIVIDEidentifier-1literal-1INTOidentifier-2ROUNDEDONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-DIVIDE

In format 1, the value of identifier-1 or literal-1 is divided into the value of identifier-2, and the quotient is then stored in identifier-2. For each successive occurrence of identifier-2, the division takes place in the left-to-right order in which identifier-2 is specified.

Format 2: DIVIDE statement with INTO and GIVING phrases

Read syntax diagramSkip visual syntax diagramDIVIDEidentifier-1literal-1INTOidentifier-2literal-2GIVING identifier-3ROUNDED ONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-DIVIDE

In format 2, 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 each data item referenced by identifier-3.

Format 3: DIVIDE statement with BY and GIVING phrases

Read syntax diagramSkip visual syntax diagramDIVIDEidentifier-1literal-1BYidentifier-2literal-2GIVING identifier-3ROUNDED ONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-DIVIDE

In format 3, 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 each data item referenced by identifier-3.

Format 4: DIVIDE statement with INTO and REMAINDER phrases

Read syntax diagramSkip visual syntax diagramDIVIDEidentifier-1literal-1INTOidentifier-2literal-2GIVINGidentifier-3ROUNDED REMAINDERidentifier-4ONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-DIVIDE

In format 4, 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.

Format 5: DIVIDE statement with BY and REMAINDER phrases

Read syntax diagramSkip visual syntax diagramDIVIDEidentifier-1literal-1BYidentifier-2literal-2GIVINGidentifier-3ROUNDED REMAINDERidentifier-4ONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-DIVIDE

In format 5, 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.

For all formats:

identifier-1, identifier-2
Must name an elementary numeric data item.
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 and literals can be used anywhere that a numeric data item or literal can be specified.

In formats 4 and 5, floating-point data items or literals cannot be used.

ROUNDED phrase

For formats 1, 2, and 3, see ROUNDED phrase.

For formats 4 and 5, the quotient used to calculate the remainder is in an intermediate field. The value of the intermediate field is truncated rather than rounded.

REMAINDER phrase

The result of subtracting the product of the quotient and the divisor from the dividend is stored in identifier-4. If identifier-3, the quotient, is a numeric-edited item, the quotient used to calculate the remainder is an intermediate field that contains the unedited quotient.

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

Any subscripts for identifier-4 in the REMAINDER phrase are evaluated after the result of the divide operation is stored in identifier-3 of the GIVING phrase.

SIZE ERROR phrases

For formats 1, 2, and 3, see SIZE ERROR phrases.

For formats 4 and 5, if a size error occurs in the quotient, no remainder calculation is meaningful. Therefore, 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 either of these cases, you must analyze the results to determine which situation has actually occurred.

For information about the NOT ON SIZE ERROR phrase, see SIZE ERROR phrases.

END-DIVIDE phrase

This explicit scope terminator serves to delimit the scope of the DIVIDE statement. END-DIVIDE turns a conditional DIVIDE statement into an imperative statement that can be nested in another conditional statement. END-DIVIDE can also be used with an imperative DIVIDE statement.

For more information, see Delimited scope statements.