The SUBTRACT statement is used to subtract one, or the sum of two or more, numeric data items from a numeric data item and store the result.

Format 1:Subtract…From


Format 2:Subtract…Giving


Format 3:Subtract Corresponding

Subtract Corresponding

In Format 1, all literals or identifiers preceding the word FROM are added together and the sum is stored in a temporary data item.The value of this temporary data item is subtracted from the value of the data item specified by identifier-3, storing the result into the data item specified by identifier-3, and repeating this process for each successive occurrence of identifier-3 in the left-to-right order in which identifier-3 is specified.

In Format 2, all literals or identifiers preceding the word FROM are added together, the sum is subtracted from literal-2 or identifier-2 and the result of the subtraction is stored as the new value of identifier-3.

If Format 3 is used, data items in identifier-1 are subtracted from and stored into corresponding data items in identifier-2.

Each identifier must refer to a numeric elementary item except that:

  • In Format 2, the identifier following the word GIVING must refer to either an elementary numeric item or an elementary numeric edited item
  • In Format 3, the identifiers must refer to group items.

Each literal must be a numeric literal.

Additional rules and explanations regarding features of the SUBTRACT 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.



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

For the SUBTRACT 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 id entifier-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-1 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 subtractions are completed.

CORR is an abbreviation for CORRESPONDING.

SUBTRACT Statement Examples

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

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

COBOL Topics