Function
The ADD statement causes two or more numeric operands to be summed and the result to be stored.
Format 1 | of the ADD statement stores the sum in one of the operand items. More than one addition may be expressed by specifying more than one result item in the same ADD statement. |
Format 2 | of the ADD statement stores the sum in a separate result item. |
Format 3 | of the ADD statement adds the data items of one group item to the corresponding data items of another group item. |
Format 1
ADD {identifier-1 | literal-1}... TO {identifier-2 [ROUNDED]}...
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-ADD]
Syntax rules
Each identifier must refer to an elementary numeric item.
The composite of operands is determined by using all of the operands in a given statement and must not contain more than 31 digits (see "Arithmetic statements").
The values of the operands preceding the word TO are added together and the sum is added to the current value of identifier-2... The result is stored in identifier-2 ...
Additional rules are given under "Options in arithmetic statements" ( Phrases in statements et seq.), where the ROUNDED phrase and the (NOT) ON SIZE ERROR phrase are described.
Example 8-21
Statement | PICTURE IS of result item | Calculation |
ADD A, B TO C, D | A + B + C stored in C | |
ADD A, B, C TO D | S9999V99 | A + B + C + D stored in D as SnnnnVnn |
ADD A, 14 TO C | 99999 | A + 14 + C stored in C as nnnnn; rounded if necessary |
Format 2
ADD {identifier-1 | literal-1}... TO {identifier-2 | literal-2} GIVING {identifier-3 [ROUNDED]}...
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-ADD]
Syntax rules
Each identifier preceding the GIVING phrase must refer to an elementary numeric item.
identifier-3 may refer either to an elementary numeric item or to an elementary numericedited data item.
The composite of operands is determined by using all of the operands in a given statement, excluding the data items which follow the word GIVING, and must not contain more than 31 digits (see "Arithmetic statements").
The values of the operands preceding the word GIVING are added together, and the sum is stored as the new value of identifier-3.
Additional rules are given under "Options in arithmetic statements" ( Phrases in statements et seq.), where the GIVING, ROUNDED, and (NOT) ON SIZE ERROR phrases are described.
Example 8-22
Statement | PICTURE IS of result item | Calculation |
ADD A, B, C GIVING D. | 9999.99 | A + B + C stored in D as nnnn.nn |
ADD A, B, 43.6 GIVING D | 99V99 | A + B + 43.6 stored in D. If the integer result is greater than 2 digits, the size error condition occurs and the GO TO statement specified in the SIZE ERROR phrase is executed. |
Format 3
ADD {CORR | CORRESPONDING} identifier-1 TO identifier-2 [ROUNDED]
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-ADD]
Syntax rules
Each identifier must refer to a group item.
The composite of operands is determined separately for each pair of corresponding data items, and must not contain more than 31 digits (see "Arithmetic statements").
Elementary items within the first operand (identifier-1) are added to the corresponding elementary items in the second operand (identifier-2 ...). The results are stored in the items of the second operand.
Additional rules are given under "Options in arithmetic statements" ( Phrases in statements et seq.), where the CORRESPONDING, ROUNDED, and (NOT) ON SIZE ERROR phrases are described.
Example 8-23
Refer to the description of the CORRESPONDING phrase for an example of the use of this option ( CORRESPONDING phrase ).