ABAP

Strings

Literals

ABAP offers three different operators for declaring string- or char-like-variables

Symbols Internal Type Length Name
’…’ C 1-255 Chars text field literals
`…` CString 0-255 Chars text string literals
|…| CString 0-255 Chars template literals

Note that the length-range only applies to hard coded values. Internally CString-variables have arbitrary length while variables of type C always have a fixed length.

String templates

String templates are a convenient way of mixing literal strings with values from variables:

WRITE |Hello, { lv_name }, nice to meet you!|.

It can also format things like dates. To use the logged on user’s date format:

WRITE |The order was completed on { lv_date DATE = USER } and can not be changed|.

Functional method calls and expressions are supported:

WRITE |Your token is { to_upper( lv_token ) }|.
WRITE |Version is: { cond #( when lv_date < sy-datum then 'out of date' else 'up to date' ) }|.

Attention! Directly implementing temporary results (like method-calls) inside of string templates can lead to massive performance problems (read more about it here). While using it inside of rarely executed statements is okay, it causes your program to rapidly slow down in loops.

Concatenating strings

String and char-like variables can be concatenated using ABAP CONCATENATE command. An extra variable for storing the results is required.

Example:

CONCATENATE var1 var2 var3 INTO result.
"result now contains the values of var1, var2 & var3 stringed together without spaces

Shorthand

Newer versions of ABAP offer a very short variant of concatenation using && (Chaining operator).

DATA(lw_result) = `Sum: ` && lw_sum.

Attention! It’s worth noticing, that using temporary results in combination with the Chaining operator inside of loops can lead to massive performance problems due to growing copy instructions (read more about it here).


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow