SUBTRACT statement
The SUBTRACT statement subtracts one numeric item, or the sum of two or more
numeric items, from one or more numeric items, and stores the result.
| Format 1 |
 .------------------.
V |
>>-SUBTRACT----+-identifier-1-+-+--FROM------------------------->
'-literal-1----'
.---------------------------.
V |
>----identifier-2--+---------+-+-------------------------------->
'-ROUNDED-'
>--+--------------------------------------------+--------------->
'-+----+--SIZE ERROR--imperative-statement-1-'
'-ON-'
>--+-------------------------------------------------+---------->
'-NOT--+----+--SIZE ERROR--imperative-statement-2-'
'-ON-'
>--+--------------+--------------------------------------------><
'-END-SUBTRACT-'
|
All identifiers or literals preceding the keyword FROM are added together and
their sum is subtracted from and stored immediately in identifier-2.
This process is repeated for each successive occurrence of identifier-2,
in the left-to-right order in which identifier-2 is specified.
| Format 2 |
 .------------------.
V |
>>-SUBTRACT----+-identifier-1-+-+--FROM--+-identifier-2-+------->
'-literal-1----' '-literal-2----'
.---------------------------.
V |
>--GIVING----identifier-3--+---------+-+------------------------>
'-ROUNDED-'
>--+--------------------------------------------+--------------->
'-+----+--SIZE ERROR--imperative-statement-1-'
'-ON-'
>--+-------------------------------------------------+---------->
'-NOT--+----+--SIZE ERROR--imperative-statement-2-'
'-ON-'
>--+--------------+--------------------------------------------><
'-END-SUBTRACT-'
|
All identifiers or literals preceding the keyword FROM are added together and
their sum is subtracted from identifier-2 or literal-2.
The result of the subtraction is stored as the new value of each data item
referenced by identifier-3.
| Format 3 |
 >>-SUBTRACT--+-CORRESPONDING-+--identifier-1--FROM-------------->
'-CORR----------'
>--identifier-2--+---------+------------------------------------>
'-ROUNDED-'
>--+--------------------------------------------+--------------->
'-+----+--SIZE ERROR--imperative-statement-1-'
'-ON-'
>--+-------------------------------------------------+---------->
'-NOT--+----+--SIZE ERROR--imperative-statement-2-'
'-ON-'
>--+--------------+--------------------------------------------><
'-END-SUBTRACT-'
|
Elementary data items within identifier-1 are subtracted from, and
the results are stored in, the corresponding elementary data items within identifier-2.
When the ARITH(COMPAT) compiler option is in effect, the composite of
operands can contain a maximum of 30 digits. When the ARITH(EXTEND) compiler
option is in effect, the composite of operands can contain a maximum of 31
digits. For more information about arithmetic intermediate results, see the
COBOL for Windows Programming Guide.
For all formats:
- identifier
- In format 1, must name an elementary numeric data item.
In format 2, must name an elementary numeric data item, unless the
identifier follows the word GIVING. Each identifier following the word
GIVING must name a numeric or numeric-edited elementary data item.
In format 3, must name an alphanumeric group item or a national
group item.
The following restrictions apply to date fields:
- In format 1, identifier-1 can specify at most one date
field. If identifier-1 specifies a date field, then every
instance of identifier-2 must specify a date field that is
compatible with the date field specified by identifier-1. If identifier-1
does not specify a date field, then identifier-2 can specify
one or more date fields, with no restriction on their DATE FORMAT
clauses.
- In format 2, identifier-1 and identifier-2 can
each specify at most one date field. If identifier-1
specifies a date field, then the FROM identifier-2 must be a
date field that is compatible with the date field specified by identifier-1.
identifier-3 can specify one or more date fields. If identifier-2
specifies a date field and identifier-1 does not, then every
instance of identifier-3 must specify a date field that is
compatible with the date field specified by identifier-2.
- In format 3, if an item within identifier-1 is a date
field, then the corresponding item within identifier-2 must
be a compatible date field.
- A year-last date field is allowed in a SUBTRACT statement only as identifier-1
and when the result of the subtraction is a nondate.
There are two steps to determining the result of a SUBTRACT statement
that involves one or more date fields:
- Subtraction: determine the result of the subtraction operation, as
described under Subtraction that involves date fields.
- Storage: determine how the result is stored in the receiving field.
(In formats 1 and 3, the receiving field is identifier-2; in
format 3, the receiving field is the GIVING identifier-3.)
For details, see Storing arithmetic results that involve date fields.
- literal
- Must be a numeric literal.
Floating-point data items and literals can be used anywhere numeric data items
and literals can be specified.
For information about the ROUNDED phrase, and for operand considerations, see ROUNDED phrase.
For information about the SIZE ERROR phrases, and for operand considerations,
see SIZE ERROR phrases.
See CORRESPONDING phrase.
END-SUBTRACT phrase
This explicit
scope terminator serves to delimit the scope of the SUBTRACT statement.
END-SUBTRACT permits a conditional SUBTRACT statement to be nested in another
conditional statement. END-SUBTRACT can also be used with an imperative SUBTRACT
statement.
For more information, see Delimited scope statements.
|