Enterprise COBOL for z/OS, V4.2, Language Reference

COMPUTE statement

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.

Read syntax diagramSkip visual syntax diagram
Format

            .---------------------------.              
            V                           |              
>>-COMPUTE----identifier-1--+---------+-+--+- = ---+------------>
                            '-ROUNDED-'    '-EQUAL-'   

>--arithmetic-expression---------------------------------------->

>--+--------------------------------------------+--------------->
   '-+----+--SIZE ERROR--imperative-statement-1-'   
     '-ON-'                                         

>--+-------------------------------------------------+---------->
   '-NOT--+----+--SIZE ERROR--imperative-statement-2-'   
          '-ON-'                                         

>--+-------------+---------------------------------------------><
   '-END-COMPUTE-'   

identifier-1
Must name an elementary numeric item or an elementary numeric-edited item.

Can name an elementary floating-point data item.

If identifier-1 or the result of arithmetic expression (or both) are date fields, see Storing arithmetic results that involve date fields for details on how the result is stored in identifier-1. If a year-last date field is specified as identifier-1, the result of arithmetic expression must be a nondate.

arithmetic-expression
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.

A year-last date field must not be specified in the arithmetic expression.

ROUNDED phrase

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.

END-COMPUTE phrase

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.



Rate this page

[ Index | Table of contents ]