| |
 |
|
| |
COBOL TUTORIAL
FOR BCA STUDENTS OF M G UNIVERSITY |
|
| |
|
|
| |
 |
|
| |
|
| |
|
| |
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.
|
|
| |
|
| |
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:
|
|
| |
|
|
| |
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.
|
|
| |
|
|
| |
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.
|
|
| |
|
|
| |
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.
|
|
| |
|
| |
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.
|
|
| |
|
| |
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.
|
|
| |
|
| |
|
|
| |
 |
|
| |
|
|
| |
 |
|
| |
|
|