## 6.2.7 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.

___ **Format** _____________________________________________________________
| |
| <___________________________ |
| >>__`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 elementary numeric item(s) or elementary numeric-edited
item(s).

X Can name an elementary floating-point data item.

X The word EQUAL can be used in place of =.

X If identifier-1 or the result of the arithmetic expression (or both)

X are date fields, see "Storing Arithmetic Results That Involve Date

X Fields" in topic 6.1.5.2.3 for details on how the result is stored in

| identifier-1. If a year-last date field is specified as identifier-1,

| then the result of the arithmetic expression must be a non-date.

**arithmetic-expression**
Can be any arithmetic expression, as defined in "Arithmetic
Expressions" in topic 6.1.5.

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

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

X expression.

Subtopics:

© Copyright IBM Corp. 1991, 1998

###### IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.

**Return to library:**
z/OS |
z/OS.e |
TPF |
z/VSE |
z/VM |
IBM Hardware |
IBM System z Redbooks

**Glossary:**
IBM terminology

**Publications:**
How to order publications

**Readers:**
Download IBM Library Reader |
Download IBM Softcopy Reader |
Download Adobe® Acrobat® Reader®

**Library management:**
Download IBM Softcopy Librarian

**Contacts:**
Contact z/OS

Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks
of Adobe Systems incorporated.