ADD Statement COBOL

The ADD statement causes two or more numeric operands to be summed and the result to be stored.

Format 1:Add…To

ADD Statement

Format 2:Add…Giving

Add…Giving

Format 3:Add Corresponding

Add Corresponding

In Format 1, the values of the operands preceding the word TO are added together; that sum is then added to the current value of each data item referenced by identifier-2 storing the result immediately into that data item.

In Format 2, the values of the operands preceding the word GIVING are added together; that sum is then stored as the new value of each data item referenced by identifier-3.

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 may refer to either an elementary numeric item or an elementary numeric edited item.

In Format 3, data items in identifier-1 are added to and stored in the corresponding data items in identifier-2.

In Format 3, each identifier must refer to a group item.

Each literal must be a numeric literal.

Additional rules and explanations regarding features of the ADD statement that are common to other arithmetic statements can be found in the discussion of common rules.See in particular the discussions of the ROUNDED phrase, the size error condition, overlapping operands, modes of operation, composite size, and incompatible data.

CORRESPONDING Phrase

CORRESPONDING Phrase

If the CORRESPONDING phrase is used, selected items within identifier-1 are added to, and the result stored in, the corresponding items in identifier-2.

For the ADD statement with the CORRESPONDING phrase:

  • The description of identifier-1 and identifier-2 must not contain level-number 66, 77, 78, or 88 or the USAGE IS INDEX clause.
  • Neither identifier-1 nor identifier-2 may be reference modified.
  • identifier-1 or identifier-2 may be described with the OCCURS or REDEFINES clauses or be subordinate to data items described with the OCCURS or REDEFINES clauses.If identifier-1 or identifier-2 is a table element, then the required subscripting must be specified as part of identifier-1 or identifier-2.The specified subscripting will be applied to the selected subordinate corresponding data items, respectively, for identifier-1 and identifier-2.

The rules that govern the selection of eligible subordinate data item pairs are as follows:

  1. The data items are not designated by the keyword FILLER and have the same data-name and the same qualifiers up to but not including the original group items, identifier-1 and identifier-2.
  2. Both of the data items are elementary numeric data items.
  3. A data item that is subordinate to identifier-1 or identifier-2 and contains a REDEFINES, OCCURS, USAGE IS INDEX, or USAGE IS POINTER clause is ignored, as well as those data items subordinate to the data item that contains the REDEFINES, OCCURS, USAGE IS INDEX, or USAGE IS POINTER clause.
  4. The name of each data item that satisfies the above conditions must be unique after application of the implied qualifiers.

If any of the individual operations produces a size error condition, imperative-statement-1 in the ON SIZE ERROR phrase is not executed until all of the individual additions are completed. CORR and CORRESPONDING are synonymous.

ADD Statement Examples



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics