This is a test message to test the length of the message box.
ABAP String Functions (Part 3)
Created by Software-Heroes

ABAP - String Functions (Part 3)

This article is about other new string functions and a replacement for CONDENSE. We would like to show you why you should use the new functions.

We have already discussed the new and practical functions in the last parts of the string functions. Today we're going to show you a few new options, a replacement of old one-line commands and why you actually need all these new functions.



The instruction is used to remove leading and trailing blanks in CHAR fields and strings. Furthermore, multiple spaces within the character string are compressed to one space. The instruction also offers a special function to remove all spaces.

In our examples we will refer to various constants and variables, so here are the basic definitions:

  c_string TYPE string VALUE `  This is  my name  `,
  c_char   TYPE c LENGTH 25 VALUE '  This is  my name  '.    

  ld_string TYPE string,
  ld_char   TYPE c LENGTH 25.


Hint: CHAR fields always fill the last digits with spaces, so the information above is actually superfluous. However, to keep the example unchanged, these have also been adopted.


Simple version

In the example, you will immediately notice that the new function works again with inline declaration and that we do not need our own variable for the transfer and we can work directly with the constant.

" Old
ld_string = c_string.
CONDENSE ld_string.

ld_char = c_char.
CONDENSE ld_char.    
" New
DATA(ld_new_string) = condense( c_string ).
DATA(ld_new_char) = condense( c_char ).



For the addition of the CONDENSE instruction, however, SAP does not provide any enhancement of the new function. But here you can fall back on a new function you have already learned about, the replace. Unfortunately, it shouldn't be written so briefly, but also very understandable in terms of implementation.

" Old
ld_string = c_string.

ld_char = c_char.
CONDENSE ld_char NO-GAPS.    
" New
DATA(ld_new_string) = replace( val = c_string sub = ` ` with = `` occ = 0 ).
DATA(ld_new_char) = replace( val = c_char sub = ` ` with = `` occ = 0 ).



Also known as substring access, you only need part of a character or a string from time to time. Previously, the very short version of the offset and the length were used directly on the corresponding character string. The SUBSTRING function is now available for this, as in other programming languages.

" Old
ld_string = c_string+3(3).
ld_char = c_char+3(3).
" New
DATA(ld_new_string) = substring( val = c_string off = 3 len = 3 ).
DATA(ld_new_char) = substring( val = c_char off = 3 len = 3 ).



In the last few articles on these topics, you will have probably asked yourself why you should use the new functions at all. An advantage that we have already mentioned is of course the use and nesting within existing calls (chaining), as well as the possibility of inline declaration.

A crucial point, however, is the use in ABAP coding and the simultaneous modeling of Core Data Services (CDS). In a HANA environment, many actions with the data should be outsourced to the database via code pushdown. Therefore, all new commands can be found in this environment and only these can be used. It is therefore very useful to get used to the new functions.


Here is a brief explanation of the functions used to define the columns in the CDS. More information about string functions in SQL via the following link.

  • UPPER - Conversion of the field content to capital letters, deviation from the ABAP function TO_UPPER
  • CONCAT_WITH_SPACE - Merge the content with a space in between
  • REPLACE - Replace the semicolons in the city field with commas (e.g. for the CSV deduction)



As you have seen, not all new commands and functions are automatically shorter and easier to use. However, there are also advantages to switching directly to the new functions, especially if you are already working on a HANA system.


SAP Documentation - Condense
SAP Documentation - Replace
SAP Documentation - Substring

Included topics:
New ABAPString Functions
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.