ILE COBOL 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.

COMPUTE Statement - Format
 
            .---------------------------.
            V                           |
>>-COMPUTE----identifier-1--+---------+-+--+-=-----+------------>
                            '-ROUNDED-'    '-EQUAL-'
 
>--arithmetic-expression---------------------------------------->
 
>--+--------------------------------------------+--------------->
   '-+----+--SIZE ERROR--imperative-statement-1-'
     '-ON-'
 
>--+-------------------------------------------------+---------->
   '-NOT--+----+--SIZE ERROR--imperative-statement-2-'
          '-ON-'
 
>--+-------------+---------------------------------------------><
   '-END-COMPUTE-'
 
 

If portability is desired, however, you should use ADD, SUBTRACT, MULTIPLY, and DIVIDE rather than COMPUTE. This is because of potentially different system-specific intermediate results.

When arithmetic operations are combined, the COMPUTE statement may be more efficient than the separate arithmetic statements written in series.

identifier-1

Must be either elementary numeric item(s) or elementary numeric-edited item(s).

+-------------------------------IBM Extension--------------------------------+

Can be an elementary floating-point data item.

+----------------------------End of IBM Extension----------------------------+

arithmetic-expression
Can be any arithmetic expression, as defined in Arithmetic Expressions.

When the COMPUTE statement is executed, the value of the arithmetic expression is calculated, and this value is stored as the new value of each data item referenced by identifier-1.

An arithmetic expression consisting of a single identifier, numeric function, or numeric literal allows the user to set the value of the data item(s) referenced by identifier-1 equal to the value of that identifier or literal.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]