Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  string_exp - String Expressions →  string_exp - String Templates 

String Templates - embedded_expressions

Other versions: 7.31 | 7.40 | 7.54

Syntax


{ expr [format_options] }

Effect

Within a string template, an opening and a closing curly bracket { ... } define a general expression position, expr, at which the following can be specified in ABAP syntax:

At least one blank must be included on the right of the opening bracket and one the left of the closing bracket. An embedded expression must be complete within the current string template. An embedded expression within the curly brackets is handled in accordance with regular ABAP syntax:

  • Tokens must be separated by at least one blank or line break.
  • In other cases, blanks and line breaks between tokens are not significant.
  • No distinction is made between uppercase and lowercase letters.

The data type of the expression must be an elementary data type and the value of the expression must be character-like or be convertible to a string. When a string template is analyzed, the value of each embedded expression is converted to a character string. The string is inserted in the correct location. The string is formatted either using

The embedded expressions in a string template are analyzed from left to right. If function methods are specified, they are executed during the analysis.


Notes

  • To display the curly brackets { and } in literal text in a string template, they must be prefixed with the escape character \.

  • Curly brackets cannot be nested directly. If expr is itself a string expression, or contains a string expression, it can contain embedded expressions.

  • String functions with character-like return values are recommended when embedded functions are specified.

  • Unlike arithmetic expressions and bit expressions, embedded functional methods are not executed before the whole expression is analyzed. If an embedded functional method modifies the value of data objects that are also used as embedded operands, the change only affects data objects on the right of the method.

Example

The string template in the method main uses embedded expressions to display the text "Hello world!". The first embedded expression is the attribute attr of the class. The return code of the method func is used in the second embedded expression. The third embedded expression is again the attribute attr, whose value has been changed in the method func in the meantime. The second embedded expression includes a line break and a comment.

CLASS demo DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS: main, 
                   func RETURNING value(p) TYPE string. 
  PRIVATE SECTION. 
    CLASS-DATA attr TYPE string VALUE `Hello`. 
ENDCLASS. 

CLASS demo IMPLEMENTATION. 
  METHOD main. 
    DATA txt TYPE string. 
    txt = |{ attr }{ func( ) "a function call 
                    WIDTH = 6 ALIGN = RIGHT }{ attr }|. 
    cl_demo_output=>display( txt ). 
  ENDMETHOD. 
  METHOD func. 
    p = `world`. 
    attr = '!'. 
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION. 
  demo=>main( ). 

Continue

Embedded Expressions - Predefined Formats

Embedded Expressions - format_options