| |
 |
|
| |
COBOL TUTORIAL
FOR BCA STUDENTS OF M G UNIVERSITY |
|
| |
|
|
| |
 |
|
| |
|
| |
|
| |
COMPUTE verb is very powerful. All the computations
performed by the other four verbs can also be done
easily by using the COMPUTE verb.
Its general format is:
|
|
| |
|
|
| |
The
COMPUTE statement has the following meaning. During
execution the arithmetic expression on the right of
the equal sign is evaluated and the value is then
moved to the identifiers(s) on the left-hand side.
If any identifier on the left of the equal sign is
a numericedited item, editing takes place when the
value of the expression is moved to the said identifier.
The identifiers on the left of the equal sign (=)
must be numeric or numeric-edited elementary items.
The right-hand side must be an arithmetic expression.
An arithmetic expression can be an identifier (numeric
elementary items only), a numeric literal or can specify
a computation involving two or more such identifiers
and/or literals. An arithmetic expression has always
a numeric value.
|
|
| |
When an arithmetic expression specifies a computation,
it may consist of two or more numeric literals and/or
data names joined by arithmetic operators.
The following table lists the operations and their
meaning:
|
|
| |
|
|
| |
There must be at least one space preceding and following
the operator in an arithmetic expression. No two arithmetic
operators can appear together in an expression. In
this respect ** is considered to be a single operator.
|
|
| |
Parentheses may be used to specify the order of operations
in an arithmetic expression. When parentheses are
used, the portion of the expression enclosed within
parentheses is evaluated first.
An arithmetic expression may be proceeded by a + or
– sign. Such operations are called unary + or
unary – operators.
Example:
|
|
| |
|
| |
This has the same effect as that as that of ADD B
C GIVING A.
|
|
| |
|
| |
The value of the expression on the right-hand side
is evaluated and this value is then
moved to F. Suppose C and F are defined with pictures
99 and ZZ9.9 respectively and the current value of
C is 3. Then after the execution of the statement,
F will have the value 37.4.
|
|
| |
 |
|
| |
|
|
| |
 |
|
| |
|
|