The ADD statement sums two or more numeric operands and stores the result.
All identifiers or literals that precede the keyword TO are added together, and this sum is added to and stored in identifier-2. This process is repeated for each successive occurrence of identifier-2 in the left-to-right order in which identifier-2 is specified.
The values of the operands that precede the word GIVING are added together, and the sum is stored as the new value of each data item referenced by identifier-3.
Elementary data items within identifier-1 are added to and stored in the corresponding elementary items within identifier-2.
For all formats:
In format 2, must name an elementary numeric item except when following the word GIVING. Each identifier that follows the word GIVING must name an elementary numeric or numeric-edited item.
In format 3, must name an alphanumeric group item or national group item.
The following restrictions apply to date fields:
If neither identifier-1 nor identifier-2 specifies a date field, identifier-3 can specify one or more date fields without any restriction on the date formats.
There are two steps to determining the result of an ADD statement that involves one or more date fields:
Floating-point data items and literals can be used anywhere that a numeric data item or literal can be specified.
When the ARITH(COMPAT) compiler option is in effect, the composite of operands can contain a maximum of 30 digits. When the ARITH(EXTEND) compiler option is in effect, the composite of operands can contain a maximum of 31 digits. For more information, see Arithmetic statement operands and the details on arithmetic intermediate results in the COBOL for Windows Programming Guide.
For formats 1, 2, and 3, see ROUNDED phrase.
For formats 1, 2, and 3, see SIZE ERROR phrases.
See CORRESPONDING phrase.
This explicit scope terminator serves to delimit the scope of the ADD statement. END-ADD permits a conditional ADD statement to be nested in another conditional statement. END-ADD can also be used with an imperative ADD statement.
For more information, see Delimited scope statements.