SAP COMPUTE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID COMPUTE
• COMPUTE ABAP Statement
• EXACT COMPUTE (obsolete)
• = COMPUTE (obsolete)

COMPUTE
Short Reference

ABAP_SYNTAX_OBS
COMPUTE $[EXACT$] lhs =$|?= rhs.

What does it do?
The keyword COMPUTE can be written before every assignment with an assignment operator = or ?=, except when an inline declaration is made on the left side or a writable expression exists. 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.



Latest notes:

The keyword COMPUTE is a historical 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.
In addition to the introduction using a calculation expression on the right side, the following variants also exist:
COMPUTE destination = dobj. If a data object dobj is specified on the right side, COMPUTE works like an assignment of data objects.
COMPUTE destination_ref =$|?= source_ref. If the source objects and target objects have reference types, COMPUTE works like an upcast or downcast.
COMPUTE destination = meth( ) $| func( ) $| constr_expr If functional method calls, built-in functions, constructor expressions, or table expressions are specified on the right side, COMPUTE works like an assignment of return values .
COMPUTE destination1 = destination2 = ... = destination = rhs. 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 determined:
When a data object is assigned to a target object, the type of the source object is always converted to the type of the target object, even if prefixed with COMPUTE.
When an arithmetic expression is assigned, the calculation type is always determined from all operands involved, including the left side, even if not prefixed with COMPUTE .
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.
ABAP_HINT_END



Latest notes:

When COMPUTE is used for assignments to enumerated variables, addition EXACT and the lossless operator EXACT have the special effect that they can enable assignments, which otherwise would not have been possible.
ABAP_HINT_END

ABAP_PGL
Assignments with the assignment operators = and ?= only
ABAP_PGL_END



Example ABAP Coding

It is not possible to make two commented out assignments of a calculation to the enumerated variable num. The assignment is possible using EXACT, because in this case the assignment follows the same rules as the lossless operator shown below.
ABEXA 00117
ABAP_EXAMPLE_END

Return to menu