The COMPUTE Statement

General Format for Format 1 (arithmetic compute)


ISO2002MF Format 2 (boolean compute)

COMPUTE {identifier-2} ... = boolean-expression-1 [END-COMPUTE]

Syntax Rules for Format 1

  1. Identifiers that appear only to the left of "=" must refer to either an elementary numeric item or an elementary numeric edited item

    OSVSVSC2MF or a floating-point item.

  2. OSVSVSC2MF "Equal" and "=" are synonymous.

ISO2002MF Syntax Rules for Format 2

  1. Identifier-2 must reference an elementary boolean data item.
  2. Boolean-expression-1 must not consist solely of the figurative constant ALL literal.

General Rules

  1. See the topics Arithmetic Expressions, The ROUNDED Phrase, The ON SIZE ERROR Phrase, Arithmetic Statements, Overlapping Operands and Multiple Results in Arithmetic Statements in the chapter Procedure Division; the section Explicit and Implicit Scope Terminators in the chapter Concepts of the COBOL Language, and the section Delimited Scope Statements in the chapter Language Fundamentals.
  2. An arithmetic expression consisting of a single identifier or literal provides a method of setting the values of identifier-1 equal to the value of the single identifier or literal.
  3. The COMPUTE statement allows you to combine arithmetic operations without the need to explicitly store intermediate results in temporary data items, as would be necessary using the arithmetic statements ADD, SUBTRACT, MULTIPLY and DIVIDE. The expression is evaluated to as many digits as possible, and truncated or rounded to fit into identifier-1.

    OSVSVSC2 The intermediate results obtained during the expression evaluation are truncated as if they were moved to data items whose PICTURE is determined by the COBOL system. This behavior is selected using the ARITHMETIC Compiler directive.

    ISO2002MF The number of boolean positions in the value resulting from the evaluation of boolean-expression-1 is the number of boolean positions in the largest boolean item referenced in the expression. The resulting value is moved to the data item referenced by identifier-2 according to the rules of the MOVE statement.

  4. If more than one identifier is specified for the result of the operation, that is preceding "=", the value of the arithmetic expression is computed, and then this value is stored as the new value of each occurrence of identifier-1 in turn.