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 in which

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

  • Unlike other syntax representations in the ABAP key word documentation, the curly brackets are part of the syntax.

  • 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, then 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.

  • The delimiter characters "|" can be formatted in the new ABAP Editor by choosing Fonts and Colors → Token operator to highlight them in the source code.

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 value 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 
                    WIDTH = 6 ALIGN = RIGHT }{ attr }|. 
    MESSAGE txt TYPE 'I'. 
  ENDMETHOD. 
  METHOD func. 
    p = `world`. 
    attr = '!'. 
  ENDMETHOD. 
ENDCLASS. 

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


This translation does not reflect the current version of the documentation.

Continue

Embedded Expressions - Predefined Formats

Embedded Expressions - format_options