ABAP Keyword Documentation →  ABAP − Reference →  Obsolete Language Elements →  Obsolete Calculation Statements → 

COMPUTE  Syntax Diagram

Short Reference

Obsolete Syntax

COMPUTE [EXACT] lhs =|?= rhs.

Effect

The keyword COMPUTE can be written before every assignment with an assignment operator = or ?=, except when an inline declaration or a writable expression is made on the left side. The keyword COMPUTE is ignored by the assignment unless the addition EXACT is specified.

If the addition EXACT is specified, the statement works as follows:

lhs = EXACT #( rhs ).

In this case, COMPUTE performs a lossless calculation in accordance with the same rules as apply when using the lossless operator EXACT for arithmetic expression. Only the simplified arithmetic expressions described here can be specified for rhs and lhs cannot have the type f. If a rounding raises an exception, the target variable is not modified.

Note

The keyword COMPUTE is a relic and was originally designed for arithmetic calculations where the right side is an arithmetic expression:

COMPUTE [EXACT] result = arith_exp.

Strictly speaking, the statement applies only in this case; more loosely, it applies even if a string expression or bit expression is specified as a different form of calculation expression on the right side.

Alongside the introduction using a calculation expression on the right side, the following variants also exist:

If a data object dobj is specified on the right side, COMPUTE functions like an assignment of data objects.
If the source objects and target objects have reference types, COMPUTE functions like an up cast or down cast.
If functional method calls, predefined functions, constructor expressions, or table expressions are specified on the right side, COMPUTE works like an assignment of return values.
If a multiple assignment is specified on the right side, COMPUTE works like a multiple assignment.

This means that the keyword COMPUTE does not produce a calculation. More specifically, COMPUTE does not modify the way a calculation type is chosen:

For this reason, it is not advisable to specify the keyword COMPUTE before assignments. If the right side is not a calculation expression, the keyword produces false information. If the right side is a calculation expression, the keyword is ignored if specified.

Programming Guideline

Assignments with the assignment operators = and ?= only