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

Syntax

|[literal_text][ embedded_expressions][ control_characters]|

Effect

A string template is enclosed by two characters "|" and creates a character string that is used by the string expression instead of the string templates. The characters of this character string consist of any sequence of the following syntax elements of the string template:

A string template that starts with "|" must be closed with "|" within the same line of source code. The only exceptions to this rule are line breaks in embedded expressions. There are, however, no length restrictions on a string template. The literal operator & or the chaining operator && can be used to join multiple string templates in a single string template. A string template can be defined across multiple lines of source code and be given comments.

Notes

|...| &  |...|
|...| && |...|
are identical for string templates. For literal-only content, they are the same as
`...` && `...`
However they are different to
`...` &  `...`
'...' &  '...'
'...' && '...'
In the first two cases, a length restriction of 255 characters applies. In the third case, trailing blanks are ignored.

Example

String template with literal text and an embedded expression. The result is made up of the content of the literal text and the result of the embedded expression.

DATA(result) = |Hello { sy-uname }!|.

Example

The following piece of source code shows three similar string templates that all display the character string "Hello World!". The first string template contains the entire character string as literal text. The next two string expressions distribute the literal text across multiple parts of the string template. The literal operator & is used to join them as the first string template.

DATA(result1) = |Hello World!|.

DATA(result2) = |Hello| & | | & |World| & |!|.

DATA(result3) = |Hello| & "sub template 1
                | |     &
                |World| & "sub template 3
* sub template 4:
                |!|.



Continue
String Templates - literal_text
String Templates - embedded_expressions
String Templates - control_characters
Examples of string templates