Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Structure and Style →  Complexity 


Other versions: 7.31 | 7.40 | 7.54


An expression is part of an ABAP statement that returns a result. An expression consists of one or more operands in combination with operators or special ABAP words. The possible expression types are logical expressions and calculation expressions. The latter type is subdivided into arithmetic expressions, bit expressions, and character string expressions. You can use data objects, other suitable expressions, and calls for built-in functions and functional methods as expression operands. In character string processing, regular expressions for searches and pattern comparisons are also used.

You can nest these expressions and combine them in many different ways. Nested and chained calls are possible for functional methods. The maximum nesting depth of expressions is restricted to 32 by the ABAP Compiler.


Limit the complexity of expressions

Use expressions at operand positions in a way that means the program remains legible and understandable.


The diverse options for expressions mean that the use of helper variables is superfluous in many places. The use of expressions and functional calls at operand positions is useful under the following prerequisites:

  • The result of an expression or a calculation is required only once. If an intermediate result is required multiple times, it should only be calculated once and saved in a helper variable. (The ABAP Compiler does not implicitly handle this task at the moment)
  • The data type of the result matches the operand position, or the conversion rules for an expression/call used at an operand position are suitable for the task to be implemented. If special type conversions must be performed, for example, for date or time fields, helper variables of an appropriate type might be required.

You should always remember to keep your program legible.. Do not be too ambitious and combine everything into one single expression. If an expression becomes too complex, it should be split at suitable points, and the intermediate results should be saved in helper variables. This particularly applies to character string processing with character string templates and to regular expressions. These are very powerful but they can also make programs difficult to read very quickly. Comments can also help to describe the functionality of a complex expression.

Bad Example

The following source code shows an arithmetic expression in a logical expression in a loop. The same total must be recalculated for each loop pass.

  IF oref->meth( <wa> ) < sy-tabix * ( offset + length ).

Good Example

The following source code has the same functionality as the example above. However, the total is only calculated once before the loop.

limit = offset + length.
  IF oref->meth( <wa> ) < sy-tabix * limit.