Rational Developer for System z
COBOL for Windows, Version 7.5, Language Reference


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
Read syntax diagramSkip visual syntax diagram             .------------------.        
             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
Read syntax diagramSkip visual syntax diagram             .------------------.                          
             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
Read syntax diagramSkip visual syntax diagram>>-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:

There are two steps to determining the result of a SUBTRACT statement that involves one or more date fields:

  1. Subtraction: determine the result of the subtraction operation, as described under Subtraction that involves date fields.
  2. 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.

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.


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)