The DIVIDE Statement
Syntax
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]
Format 2
DIVIDE { identifier-1
literal-1 } INTO { identifier-2
literal-2 } GIVING {identifier-3 [ROUNDED]}...
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]
Format 3
DIVIDE { identifier-1
literal-1 } BY { identifier-2
literal-2 } GIVING {identifier-3 [ROUNDED]}...
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-DIVIDE]
Format 4
DIVIDE { identifier-1
literal-1 } INTO { 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]
Format 5
DIVIDE { identifier-1
literal-1 } 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]
Description
The DIVIDE statement is used to divide numeric items together. Both formats work slightly differently and each is described in the correspondingly numbered area.
1. 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. For example, in 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. Furthermore, in DIVIDE C INTO D E, the value in C is divided into the value in D, storing the answer in D; the value of C is also divided into E, storing the value in E. The value in C is unchanged.
2. 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. For example, in 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.
3. 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. For example, in 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.
4. The fourtb 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. For example, in DIVIDE A INTO B GIVING C REMAINDER D, the value in A is divided into the value in B and the resultis stored in C with the remainder being stored in D. The values in A and B are unchanged.
5. 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. For example, in 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.
Tips
1. 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.
2. Receiving fields may be either numeric or numeric edited fields.
3. Use the SIZE ERROR clause to detect field overflow on the receiving field.
4. 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
Posted by
KK
at
5:22 AM