skip to main content

Procedure Division Statements : SUBTRACT

SUBTRACT
General Format
Format 1
SUBTRACT { Indentifier-1 } ... FROM { Identifier-2 [ROUNDED] } ... 
  [ ON SIZE ERROR Imperative-Statement-1 ] 
  [ NOT ON SIZE ERROR Imperative-Statement-2 ] 
  [END-SUBTRACT]
Format 2
SUBTRACT { Indentifier-1 } ... FROM { Identifier-2 } ...
  GIVING { Identifier-3 [ROUNDED] } ... 
  [ ON SIZE ERROR Imperative-Statement-1 ] 
  [ NOT ON SIZE ERROR Imperative-Statement-2 ] 
  [END-SUBTRACT]
Format 3
SUBTRACT { CORRESPONDING }{ {Identifier-4} } ... FROM { {Identifier-5} } ...
         { CORR          }
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-ADD]
Syntax rules
Formats 1 and 2
1.
2.
Format 2
3.
Format 3
4.
5.
General rules
1.
 
When standard arithmetic is in effect, the result of the initial evaluation is equivalent to the result of the arithmetic expression
 
(operand-11 + operand-12 + ... + operand-1n)
 
where the values of operand-1 are the values of literal-1 and the data items referenced by identifier-1 in the order in which they are specified in the SUBTRACT statement. The result of the subtraction from the value of each data item referenced by identifier-2 is equivalent to the result of the arithmetic expression
 
(identifier-2 – initial-evaluation)
 
where initial-evaluation represents the result of the initial evaluation.
2.
 
When standard arithmetic is in effect, the result of the initial evaluation is equivalent to the result of the arithmetic expression
 
(operand-2 – (operand-11 + operand-12 + ... + operand-1n))
 
where the values of operand-1 are the values of literal-1 and the data items referenced by identifier-1 in the order in which they are specified in the SUBTRACT statement and the value of operand-2 is the value of either literal-2 or the data item referenced by identifier-2 in the SUBTRACT statement.
3.
Examples
Format 1 - Subtract several variables and literals from variable
move 100 to num-result
move 10 to num-1
move 5 to num-2
subtract num-1 num-2 10 from num-result
Format 2 - Subtract several numbers from number and leave result on another variable validating size error
subtract 10 20 30 from 100 
  giving num-result
  on size error display message "Size error on num-result!"
Format 3 - Subtract values of one group data item from another group with corresponding sub-items
working-storage section.
01 work-hours.
   05 test-hours    pic 9(3value 10.
   05 doc-hours     pic 9(3value 11.
   05 support-hours pic 9(3value 12.
01 notconfirmed-work-hours.
   05 test-hours    pic 9(3value 2.
   05 doc-hours     pic 9(3value 4.
   05 support-hours pic 9(3value 2.
procedure division.
   subtract corresponding notconfirmed-work-hours from work-hours
       on size error display message "Error subtracting from work-hours"
       not on size error
           display message 
   end-subtract

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left