sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
     
  ARITHMETIC VERBS  
 

Most of the problems require some computations to be performed on the input or intermediate data which are numeric in nature. Arithmetic verbs are used to perform these computations. All these verbs can contain either identifiers or numeric literals or both. In the case of identifiers, they must be elementary numeric fields, and identifiers used after GIVING option must be edited or unedited numeric fields.

 
  ADD VERB  
 

This verb can be used to find the sum of two or more numbers and to store the sum.

The ADD verb takes any one of the following two forms:
 
 


 
 

Examples:

 
 

ADD A TO B.

 
 

This example shows that the value of A will be added to the value of B and the result will be stored in B. The alignment of the decimal point is done automatically.

 
 

ADD A B C TO D.

 
 

In this case the values of A, B and C will be added to the old value of D and the resultant sum will be the new value of D.

 
 

ADD 30 A TO B.

 
 

This example shows that the number 30, the value of A and the value of B will be added and the resultant sum will be stored in B.

 
  ADD A, B GIVING C.  
 
Here only the values of A and B will be added and the sum will be stored in C. The old value of C will be lost and that value will not take part in the summation.

 
  ADD A, B GIVING C, D, E.  
 

In this case the value of A, B will be added and the sum will be stored in C, D and E. Hence after the execution of this statement, C, D and E will have the same value.

 
 
The above examples indicate that in the case of the TO option the previous value of the last named operand takes part in the summation and then this value is replaced by the result. However, this is not the case when the GIVING option is used. It should be mentioned here that the last named operand in both the cases can never be a literal as the resultant sum is always stored there.
 
 

It is important to note that TO and GIVING cannot be used simultaneously. Thus ADD A TO B GIVING C would be wrong. The purpose is served by specifying as ADD A B GIVING C. With GIVING option identifier-2/numeric-literal-2 is a must.