Library View Topics Framed Contents Revised Topics Previous Topic Next Topic Search Search ResultsPrevious Topic MatchNext Topic Match Notes List Notes Print Download No PDF Handheld DisconnectedHandheld ConnectedHelp

6.2.2 ADD Statement



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


    ___ Format 1 ___________________________________________________________ 
   |                                                                        |
   |          <__________________       <___________________________        |
   | >>__ADD____ _identifier-1_ _|__TO____identifier-2__ _________ _|_____> |
   |            |_literal-1____|                        |_ROUNDED_|         |
   |                                                                        |
   | >__ ____________________________________________ ____________________> |
   |    |_ ____ __SIZE ERROR__imperative-statement-1_|                      |
   |      |_ON_|                                                            |
   |                                                                        |
   | >__ _________________________________________________ _______________> |
   |    |_NOT__ ____ __SIZE ERROR__imperative-statement-2_|                 |
   |           |_ON_|                                                       |
   |                                                                        |
   | >__ _________ ______________________________________________________>< |
   |    |_END-ADD_|                                                         |
   |                                                                        |
   |________________________________________________________________________|
All identifiers or literals preceding the key word 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____ _identifier-1_ _|__ ____ __ _identifier-2_ ______________> |
   |            |_literal-1____|    |_TO_|  |_literal-2____|                |
   |                                                                        |
   |            <___________________________                                |
   | >__GIVING____identifier-3__ _________ _|_____________________________> |
   |                            |_ROUNDED_|                                 |
   |                                                                        |
   | >__ ____________________________________________ ____________________> |
   |    |_ ____ __SIZE ERROR__imperative-statement-1_|                      |
   |      |_ON_|                                                            |
   |                                                                        |
   | >__ _________________________________________________ _______________> |
   |    |_NOT__ ____ __SIZE ERROR__imperative-statement-2_|                 |
   |           |_ON_|                                                       |
   |                                                                        |
   | >__ _________ ______________________________________________________>< |
   |    |_END-ADD_|                                                         |
   |                                                                        |
   |________________________________________________________________________|
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.


    ___ Format 3 ___________________________________________________________ 
   |                                                                        |
   | >>__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
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 following the word GIVING must name an elementary numeric or numeric-edited item.

In Format 3, must name a group item.


X The following restrictions apply to date fields:

  • X In Format 1, identifier-2 may specify one or more date fields;
    X identifier-1 must not specify a date field.
    
    
  • X In Format 2, either identifier-1 or identifier-2 (but not both)
    X may specify at most one date field. If identifier-1 or
    X identifier-2 specifies a date field, then every instance of
    X identifier-3 must specify a date field that is compatible with the
    X date field specified by identifier-1 or identifier-2. That is,
    X they must have the same date format, except for the year part,
    X which may be windowed or expanded.
    
    

    X If neither identifier-1 nor identifier-2 specifies a date field,
    X then identifier-3 may specify one or more date fields without any
    X restriction on the date formats.
    
    
  • X In Format 3, only corresponding elementary items within
    X identifier-2 may be date fields. There is no restriction on the
    X format of these date fields.
    
    
  • | A year-last date field is allowed in an ADD statement only as
    | identifier-1 and when the result of the addition is a non-date
    
    


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

  1. X Addition: determine the result of the addition operation, as
    X described under "Addition Involving Date Fields" in
    X topic 6.1.5.2.1.
    
    
  2. X Storage: determine how the result is stored in the receiving
    X field. (In Formats 1 and 3, the receiving field is identifier-2;
    X in Format 3, the receiving field is the GIVING identifier-3.) For
    X details, see "Storing Arithmetic Results That Involve Date Fields"
    X in topic 6.1.5.2.3.
    
    

literal
Must be a numeric literal.


X Floating-point data items and literals can be used anywhere a numeric
X data item or literal can be specified.

The composite of operands must not contain more than 18 digits. The compiler ensures that enough places are carried so that no significant digits are lost during execution.


X The composite of operands can be more than 18 digits. For information on
X arithmetic intermediate results, see the IBM COBOL Programming Guide for
X your platform.

Subtopics:



Previous Topic Next Topic © Copyright IBM Corp. 1991, 1998

IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.





Return to library:   z/OS | z/OS.e | TPF | z/VSE | z/VM | IBM Hardware | IBM System z Redbooks
Glossary:   IBM terminology
Publications:   How to order publications
Readers:   Download IBM Library Reader | Download IBM Softcopy Reader | Download Adobe® Acrobat® Reader®
Library management:   Download IBM Softcopy Librarian
Contacts:   Contact z/OS


Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.