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: SUBTRACT statement

Read syntax diagramSkip visual syntax diagramSUBTRACTidentifier-1literal-1FROMidentifier-2ROUNDEDONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-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: SUBTRACT statement with GIVING phrase

Read syntax diagramSkip visual syntax diagramSUBTRACTidentifier-1literal-1FROMidentifier-2literal-2GIVING identifier-3ROUNDED ONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-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 statement with CORRESPONDING phrase

Read syntax diagramSkip visual syntax diagramSUBTRACTCORRESPONDINGCORRidentifier-1FROMidentifier-2ROUNDEDONSIZE ERRORimperative-statement-1NOTONSIZE ERRORimperative-statement-2END-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 Appendix A. Intermediate results and arithmetic precision in the Enterprise COBOL 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.

literal
Must be a numeric literal.

Floating-point data items and literals can be used anywhere numeric data items and literals can be specified.

ROUNDED phrase

For information about the ROUNDED phrase, and for operand considerations, see ROUNDED phrase.

SIZE ERROR phrases

For information about the SIZE ERROR phrases, and for operand considerations, see SIZE ERROR phrases.

CORRESPONDING phrase (format 3)

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.