Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

COMPUTE statement

Function

The COMPUTE statement is used to assign the value of a data item, literal, or arithmetic expression to a data item.

Format


COMPUTE {identifier-1 [ROUNDED]}... = { identifier-2
                                      | literal-1
                                      | arithmetic-expression }

       [ON SIZE ERROR imperative-statement-1]

       [NOT ON SIZE ERROR imperative-statement-2]

       [END-COMPUTE]


Syntax rules

  1. identifier-1... must refer to an elementary numeric item or an elementary numeric-edited data item.

  2. identifier-2 must refer to an elementary numeric item.

  3. The arithmetic-expression specified in the COMPUTE statement permits the use of any meaningful combination of identifiers (which must satisfy the general rules for datanames in simple arithmetic operations), literals, and arithmetic operands; if necessary, they may also be in parentheses (see section "Arithmetic expressions").

  4. If identifier-2 or literal-1 is specified, the value of identifier-1 is set equal to the value of identifier-2 or literal-1.

  5. When an arithmetic-expression is used, the value of that arithmetic-expression is first calculated and then stored as the new value of identifier-1...

  6. The COMPUTE statement allows the user to combine arithmetic operations without the restrictions on the composite of operands and/or receiving data items which are imposed by the ADD and SUBTRACT statements.

  7. Up to 50 data-names may be specified in a COMPUTE statement.

Additional rules are given under "Options in arithmetic statements" ( Phrases in statements et seq.), where the ROUNDED and (NOT) ON SIZE ERROR phrases are described.

Example 8-28

Statement

Calculation

COMPUTE A =
(B + C) / D - E.

The value of the expression (B + C) / D - E is assigned to A. The precedence rules for evaluating expressions apply when calculating values.

COMPUTE A = 2.

The value 2 is assigned to A.