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

STRING REPLACE OPERATION

Former Member
0 Likes
1,238

Hi ,

for the code :

data : string(10) type c.

string = 'BAT_&_BALL'.

NOW I WANT TO REPLACE '_' IN STRING WITH SPACE ie ' '.

but when i use

Replace all occurrences of '_' in string with ' '.

then the output is 'BAT&BALL' ..NO SPACE IS BEING INSERTED.

I need to display it as BAT & BALL.

CAN NYONE HELP ME HOW TO REPLACE '_' WITH SPACE....

Thanks

Bhasker

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,060

Try this.



data : string(10) type c.
string = 'BAT_&_BALL'.

translate string using '_ '.

Regards

RIch Heilman

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,061

Try this.



data : string(10) type c.
string = 'BAT_&_BALL'.

translate string using '_ '.

Regards

RIch Heilman

Read only

0 Likes
1,060

Hi Rich,

Thanks for your reply.

translate string is not working for me

thanks

Bhanker

Read only

0 Likes
1,060

This sample program is working good in my NW2004s system. Copy and paste and test.



report  zrich_0003.

data : string(10) type c.
string = 'BAT_&_BALL'.

translate string using '_ '.

 Write:/ string.

REgards,

Rich Heilman

Read only

0 Likes
1,060

Hi Rich,

I am working with ECC 6.0

I just tested your code in my system.

I am getting the output as BAT_&_BALL.

Thanks

Bhasker

Read only

0 Likes
1,060

That is really weird. Are you sure that the literal in this statement has the underscore(_) and the space right next to it?

translate string using <b>'_ '</b>. <--There needs to be a space right next to the _ in this literal

REgards,

Rich Heilman

Read only

0 Likes
1,060

Hi Rich;

It was my mistake

I didnt put space right next to the _.

its working now

thanks

Bhasker

Read only

0 Likes
1,060

You scared me a little there, thought I was going crazy. Anyway, the way that the translate statement works in this context, is that you have two values in your literal, the first is what you are looking for and the second is what you want to translate it to. So for example, it can be anything.

data: string(10) type c,
 string = '1212121212'.

translate string using '20'.

So in this case the value will now be '1010101010'.

Regards,

Rich Heilman

Read only

0 Likes
1,060

Hi Guys,

I have a string containing spaces, my requirement is to replace all the spaces in the given string with some other character. Could you please help me the syntax in ABAP for this

Regards,

Hari

Read only

0 Likes
1,060

hi,

chk this.

REPLACE all occurances of space IN your_string WITH 'Your_character' INTO lv_date.

rgds

anver

if hlped pls mark points