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. |
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
Each identifier must refer to an elementary numeric data item.
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").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 |
SUBTRACT A FROM B,C | 9(3) for B 9(5) for C | B C |
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
Each identifier preceding the word GIVING must refer to an elementary numeric item.
identifier-n may refer either to an elementary numeric item or to an elementary numeric edited item.
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").
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 | 9(5) | 100 |
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
Each identifier must refer to a group item.
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").
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).