Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

SUBTRACT statement

Function

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

Format 1

of the SUBTRACT statement stores the difference in one of the operands.
In a SUBTRACT statement, more than one subtraction may be specified by supplying more than one result item.

Format 2

of the SUBTRACT statement uses the GIVING phrase.

Format 3

of the SUBTRACT statement subtracts the items in one group item from the corresponding items in another group item.

Format 1


SUBSTRACT {identifier-1 | literal-1}...

FROM {identifier-n [ROUNDED]}...

[ON SIZE ERROR imperative-statement-1]

[NOT ON SIZE ERROR imperative-statement-2]

[END-SUBTRACT]


Syntax rules

  1. Each identifier must refer to an elementary numeric data item.

  2. The composite of operands determined by using all of the operands in a given statement, with the exception of the data item following the word GIVING, must not contain more than 31 digits
    (see "Arithmetic statements").

  3. All literals and identifiers preceding the word FROM are added together, and the sum is subtracted from the current value of identifier-n... . The results of the subtraction are stored as the new value of identifier-n.

Additional rules are given under "Phrases in statements", where the ROUNDED and (NOT) ON SIZE ERROR phrases are described.

Example 8-78

Statement

PICTURE of result item

Calculation

SUBTRACT A, B FROM D

999

D - (A + B) stored in D as nnn

SUBTRACT A FROM B,C

9(3) for B

9(5) for C

B - A stored in B as nnn

C - A stored in C as nnnnn

 

Format 2


SUBSTRACT {identifier-1 | literal-1}... FROM {identifier-m | literal-m}

 GIVING {identifier-n [ROUNDED]}...

[ON SIZE ERROR imperative-statement-1]

[NOT ON SIZE ERROR imperative-statement-2]

[END-SUBTRACT]


Syntax rules

  1. Each identifier preceding the word GIVING must refer to an elementary numeric item.

  2. identifier-n may refer either to an elementary numeric item or to an elementary numeric edited item.

  3. The composite of operands determined by using all of the operands in a given statement, except for the data items which follow the word GIVING, must not contain more than 31 digits (see "Arithmetic statements").

  4. All literals and identifiers preceding the word FROM are added together, and the sum is subtracted from literal-m or identifier-m. The results of the subtraction are stored as the new value of identifier-n.

Additional rules are given under "Options in arithmetic statements" ( Phrases in statements et seq.), where the GIVING, ROUNDED, and (NOT) ON SIZE ERROR phrases are described.

Example 8-79

Statement

PICTURE of result item (C)

Calculation

SUBTRACT A, B FROM
100 GIVING C.

9(5)

100 - (A + B) stored in C as nnnnn

Format 3


SUBSTRACT { CORR | CORRESPONDING identifier-1

 FROM identifier-2 [ROUNDED]

[ON SIZE ERROR imperative-statement-1]

[NOT ON SIZE ERROR imperative-statement-2]

[END-SUBTRACT]


Syntax rules

  1. Each identifier must refer to a group item.

  2. The composite of operands, which is determined separately for each pair of corresponding data items, must not be greater than 31 digits (see "Arithmetic statements").

  3. The elementary items within the first operand (identifier-1) are subtracted from the corresponding elementary items within the second operand (identifier-2). The results are stored in the items of the second operand.

Additional rules are given under "Options in arithmetic statements" ( Phrases in statements et seq.), where the CORRESPONDING, ROUNDED, and (NOT) ON SIZE ERROR phrases are described.

Example 8-80

Refer to the description of the CORRESPONDING phrase for an example of the use of this phrase ( CORRESPONDING phrase).