Rational Developer for System z
COBOL for Windows, Version 7.5, Language Reference


ADD statement

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

Format 1
Read syntax diagramSkip visual syntax diagram        .------------------.      
        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-'  
 

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
Read syntax diagramSkip visual syntax diagram        .------------------.                            
        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-'  
 

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
Read syntax diagramSkip visual syntax diagram>>-ADD--+-CORRESPONDING-+--identifier-1--TO--identifier-2------->
        '-CORR----------'                                  
 
>--+---------+-------------------------------------------------->
   '-ROUNDED-'  
 
>--+--------------------------------------------+--------------->
   '-+----+--SIZE ERROR--imperative-statement-1-'  
     '-ON-'                                        
 
>--+-------------------------------------------------+---------->
   '-NOT--+----+--SIZE ERROR--imperative-statement-2-'  
          '-ON-'                                        
 
>--+---------+-------------------------------------------------><
   '-END-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.

The following restrictions apply to date fields:

There are two steps to determining the result of an ADD statement that involves one or more date fields:

  1. Addition: determine the result of the addition operation, as described under Addition that involves date fields.
  2. Storage: determine how the result is stored in the receiving field. (In formats 1 and 3, the receiving field is identifier-2; in Format 3, the receiving field is the GIVING identifier-3.) For details, see Storing arithmetic results that involve date fields.
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 the COBOL for Windows 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.


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)