The DIVIDE statement divides one numeric data item into others and sets the values of data items equal to the quotient and
General Formats for Format 1
General Formats for Format 2
General Formats for Format 3
General Formats for Format 4
General Formats for Format 5
Syntax Rules for All Formats
- Each identifier must refer to an elementary numeric item, except that any identifier associated with the GIVING or REMAINDER
phrase must refer to either an elementary numeric item or an elementary numeric edited item.
- Each literal must be a numeric literal.
- The composite of operands is determined by using all receiving data items except the REMAINDER data item. See the topic
Arithmetic Statements in the chapter
- When Format 1, 2, or 3 is used, floating-point data items and literals can be used anywhere a numeric data item or literal
can be specified. When Format 4 or 5 is used, no floating-point data items or literals may be specified.
General Rules for All Formats
- See the topics
The ROUNDED Phrase,
The ON SIZE ERROR Phrase,
Overlapping Operands and
Multiple Results in Arithmetic Statements in the chapter
Procedure Division; the section
Explicit and Implicit Scope Terminators in the chapter
Concepts of the COBOL Language, and the section
Delimited Scope Statements in the chapter
Language Fundamentals. .
General Rules for Format 1
- When Format 1 is used, literal-1 or the value of the data item referenced by identifier-1 is stored in a temporary data item.
The value in this temporary data item is then divided into the value of identifier-2. The value of the dividend (the value
of the data item referenced by identifier-2) is replaced by this quotient; similarly, the temporary data item is divided into
each successive occurrence of identifier-2 in the left-to-right order in which identifier-2 is specified.
General Rules for Format 2
- When Format 2 is used, the value of identifier-1 or literal-1 is divided into identifier-2 or literal-2 and the result is
stored in each data item referenced by identifier-3.
General Rules for Format 3
- When Format 3 is used, the value of identifier-1 or literal-1 is divided by the value of identifier-2 or literal-2 and the
result is stored in each data item referenced by identifier-3.
General Rules for Formats 4 and 5
- Formats 4 and 5 are used when a remainder from the division operation is desired, namely identifier-4. The remainder in COBOL
is defined as the result of subtracting the product of the quotient (identifier-3) and the divisor from the dividend. If identifier-3
is defined as a numeric edited item, the quotient used to calculate the remainder is an intermediate field which contains
the unedited quotient. If ROUNDED is used, the quotient used to calculate the remainder is an intermediate field which contains
the quotient of the DIVIDE statement, truncated rather than rounded.
- In Formats 4 and 5, the accuracy of the REMAINDER data item (identifier-4) is defined by the calculation described above.
Appropriate decimal alignment truncation (not rounding) is performed for the content of the data item referenced by identifier-4,
- When the ON SIZE ERROR phrase is used in Formats 4 and 5, the following rules pertain:
- If the size error condition occurs on the quotient, no remainder calculation is meaningful. Thus, the contents of the data
items referenced by both identifier-3 and identifier-4 ill remain unchanged.
- If the size error condition occurs on the remainder, the contents of the data item referenced by identifier-4 remains unchanged.
However, as with other instances of multiple results of arithmetic statements, you will have to do your own analysis to recognize
which situation has actually occurred.