skip to main content

Procedure Division Statements : ADD

ADD
General Format
Format 1
ADD { {Identifier-1} } ... TO { Identifier-2 [ROUNDED] } ...
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-ADD]
Format 2
ADD { {Identifier-1} } ... TO { {Identifier-2} } ...
  GIVING { Identifier-3 [ROUNDED] } ... 
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-ADD]
Format 3
ADD { CORRESPONDING }{ {Identifier-4} } ... TO { {Identifier-5} } ...
    { CORR          }
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-ADD]
Syntax rules
1.
2.
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 ADD statement. The result of the sum of the initial evaluation and the value of the data item referenced by identifier-2 is equivalent to the result of the arithmetic expression:
 
(initial-evaluation + identifier-2)
 
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-11 + operand-12 + ... + operand-1n + operand-2)
 
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 ADD statement and the value of operand-2 is the value of either literal-2 or the data item referenced by identifier-2 in the ADD statement.
3.
4.
Examples
Format 1- Increment the numeric data item num-var by 1
add 1 to num-var
Format 1 - Add 1.253 to num-var, producing a rounded result and check if the resulting value does not exceed the defined size of num-var.
add 1.253 to num-var rounded
 on size error 
    display message "Value to long for num-var"
 not on size error
    display message "New value for num-var : " num-var
Format 2 - Assign to num-3 the result of adding num-1 and num-2.
add num-1 to num-2 giving num-3
Format 2 - Assign to num-3 the result of adding num-1 and num-2, checking if the resulting value does not exceed the defined size of num-3.
add num-1 to num-2 giving num-3
 on size error 
    display message "Value to long for num-3"
 not on size error
    display message "New value for num-3 : " num-3
Format 3 - Add values from one group data item to another one 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 additional-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.
   add corresponding additional-work-hours to work-hours
       on size error display message "Error adding to work-hours"
       not on size error
           display message 
   end-add

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