SAP STRING EXPR PERFO



Get Example source ABAP code based on a different SAP table
  



ABAP_STRINGEXP - Performance Note
If on the right side of an assignment strings in a string expression are appended to a variable str with the type string specified on the left side of the assignment, the variable is used directly in the following cases without producing an interim result.
str = dobj1 dobj2 ... .
str = |{ str }...{ dobj1 [format_options] }...{ dobj2 [format_options] }...|.
The appended strings cannot be dependent on str for the compiler:
The target field str can occur only once in the string expression, and only at the very beginning.
No formatting options can be used on str in a string template.
Only directly specified data objects dobj1, dobj2, ... and no other expressions or functions can be listed, even if they are not dependent on str.
Optimization is therefore deactivated in the following cases:
str = ... meth( ... ) ... .
str = ... str ... .
str = |{ str }...{ expr( ... ) }...|.
str = |{ str format_options }...|.
str = |{ str }...{ str }...|.
Deactivating optimization for assignments that are not used very often is usually uncritical, it is strongly recommend to only use optimizable forms within loops, because otherwise the runtime would increase quadratically with the number of iterations. Within loops, the results of expressions and functions that can only be determined there should be assigned to helper variables dobj1, dobj2, and so on, and these should be used.



Latest notes:

If optimization is deactivated, the runtime is quadratically dependent on the number of iterations, since the length of the string in the interim result increases in proportion with the number of iterations and has to be copied to the result in every loop pass.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
In the following example for generating an HTML file, there is no optimization. The runtime depends quadratically on the number of iterations n.
ABEXA 01295
The following example shows how the runtime can be optimized by using a helper variable. The bigger n is, the greater the runtime difference to the previous example.
ABEXA 01296
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Concatenating Strings
ABAP_EXAMPLE_END