Application Development and Automation 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: 
Read only

Replace Character with Space

Former Member
0 Likes
23,754

We need to replace dashes in a string with a space.


DATA result TYPE string.
result = 'Hello--World!'.
REPLACE ALL OCCURRENCES OF '-' IN result WITH ' '.

However ABAP compresses all space and the result is

'HelloWorld!'

1 ACCEPTED SOLUTION
Read only

Former Member
5,997

Hello

If you unnecessary to use REPLACE ALL OCCURRENCES, that try this way:


DATA result TYPE string.
result = 'Hello--World!'.
translate result using '- '.
condense result.
write result.

4 REPLIES 4
Read only

Former Member
0 Likes
5,997

Try this.


DATA result TYPE string.
DATA blank TYPE c LENGTH 20.
result = 'Hello--World!'.
OVERLAY result WITH blank ONLY '-'.
WRITE:/ result.

REPLACE statement does not respect blanks, OVERLAY does.

Read only

Former Member
5,998

Hello

If you unnecessary to use REPLACE ALL OCCURRENCES, that try this way:


DATA result TYPE string.
result = 'Hello--World!'.
translate result using '- '.
condense result.
write result.

Read only

0 Likes
5,997

is this work in amdp eclipse?

Read only

Former Member
5,997

have you searched SDN??

any ways...try the below one.. its a backquote

data : s1 type string value 'Hello--World!'.
replace all OCCURRENCEs OF `-` IN s1 WITH ` `. "this is the quote near by 1 in keyboard...
WRITE s1.