The COMPUTE Statement
Syntax
Format
COMPUTE {identifier-2 [ROUNDED]} ... { =
EQUAL } arithmetic-expression
[ON SIZE ERROR imperative-statement-1]
[NOT ON SIZE ERROR imperative-statement-2]
[END-COMPUTE]
Description
The COMPUTE statement is used to evaluate arithmetic formulas. The formula isevaluated and the result is stored in the identifier(s) between COMPUTE and =.
The format for the formula is a standard algebraic expression with addition, subtraction, multiplication, and division represented as +, -, *, and /. The exponentiation operator is **.
When evaluating the formula, standard rules of mathematical precedence apply, i.e. exponetiation first, then multiplication and division at equal precedence, then addition and subtraction at equal precedence. If some other order is preferred, operations may be enclosed in parentheses to give them precedence.
Tips
1. If only one mathematical operation is to be performed, use the statement that performs that operation ( ADD, SUBTRACT, MULTIPLY, or DIVIDE). Reserve the COMPUTE statement for formulas or exponentiation, since it has no seoarate statement associated with it.
2. Receiving fields may be either numeric or numeric edited fields.
3. Use the SIZE ERROR clause to detect field overflow on the receiving field.
4. In all formats, the mathematically correct results are computed, but if the receiving field is too short in either the integer or decimal portion,the result will be truncated, the integer on the left and the decimal on the right. Including the ROUNDED phrase will result the answer field being rounded instead of truncating. Rounding is always done in the least significant portion of the answer.
Posted by
KK
at
5:22 AM