Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP CDS - string function to remove spaces?

vonglan
Active Participant
0 Kudos
2,935

I would like to create a CDS that provides a template for creating CDS from tables.

For this purpose, I would like to remove the spaces in database field dd04t.scrtext_l (long text of fields).

How can I do this?

The simple

replace( dd04t.scrtext_l, ' ', '' )

does not work. Maybe the "trailing spaces" in the second argument are removed.

Backquotes to preserve the space are not allowed.

Workarounds like the following also did not work:

  • cast( '' as abap.char( 1 ) ) ,
  • concat( '', ' ' ), // I found this in SAP course material
  • concat_with_space( '', '', 1 ),

Is there no way to do this in CDS? (Of course, I can always use ABAP.)

Update: I published the ABAP report for the task here:

Utility Report to provide the long field names when creating a new basic CDS | SAP Blogs

5 REPLIES 5

vonglan
Active Participant
0 Kudos
1,119

sandra.rossi :

1) would you mind explaining how exactly you searched ? I did not find anything related to removing spaces in core data services

2) the approach with char(32) did not work for me (syntax error). Did you mean

                         cast( '' as abap.char( 32 ) ) ,

?

That also did not work

Sandra_Rossi
Active Contributor
0 Kudos
1,119

I'm so sorry, I completely missed that your question was about CDS, and I was looking at SQL/SQLScript/AMDP (in SQL, replace also didn't work for removing spaces, the SQL function CHAR(32) worked), so please forget my previous comment. I just deleted it to not confuse future readers.

Sandra_Rossi
Active Contributor
1,119

In fact, just thinking again, if we create a CDS Table Function whose AMDP does REPLACE( dd04t.scrtext_l, char(32), '' ) (here CHAR(32) OR NCHAR(32) will work, being a HANA SQL function), I think it should work.

Former Member
0 Kudos
1,119

Are you talking about leading or trailing spaces and other characters? What kind of value is it?

Try these keywords see which one fulfills your requirement- LTRIM or RTRIM, LEFT, RIGHT

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abensql_functions_string.htm

0 Kudos
1,119

no, it is not about trailing of leading spaces