The ADD statement causes two or more numeric operands to be summed and the result to be stored.
General Formats for Format 1
General Formats for Format 2
General Formats for Format 3
Syntax Rules for All Formats
- In Formats 1 and 2, each identifier must refer to an elementary numeric item, except that in Format 2 each identifier following
the word GIVING must refer to either an elementary numeric item or an elementary numeric edited item. In Format 3, each identifier
must refer to a group item.
- Each literal must be a numeric literal.
- The composite of operands is determined as follows (see the topic
Arithmetic Statements in the chapter
Procedure Division):
- In Format 1, by using all of the operands in a given statement.
- In Format 2, by using all of the operands in a given statement excluding the data items that follow the word GIVING.
- In Format 3, separately for each corresponding pair of data items.
- In Format 3, CORR is an abbreviation for CORRESPONDING.
- Floating-point literals and floating-point data items can be used anywhere a numeric data item or literal can be specified.
General Rules for All Formats
- See the topics
The ROUNDED Phrase,
The ON SIZE ERROR Phrase,
The CORRESPONDING Phrase,
Arithmetic Statements,
Overlapping Operands and
Multiple Results in Arithmetic Statements in the chapter
Procedure Division; the section
Explicit and Implicit Scope Terminators in the chapter
Concepts of the COBOL Language, and the section
Delimited Scope Statements in the chapter
Language Fundamentals.
- If Format 1 is used, the values of the operands preceding the word TO are added together, then this sum is added to the current
value of identifier-2 storing the result immediately into identifier-2, and repeating this process respectively for each successive
operand following the word TO in left-to-right order.
- If Format 2 is used, the value of the operands preceding the word GIVING are added together, then the sum is stored as the
new value of each data item referenced by identifier-3, the resultant identifier.
- If Format 3 is used, data items in identifier-1 are added to and stored in corresponding data items in identifier-2.
- Your COBOL system ensures that enough places are carried so as not to lose any significant digits during execution.