The COMPUTE statement assigns the value of an arithmetic expression to one or more data items.
With the COMPUTE statement, arithmetic operations can be combined without the restrictions on receiving data items imposed by the rules for the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements.
When arithmetic operations are combined, the COMPUTE statement can be more efficient than the separate arithmetic statements written in a series.
- Must name an elementary numeric item or an elementary numeric-edited
Can name an elementary floating-point data item.
- Can be any arithmetic expression, as defined in Arithmetic expressions.
When the COMPUTE statement is executed, the value of arithmetic expression is calculated and stored as the new value of each data item referenced by identifier-1.
An arithmetic expression consisting of a single identifier, numeric function, or literal allows the user to set the value of the data items that are referenced by identifier-1 equal to the value of that identifier, function, or literal.
For a discussion of the ROUNDED phrase, see ROUNDED phrase.
SIZE ERROR phrases
For a discussion of the SIZE ERROR phrases, see SIZE ERROR phrases.
This explicit scope terminator serves to delimit the scope of the COMPUTE statement. END-COMPUTE permits a conditional COMPUTE statement to be nested in another conditional statement. END-COMPUTE can also be used with an imperative COMPUTE statement.
For more information, see Delimited scope statements.