The ADD statement adds two or more numeric operands and stores the result.
The ADD statement has three formats:
ADD Statement - Format 1 - ADD
.------------------.
V |
>>-ADD----+-identifier-1-+-+--TO-------------------------------->
'-literal-1----'
.---------------------------.
V |
>----identifier-2--+---------+-+-------------------------------->
'-ROUNDED-'
>--+--------------------------------------------+--------------->
'-+----+--SIZE ERROR--imperative-statement-1-'
'-ON-'
>--+-------------------------------------------------+---------->
'-NOT--+----+--SIZE ERROR--imperative-statement-2-'
'-ON-'
>--+---------+-------------------------------------------------><
'-END-ADD-'
In Format 1, identifiers and literals preceding the keyword TO are added together, and this initial sum is added to and stored in identifier-2. The initial sum is also added to each successive occurrence of identifier-2, in the left-to-right order in which identifier-2 is specified.
ADD Statement - Format 2 - ADD GIVING
.------------------.
V |
>>-ADD----+-identifier-1-+-+--+----+--+-identifier-2-+---------->
'-literal-1----' '-TO-' '-literal-2----'
.---------------------------.
V |
>--GIVING----identifier-3--+---------+-+------------------------>
'-ROUNDED-'
>--+--------------------------------------------+--------------->
'-+----+--SIZE ERROR--imperative-statement-1-'
'-ON-'
>--+-------------------------------------------------+---------->
'-NOT--+----+--SIZE ERROR--imperative-statement-2-'
'-ON-'
>--+---------+-------------------------------------------------><
'-END-ADD-'
In Format 2, the values of the operands preceding the word GIVING are added together, and the sum is stored as the new value of each data item referenced by identifier-3.
ADD Statement - Format 3 - ADD CORRESPONDING
>>-ADD--+-CORRESPONDING-+--------------------------------------->
'-CORR----------'
>--identifier-4--TO--identifier-5--+---------+------------------>
'-ROUNDED-'
>--+--------------------------------------------+--------------->
'-+----+--SIZE ERROR--imperative-statement-1-'
'-ON-'
>--+-------------------------------------------------+---------->
'-NOT--+----+--SIZE ERROR--imperative-statement-2-'
'-ON-'
>--+---------+-------------------------------------------------><
'-END-ADD-'
In Format 3, elementary data items within identifier-4 are added to and stored in the corresponding elementary items within identifier-5.
For all Formats:
In Format 1, the composite of operands is determined by using all of the operands in a given statement.
In Format 2, the composite of operands is determined by using all of the operands in a given statement excluding the data items that follow the word GIVING.
In Format 3, the composite of operands is determined separately for each pair of corresponding data items.
For more information on the composite of operands, see the Size of Operands.
+-------------------------------IBM Extension--------------------------------+
Floating-point data items and literals can be used anywhere a numeric data item or literal can be specified.
+----------------------------End of IBM Extension----------------------------+
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.