ADD statement

The ADD statement sums two or more numeric operands and stores the result.

Format 1: ADD statement

Read syntax diagramSkip visual syntax diagramADDidentifier-1literal-1TOidentifier-2ROUNDEDONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-ADD

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.

Format 2: ADD statement with GIVING phrase

Read syntax diagramSkip visual syntax diagramADDidentifier-1literal-1TOidentifier-2literal-2GIVING identifier-3ROUNDED ONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-ADD

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.

Format 3: ADD statement with CORRESPONDING phrase

Read syntax diagramSkip visual syntax diagramADDCORRESPONDINGCORRidentifier-1TOidentifier-2ROUNDEDONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-ADD

Elementary data items within identifier-1 are added to and stored in the corresponding elementary items within identifier-2.

For all formats:

identifier-1, identifier-2
In format 1, must name an elementary numeric item.

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.

literal
Must be a numeric literal.

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 Appendix A. Intermediate results and arithmetic precision in the Enterprise COBOL Programming Guide.

ROUNDED phrase

For formats 1, 2, and 3, see ROUNDED phrase.

SIZE ERROR phrases

For formats 1, 2, and 3, see SIZE ERROR phrases.

CORRESPONDING phrase (format 3)

See CORRESPONDING phrase.

END-ADD 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.