Library View Topics Framed Contents Revised Topics Previous Topic Next Topic Search Search ResultsPrevious Topic MatchNext Topic Match Notes List Notes Print Download No PDF Handheld DisconnectedHandheld ConnectedHelp

6.2.38 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____ _identifier-1_ _|__FROM_____________________________> |
   |                 |_literal-1____|                                       |
   |                                                                        |
   |    <___________________________                                        |
   | >____identifier-2__ _________ _|_____________________________________> |
   |                    |_ROUNDED_|                                         |
   |                                                                        |
   | >__ ____________________________________________ ____________________> |
   |    |_ ____ __SIZE ERROR__imperative-statement-1_|                      |
   |      |_ON_|                                                            |
   |                                                                        |
   | >__ _________________________________________________ _______________> |
   |    |_NOT__ ____ __SIZE ERROR__imperative-statement-2_|                 |
   |           |_ON_|                                                       |
   |                                                                        |
   | >__ ______________ _________________________________________________>< |
   |    |_END-SUBTRACT_|                                                    |
   |                                                                        |
   |________________________________________________________________________|
All identifiers or literals preceding the key word FROM are added together and this 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____ _identifier-1_ _|__FROM__ _identifier-2_ ___________> |
   |                 |_literal-1____|          |_literal-2____|             |
   |                                                                        |
   |            <___________________________                                |
   | >__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 key word FROM are added together and this 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.

The composite of operands must not contain more than 18 digits. The compiler ensures that enough places are carried so that no significant digits are lost during execution.


X The composite of operands may contain more than 18 digits. For more
X information on arithmetic intermediate results, see the IBM COBOL
X Programming Guide for your platform.

For all Formats:

identifier
In Format 1, must name an elementary numeric item.

In Format 2, must name an elementary numeric item, unless the identifier follows the word GIVING. Each identifier following the word GIVING must name a numeric or numeric-edited elementary item.

In Format 3, must name a group item.


X The following restrictions apply to date fields:

  • X In Format 1, identifier-1 may specify at most one date field. If
    X identifier-1 specifies a date field, then every instance of
    X identifier-2 must specify a date field that is compatible with the
    X date field specified by identifier-1. If identifier-1 does not
    X specify a date field, then identifier-2 may specify one or more
    X date fields, with no restriction on their DATE FORMAT clauses.
    
    
  • X In Format 2, identifier-1 and identifier-2 may each specify at
    X most one date field. If identifier-1 specifies a date field, then
    X the FROM identifier-2 must be a date field that is compatible with
    X the date field specified by identifier-1. Identifier-3 may
    X specify one or more date fields. If identifier-2 specifies a date
    X field and identifier-1 does not, then every instance of
    X identifier-3 must specify a date field that is compatible with the
    X date field specified by identifier-2.
    
    
  • X In Format 3, if an item within identifier-1 is a date field, then
    X the corresponding item within identifier-2 must be a compatible
    X 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 non-date.
    
    


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

  1. X Subtraction: determine the result of the subtraction operation, as
    X described under "Subtraction Involving Date Fields" in
    X topic 6.1.5.2.2.
    
    
  2. X Storage: determine how the result is stored in the receiving
    X field. (In Formats 1 and 3, the receiving field is identifier-2;
    X in Format 3, the receiving field is the GIVING identifier-3.) For
    X details, see "Storing Arithmetic Results That Involve Date Fields"
    X in topic 6.1.5.2.3.
    
    

literal
Must be a numeric literal.


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

Subtopics:



Previous Topic Next Topic © Copyright IBM Corp. 1991, 1998

IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.





Return to library:   z/OS | z/OS.e | TPF | z/VSE | z/VM | IBM Hardware | IBM System z Redbooks
Glossary:   IBM terminology
Publications:   How to order publications
Readers:   Download IBM Library Reader | Download IBM Softcopy Reader | Download Adobe® Acrobat® Reader®
Library management:   Download IBM Softcopy Librarian
Contacts:   Contact z/OS


Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.