Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Structure and Style →  Alternative Spellings 

Calculation Expressions

Other versions: 7.31 | 7.40 | 7.54

Background

Calculation expressions are:

  • Arithmetic expressions
  • Bit expressions
  • String Expressions

You can execute calculation expressions at suitable operand positions or on the right side of the equals sign in the COMPUTE statement. The COMPUTE keyword is optional.

Rule

Omit the COMPUTE keyword

Omit the COMPUTE keyword whenever a calculation expression is used on the right side of the equals sign (=).

Details

To make the program easier to read, you should use the notation of the COMPUTE statement without the COMPUTE keyword. In this notation, specifying a calculation expression on the right side of the equals sign is not any different to specifying an expression at any other operand position. In addition, the literal meaning of the COMPUTE keyword, which originates from a time when there were only arithmetic expressions, is not particularly relevant for character string expressions.

If only a single data object (but no calculation expression) is specified on the right side of the equals sign (=) in the COMPUTE statement, then this is not a complete calculation expression. In this case, only a simple assignment is performed. A calculation with a calculation type is not carried out. In this scenario, you should never use the COMPUTE keyword, because otherwise the reader will expect a conversion to a calculation type to be performed.

Exception

The COMPUTE keyword must be specified if the EXACT addition needs to be specified. This addition results in an exception if rounding is carried out in a calculation with decimal floating point numbers. This is not a disadvantage because the COMPUTE EXACT expression can be regarded as a special statement that should stand out in the source code. The same applies to the MOVE EXACT statement, which is also new.

Bad Example

The following source code shows a simple assignment and a character string expression on the right side of COMPUTE. The COMPUTE keyword is also specified, although the literal meaning is not relevant here.

COMPUTE result = dobj.
COMPUTE result = text1 && condense( text2 ).

Good Example

The following source code shows the same example as above, but without the superfluous COMPUTE keyword.

result = dobj.
result = text1 && condense( text2 ).