Friday, 12 December 2008

COMPUTE VERB:

In COBOL there is another arithmetic verb called COMPUTE. This verb is so powerful that all the computations performed by the other four verbs can also be done by using only the COMPUTE verb.

Syntax:

During execution the arithmetic expression on the right of the equal sign is evaluated and the value is then moved to the identifier(s) on the left-hand side.
(i) 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 operators and their meanings.
Operator Meaning
** Exponentiation
/ Division
* Multiplication
- Subtraction
+ Addition
(ii) Parentheses may be used to specify the order of operations in an arithmetic expression. Where parentheses are absent, the order is taken to be left to right as follows:

** Exponentiation
/* Division and Multiplication
-+ Subtraction and addition

(iii) An arithmetic expression may be preceded by a + or – sign. Such operators are called unary + or unary – operators.

Examples of valid arithmetic expressions are
3 * I
RATE * QUANTITY – DISCOUNT
A + ( B - C ) * D **2
- B
Examples of invalid arithmetic expressions
A + - B
4 ( K - 1)
Examples:
COMPUTE A = B + C
COMPUTE F = 1.8 * C + 32

No comments:

Post a Comment