What’s New In ABAP – Series 01, Episode 06 – Strings on Me!

Strings on Me!

Hello everyone, with the release of ABAP 7.30 +(before 7.40)  there are some new features added to deal with strings in ABAP. The new operators, chaining operator(&&), literal operator(&). These two operators can replace with the old CONCATENATE and we discuss about them at the end of this episode. Before that we are going to see about string templates & more in this episode strings on me!.

1. String Template:

String template is defined using the pipe symbol ‘|’. Whenever we want to concatenate the character strings we can keep the between the pipe symbols as below.

Prior to ABAP 7.30 +

WRITE: 'inkyourcode.com'.

Output: inkyourcode.com

with ABAP 7.30 +

WRITE: |inkyourcode.com|.

Output: inkyourcode.com.

You might ask whats so big deal about it? I am coming there. The advantage of using string template is that it can have expressions, character strings and control characters between the pipe symbol with slight change.

2. String Templates with Expressions:

Here expression can be a arithmetic expression should be placed between the string template. In order to make a difference between expression and the text we need to keep the expression in the curly braces {…}. The expression you kept within the curly braces would be evaluated first and then converted to character string.

Let me explain you with an example below.

Prior to ABAP 7.30 +:

1.DATA: lv_days_in_year TYPE i VALUE 365,
2.lv_age TYPE i VALUE 26,
3.lv_string TYPE string.

4.lv_days_lived = lv_days_in_year * lv_age.
5.CONCATENATE 'Number of days lived: ' lv_days_lived ' roughly' INTO lv_string RESPECTING BLANKS.
6.WRITE: lv_string.

Output: Number of days lived: 9, 490 roughly

With ABAP 7.30:

1.DATA: lv_days_in_year TYPE i VALUE 365,
2.lv_age TYPE i VALUE 26.

3.DATA(lv_string) = |Number of days lived | && |{lv_days_in_year * lv_age}| & | roughly.|.
4.WRITE: lv_string.

Ouput: Number of days lived till now: 9, 490 roughly.

If any of you readers observed the 3rd line closely we have used the chaining operator ‘&&’ and the literal operator ‘&’. lets talk about it.

next episode Iteration Expression FOR or series home page

3. ‘&&’ Vs. ‘&’

Here these two do the same thing but there are some differences. First difference is ‘&&’ has 2 ampersand signs and ‘&’ has one ampersand sign, 😛 I am sorry it was bad joke. Here is the real difference.

3.1 Chaining Operator(&&):

It is used to concatenate the character literals and can accept any number of literals to build a loooong continuous text. It is checked at the run time whereas for literal it gives a syntax error in compile time.

3.2 Literal Operator(&):

It is used do to define the string text across multiple program lines but it has a limit i.e. only up to 255 characters. As mentioned above it would give syntax error in compiling time.

Wondering what is ‘text across multiple program lines’? check this example.


In the above example each line has 70 characters so 70 * 4 = 280 characters which give a syntax error. Where as the following would not give any error with ‘&&’.


This works fine with ‘&&’. Hope you understand the difference.


1. ALPHA Conversion:

Remember that annoying function modules CONVERSION_EXIT_ALPHA_INPUT & CONVERSION_EXIT_ALPHA_OUTPUT?. To add or remove zeros numeric values. There is an expression we can use to avoid these function modules.

ALPHA = IN | OUT | RAW ( value ).

DATA(lv_vbeln) = ‘0000089846’.
WRITE / |{ lv_vbeln  ALPHA = OUT }|.

Output : 89846.

DATA(lv_vbeln) = ‘89846’.
WRITE / |{ lv_vbeln  ALPHA = IN }|.

Output: 0000089846.

2. Case:

WRITE / |{ ‘Text’ CASE = (cl_abap_format=>c_upper) }|.
WRITE / |{ ‘Text’ CASE = (cl_abap_format=>c_lower) }|.

Output: TEXT











They are more features available you can check in SAP Help document here

End of this section, go to next episode Iteration Expression FOR or series home page

More Episodes:

Constructor Operators

Squeezing ABAP Code

Table Expressions

Internal table functions

FOR Expression