The SUBTRACT Statement

The SUBTRACT statement is used to subtract one, or the sum of two or more, numeric data items from one or more items, and set the values of one or more items equal to the results.

General Formats for Format 1


SUBTRACT - FORMAT 1

General Formats for Format 2


SUBTRACT - FORMAT 2

General Formats for Format 3


SUBTRACT - FORMAT 3

Syntax Rules for All Formats

  1. Each identifier must refer to a numeric elementary item, except that in Format 2 each identifier following the word GIVING must refer to either an elementary numeric item or an elementary numeric edited item, and in Format 3 each identifier must refer to a group item.
  2. The composite of operands is determined as follows (see the topic Arithmetic Statements in the chapter Procedure Division):
    1. In Format 1, by using all of the operands in a given statement.
    2. In Format 2, by using all of the operands in a given statement excluding the data items that follow the word GIVING.
    3. In Format 3, separately for each pair of corresponding data items.

Syntax Rules for Formats1 and 2

  1. Each literal must be a numeric literal.
  2. OSVSVSC2MF Floating-point data items and literals can be used anywhere numeric data items and literals can be specified.

Syntax Rules for Format 3

  1. CORR is an abbreviation for CORRESPONDING.

General Rules for All Formats

  1. See the topics The ROUNDED Phrase, The ON SIZE ERROR Phrase, Arithmetic Statements, Overlapping Operands and Multiple Results In Arithmetic Statements in the chapter Procedure Division.
  2. VSC2MF The COBOL system ensures enough places are carried so as not to lose significant digits during execution.

General Rules for Format 1

  1. All literals or identifiers preceding the word FROM are added together and this total is subtracted from the current value of identifier-2 storing the result immediately into identifier-2, and repeating this process respectively for each operand following the word FROM.

General Rules for Format 2

  1. 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 each data item referenced by identifier-3.

General Rules for Format 3

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