What does it do? A string template is enclosed by two characters |> and creates a character string that is used by the string expression at the operand position of the string template. The characters in this character string are determined by any sequence of the following syntax elements of the string template:
Literal text literal_text>>
Embedded expressions embedded_expressions>>
Control characters 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>. However, a string template is not subject to any length restrictions. The literal operator> > or the concatenation operator> > can be used to combine multiple string templates into a single string template. A string template can be defined across multiple lines of source code and be given comments>.
Latest notes:
To display the delimiters |> within literal text> of a string template, it must be prefixed with the escape symbol >.
Using the string function escape>>, all special characters for string templates can be put in front of their escape character.
When string templates are combined, the literal operator >> behaves differently than with literals. This operator is executed at runtime in the same way as the concatenation operator >> and not just once during compilation. This means, however, that the restriction of 255 characters for literals no longer applies. The two combinations |...| |...|> |...| |...|> are identical for string templates. For purely literal 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.
If on the right side of an assignment>, strings are appended to a variable specified with the type string> on the left side of the assignment, the variable is used directly in specific cases> without producing an interim result. It should be ensured that this optimization is not undone, especially in loops. NON_V5_HINTS
The delimiter characters |> can be formatted in the ABAP Editor by choosing Fonts and Colors -> Token operator> to highlight them in the source code. ABAP_HINT_END
ABAP_EXAMPLE_VX5 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. ABEXA 01308 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 The following section of source code shows three identical string templates, all of which represent 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 and these are combined into the same character string using the literal operator > as in the first string template. ABEXA 01309 ABAP_EXAMPLE_END