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

Replacing string with space

Former Member
0 Likes
921

Hi SDNers,

I have an address field of length 100.But it has single quotes ( ' ).

I have to replace the single quote with space...can anyone suggest me

how it can be done...am using (contains pattern) but unsuccessful.

Thanks

Mahendhar Reddy

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
889

Please try with <b>TRANSLATE</b> statement.

Please check this example:

parameters: p_text(10) type c.

translate p_text using ''' '.
write:/ p_text.

Kind Regards

Eswar

9 REPLIES 9
Read only

Former Member
0 Likes
890

Please try with <b>TRANSLATE</b> statement.

Please check this example:

parameters: p_text(10) type c.

translate p_text using ''' '.
write:/ p_text.

Kind Regards

Eswar

Read only

raja_thangamani
Active Contributor
0 Likes
889
  • Populate the Single Quotes with Space.



CONSTANTS: C_QUOTE_SNG TYPE C  VALUE ''''.

REPLACE ALL OCCURRENCES OF C_QUOTE_SNG IN V_STRING WITH SPACE.

THis will slve your problem.

<b>Note:</b> Reward each useful post.

Raja T

Message was edited by:

Raja T

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
889

As suggest earlier, use the TRANSLATE statement, here is an example.



report zrich_0001.


data: str type string.

str = '12345''67890''abcde'.

translate str using ''' '.

write:/ str.

REgards,

RIch Heilman

Read only

0 Likes
889

oops, Eswar already has one there for ya.

Regards,

Rich Heilman

Read only

0 Likes
889

@ Rich

Maybe you have missed out while i was editing my post...:)

Kind Regards

Eswar

Read only

0 Likes
889

I believe so, I was writing my example at that time

Regards,

RIch Heilman

Read only

0 Likes
889

@ Rich

More Examples ---> Better Understanding.

So i guess it is never a problem.:)

Hope our examples will help Mahendhar...

Kind Regards

Eswar

Read only

0 Likes
889

Vow...you guys are very helpful man...

Thanks a lot.yaah...examples have not only solved my prblm but

taught several other things..thanks again

Read only

Former Member
0 Likes
889

Hi Mahendhar,

Try this:

DATA: text TYPE STRING.

text = 'abcdefgh'.

REPLACE 'd' IN text WITH 'XXXX'.

returns: text = 'abcXXXXefgh', sy-subrc = 0

Rewards if the above helps.

Cheers,

Patrick