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.

The DIVIDE statement is used to divide numeric items together. Both formats work slightly differently and each is described below,The first format is used to divide a field(s) or value(s) by another field or value. The field or value listed between DIVIDE and INTO is divided into the value of the field(s) following the INTO. The answer is stored if the individual field.

DIVIDE {indentifier-1 or literal-1}...INTO {identifier-2 [ROUNDED]}... [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-DIVIDE] |

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.

DIVIDE A INTO B |

- The value in A is divided into the value in B and the result is stored in B. The value in A is unchanged.

DIVIDE C INTO D E |

- The value in C is divided into the value in D, storing the ans er in D; the value of C is also divided into E, storing the value in E. The value in C is unchanged.

The second format is used to divide field(s) or value(s) by one another, storing the answer in a different field. The field(s) or value(s) listed between DIVIDE and GIVING are divided and stored in the field following the field(s) following the GIVING.

DIVIDE {indentifier-1 or literal-1}...INTO {identifier-2 or literal-2} GIVING {identifier-3 [ROUNDED]}... [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-DIVIDE] |

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.

DIVIDE A INTO B GIVING C |

- The value in A is divided into the value in B and the result is stored in C. The values in A and B are unchanged.

The third format is also used to divide field(s) or value(s) by one another, storing the answer in a different field. The field(s) or value(s) listed between DIVIDE and GIVING are divided and stored in the field following the field(s) following the GIVING.

DIVIDE {indentifier-1 or literal-1} BY {identifier-2 or literal-2} GIVING {identifier-3 [ROUNDED]}... [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-DIVIDE] |

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.

DIVIDE A BY B GIVING C |

- The value in A is divided by the value in B and the result is stored in C. The values in A and B are unchanged.

The fourth format is used to divide field(s) or value(s) by one another, storing the answer in a different field. The field(s) or value(s) listed between DIVIDE and GIVING are divided and stored in the field following the field(s) following the GIVING.

DIVIDE {indentifier-1 or literal-1} INTO {identifier-2 or literal-2} GIVING identifier-3 [ROUNDED] REMAINDER identifier-4 [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-DIVIDE] |

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.

DIVIDE A INTO B GIVING C REMAINDER D- The value in A is divided into the value in B and the results stored in C with the remainder being stored in D. The values in A and B are unchanged.

The fifth format is also used by divide field(s) or value(s) by one another, storing the answer in a different field. The field(s) or value(s) listed between DIVIDE and GIVING are divided and stored in the field following the field(s) following the GIVING.

DIVIDE {indentifier-1 or literal-1} BY {identifier-2 or literal-2} GIVING identifier-3 [ROUNDED] REMAINDER identifier-4 [ON SIZE ERROR imperative-statement-1] [NOT ON SIZE ERROR imperative-statement-2] [END-DIVIDE] |

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.

DIVIDE A BY B GIVING C REMAINDER D |

- The value in A is divided by the value in B and the result is stored in C with the remainder being stored in D. The values in A and B are unchanged.

If identifier-3 or identifier-4 is a date field, see Storing arithmetic results that involve date fields for details on how the quotient or remainder is stored in identifier-3.

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.

Optional phrases in DIVIDE operation:

With ROUNDED option, the computer will always round the result to the PICTURE clause specification of the receiving field. It is usually coded after the field to be rounded.

If this is coded with any operation that ended with SIZE error will not be carried out but the statement follows ON SIZE ERROR will be executed.

This is opposite to SIZE ERROR. If this is coded with any operation that not ended with SIZE error, then the statement follows ON SIZE ERROR will be executed.

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

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.

- The fields to be divided must have numeric pictures, that is, they can only have the characters 9, S, and V in their PIC clauses.

- Receiving fields may be either numeric or numeric edited fields.

- Use the SIZE ERROR clause to detect field overflow on the receiving field.

- In all formats, the mathematically correct results are computed, but if the receiving field is too short in either the integer or decimal portion, the result will be truncated, the integer on the left and the decimal on the right.

Including the ROUNDED phrase will result the answer field being rounded instead of truncating. Rounding is always done in the least significant portion of the answer result the answer field being rounded instead of truncating. Rounding is always done in the least significant portion of the answer

* If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!*