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
A string template is enclosed in two "
|" characters and can only be specified in a
string expression of a
Unicode program. A
string template creates a character string that is used by the string expression instead of the string
template. The characters of this character string are determined by any sequence of the following syntax elements of the string template:
- Literal text
- Embedded expressions
- Control characters
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. You can use the
&& to link multiple string templates in a single string template. A string template can be defined across multiple lines of source code and be given
- Unlike with other syntax representations in the ABAP keyword documentation, the "
|" characters are part of the syntax.
- To display the "
|" character in literal text in a string template, you must prefix it with the escape symbol
- 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.
- Using the string function
escape, all special characters for string templates can be put in front of their escape character.
- In non-Unicode
programs, string templates cannot be used, since they cannot be distinguished from potential identifiers that begin and end with the delimiters
|". In non-Unicode programs, a statement section that begins or ends with "
|" is interpreted as an identifier and creates a syntax error if the identifier does not exist.
- When string templates are linked, the literal operator
& behaves differently than for literals. Similar to the chaining operator
&&, it is executed at runtime and not once upon compilation. However, the 255-character restriction that applies to literals does not apply. The following two link operations are identical for string templates:
|...| & |...|
|...| && |...|
'...' & '...'
'...' && '...'
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.
In the next two string expressions, the literal text is distributed across multiple parts of the string template. The literal operator
& is used to join them as the first string template.
DATA result TYPE string. result = |Hello World!|. result = |Hello| & | | & |World| & |!|. result = |Hello| & "sub template 1 | | & |World| & "sub template 3 * sub template 4: |!|.