Previous Topic: ADDNext Topic: DIVIDE


COMPUTE

Purpose

Evaluates an arithmetic expression. The result of the evaluation is placed in a variable data field.

Syntax

►►─── COMPUTE variable ── options ──┬─ ─ = ─ arithmetic-expression ───┬───►
                                    └─ ALLOWING assignment-condition ─┘

Expansion of options

►───┬─────────────────────────────────┬──────────────────────────────────►◄
    ├─ ROUNDED ───────────────────────┤
    └─ TRUNCATED ─────────────────────┘

Parameters

variable

Specifies the name of a variable data field that contains the result of the COMPUTE operation.

ROUNDED

Rounds the result of the computation to the number of decimal positions found in variable.

TRUNCATED

Truncates the result of the computation to the number of decimal positions found in variable.

The default specification is ROUNDED if COBOL moves are enabled is not selected and TRUNCATED if the option is selected.

ALLOWING

Specifies which error conditions would normally abend and should cause control to be returned to the dialog for error handling. The list of allowable assignment-condition names can be found in the section entitled "Arithmetic and Assignment Command Status Condition."

arithmetic-expression

Specifies the arithmetic expression being evaluated for the value contained in variable.

More information:

For information on arithmetic-expression, see Chapter 6, Arithmetic Expressions.

Example

The following example uses the COMPUTE command to calculate commission as a percentage of sales plus a percentage of sales above quota. The result is truncated.

COMPUTE COMMISSION TRUNCATED =
        0.10 * SALES + 0.03 * (SALES - QUOTA).

More information:

Assignment Command