SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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
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:
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
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( ).