ADD Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
ADD Statement
The ADD statement computes the sum of two or more operands and stores the
result.
Syntax
Parameters
In format 1 and 2, identifier-1, identifier-2, and so forth must refer to
elementary numeric items, except that in format 2, each identifier
following the word GIVING may also be an edited numeric data item. Also,
the word literal means numeric literal.
In format 3, both identifiers must refer to group items.
Description
When format 1 is used, the values of all identifiers and literals to the
left of the keyword TO are added together and the resulting sum is added
to the current contents of identifier-2. The results are then stored
into identifier-2. This process of adding the resulting sum to an
identifier and then storing the results into the identifier is continued
until all identifiers to the right of the TO keyword have been used.
When format 2 is used, all literals and values of identifiers to the left
of the GIVING keyword are added, and the result is stored into each
identifier named to the right of the GIVING keyword.
When format 3 is used, data items in identifier-1 are added to
corresponding data items in identifier-2. The results are stored in
corresponding data items of identifier-2. Thus, format 3 is equivalent
to using format 1 for each pair of corresponding data items.
See Chapter 8 for details on the ROUNDED, SIZE ERROR, and
CORRESPONDING phrases.
The composite of operands must not exceed 18 digits (see "Arithmetic
Expressions" in Chapter 8 ). In format 1, it is calculated by using
all of the operands in the statement; in format 2, it is calculated using
all of the operands to the left of the GIVING phrase; in format 3, the
composite of operands is calculated using pairs of corresponding data
items.
During execution, the compiler always ensures that enough places are
carried to avoid losing any significant digits.
For an example of format 3 usage, refer to "CORRESPONDING Phrase" in
Chapter 8 . For an example of format 1 usage refer to "Arithmetic
Expressions" in Chapter 8 .
Example
Following is an example of the ADD statement using format 2.
The operands and their assumed values are:
01 SUM-IT PICTURE 9(9)V999. Assumed value is 329^182
01 SUM-AT PICTURE 999V9. Assumed value is 203^9
The receiving data items are:
01 TAKE-1 PICTURE 9(9)V999.
01 TAKE-2 PICTURE 9(8)V9.
The example ADD statement is:
ADD SUM-IT, SUM-AT GIVING TAKE-1
TAKE-2 ROUNDED
ON SIZE ERROR PERFORM
REPORT-IT.
The composite of operands is: 329^182
The results of the ADD statament are:
TAKE-1 has the value 533^082
TAKE-2 has the value 533^1 because of the ROUNDED phrase.
MPE/iX 5.0 Documentation