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

Other versions: 7.31 | 7.40 | 7.54




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.


  • Unlike other syntax representations in the ABAP key word documentation, the "|" characters are part of the syntax.

  • To represent the delimiter "|" as a string template with in literal text, it must be prefixed with the escape character \.

  • 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 character string function escape, all special characters for character string templates can be put in front of their escape character.

  • In obsolete non-Unicode programs, character string programs are not possible because they cannot be distinguished from potential identifiers (which begin and end with the delimiters "|"). In non-Unicode programs, a part of a statement that begins or ends with "|" is interpreted as an identifier and creates a syntax error if the identifier does not exist. The delimiters "{" and "}" for embedded expressions can cause similar problems.

  • When string templates are joined, the literal operator & behaves differently than with literals. This operator is executed at runtime (like the chaining operator &&) and not during compilation as a one-off process. This means the restriction of 255 characters for literals no longer applies. The two joins
|...| &  |...|
|...| && |...|
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.


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: 


String Templates - literal_text

String Templates - embedded_expressions

String Templates - control_characters

Examples of string templates