ARTICLE
string_exp - String Templates
Syntax
|[ literal_text ][
embedded_expressions ][
control_characters ]|
Effect
A string template is enclosed between 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 templates. The characters of
this character string consist of any sequence of the following syntax
elements of the string template:
Literal text literal_text
Embedded expressions
embedded_expressions
Bedingungen conditions
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 . 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
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 \ .
Die Verkn�pfung mehrerer Teile eines Zeichenketten-Templates zu einem
Zeichenketten-Template mit dem
Literaloperator ist nicht
gleichbedeutend zu deren Verkettung mit dem Verkettungsoperator
, da nur vollst�ndige Zeichenketten-Templates verkettet werden
k�nnen. (nur wenn die IF-ELSE-ENDIF gekommen w�ren!)
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.
String templates can be specified in all programs where
Unicode checks are activated. In
non-Unicode programs , character
string programs are not possible because they cannot be distinguished
from possible 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. The option of deactivating
Unicode checks is obsolete anyway.
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.
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:
|!|.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved