The data descriptions of operands in an arithmetic statement need not be the same. Throughout the calculation, the compiler performs any necessary data conversion and decimal point alignment.
If the ARITH(COMPAT) compiler option is in effect, the maximum size of each operand is 18 decimal digits. If the ARITH(EXTEND) compiler option is in effect, the maximum size of each operand is 31 decimal digits.
The composite of operands is a hypothetical data item resulting from aligning the operands at the decimal point and then superimposing them on one another.
If the ARITH(COMPAT) compiler option is in effect, the composite of operands can be a maximum of 30 digits. If the ARITH(EXTEND) compiler option is in effect, the composite of operands can be a maximum of 31 digits.
The following table shows how the composite of operands is determined for arithmetic statements:
| Statement | Determination of the composite of operands |
|---|---|
| SUBTRACT
ADD |
Superimposing all operands in a given statement except those following the word GIVING |
| MULTIPLY | Superimposing all receiving data items |
| DIVIDE | Superimposing all receiving data items except the REMAINDER data item |
| COMPUTE | Restriction does not apply |
For example, assume that each item is defined as follows in the data division:
A PICTURE 9(7)V9(5). B PICTURE 9(11)V99. C PICTURE 9(12)V9(3).
If the following statement is executed, the composite of operands consists of 17 decimal digits:
ADD A B TO C
It has the following implicit description:
COMPOSITE-OF-OPERANDS PICTURE 9(12)V9(5).
In the ADD and SUBTRACT statements, if the composite of operands is 30 digits or less with the ARITH(COMPAT) compiler option, or 31 digits or less with the ARITH(EXTEND) compiler option, the compiler ensures that enough places are carried so that no significant digits are lost during execution.
In all arithmetic statements, it is important to define data with enough digits and decimal places to ensure the desired accuracy in the final result. For more information, see the section on intermediate results in the COBOL for Windows Programming Guide.
When operands in an arithmetic statement share part of their storage (that is, when the operands overlap), the result of the execution of such a statement is unpredictable.
When an arithmetic statement has multiple results, execution conceptually proceeds as follows:
For example, executing the following statement:
ADD A, B, C, TO C, D(C), E.
is equivalent to executing the following series of statements:
ADD A, B, C GIVING TEMP. ADD TEMP TO C. ADD TEMP TO D(C). ADD TEMP TO E.
In the above example, TEMP is a compiler-supplied temporary result field. When the addition operation for D(C) is performed, the subscript C contains the new value of C.