This is a test message to test the length of the message box.
New ABAP string templates
Created by Software-Heroes

ABAP - String templates (Part 1)

The processing and creation of strings has been adjusted once more by SAP. The new structure of the strings is now easier and offers many advantages.

The topic of string processing has once again changed. The presentation and creation of a concatenated text is now a little more intuitive, as it is known from other programming language. The encoding of the strings looks a bit different, but here you will be able to get used to it quickly.


Current version

At the moment the string is shown with the "Accent grave", this can easily lead to problems with the recognition of the character string, because this can be confused with a simple quote. With the string, closing blanks are considered and not truncated as in the char field.

Here's a little example with an assignment and spaces at the end of the string. This is a simple assignment. The second example shows a combination of multiple strings joined together with a space in the middle.

  ld_value TYPE string.

" Creation of a string
ld_value = `This is a string. The spaces at the end still there ...   `.

" with string connection
ld_value = `Part 1` && ` ` && `Part 2`.


New version

The new path now uses "pipes" that define the beginning and the end. In addition, the contents of variables can still be adopted with curly brackets. It is important to mention that every space between the pipes is a space at the end of the string.

  ld_value TYPE string.

" Creation of a string
ld_value = |This is a string. The spaces at the end still there ...   |.

" with connection
ld_value = |Part 1| && | | && |Part 2|.


When using the curly braces, pay attention to the spaces between parentheses and variables, such as brackets with logical expressions or arithmetic operations. Any number of variables can be used in the string.

  ld_text TYPE char25 VALUE ''.

" Text and variable
DATA(ld_string) = |Here goes the variable: { ld_text }|.



In the examples shown so far only the leading signs have been changed and it is still no great advantage to recognize the conventional strings. The advantage of the new variant is the possibility of formatting the variable when inserting it into the string.

There are various options available for preparing the variable contents for the output, which previously might have been implemented with additional intermediate variables or for which further function modules had to be used.

In order to format the content, there must be an addition after the variable, which determines the action to be performed.



For easy output of the date in various formats the DATE function is available. The simplest form for this is the output in USER format, in most cases already the correct format for your needs.

" Date conversion
DATA(ld_date_out) = |{ sy-datum DATE = USER }|.



The alpha conversion is the standard input and output form, which you need for all sorts of things to output and processing of numbers or document numbers needed. This allows leading zeros to be added or removed.

  ld_char TYPE CHAR10 VALUE '123'.

" Output
DATA(ld_belnr) = |{ ld_char ALPHA = IN }|.


Width & Align

Defines the length of a field for the output or for the length of the string that is generated. The string only can be extended, not shortened. With the formatting option Align, the text within the enlarged area can still be indented. In the following example, the text is positioned at the end of the string and padded with spaces in front of it.

" Output conversion
DATA(ld_width) = |{ 'Four' WIDTH = 10 ALIGN = RIGHT }|.



There are many more ways to convert output, you can find them under the link at the bottom of this article (sources).



The new string templates offer many new possibilities in the processing of messages, texts and outputs. The integrated formatting saves intermediate variables and makes the coding a lot clearer. In the next part we will deal with the new inline functions on string processing


SAP Documentation string templates
SAP Documentation string formatting

Included topics:
New ABAPString Template|{ }|
Comments (0)

ABAP - Text, String, Template

Category - ABAP

How do I use character strings in modern ABAP development and how do they behave together with inline declarations. We also look at errors that can happen with it.


ABAP - Predicative Method Call

Category - ABAP

Due to the OO concept, own methods are usually used for complex queries. This article is about comparing the result from such methods.


ABAP - Performance for the SELECT

Category - ABAP

In this article we will look at a few special cases with the SELECT and examine the performance of these constructs. We'll show you the current alternatives and give you little tips while reading.


ABAP - Check objects (Instances)

Category - ABAP

In this article we will show you how you can analyze instances and react to them correctly, for example if you hand them over during processing and want to react individually.


ABAP - Loops

Category - ABAP

With New ABAP, new loops and possibilities for restricting table contents were created. We'll take a closer look at these new commands in this article.