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

About REPLACE ALL functionality

Amey-Mogare
Contributor
0 Likes
1,103

Dear All,

I have one string which contains '#' in between. And I want to replace all these '#' with ' ' (ie blank SPACE)..

For this I am using:-

REPLACE ALL OCCURRENCES OF '#' IN L_TEXT WITH ' '.

But to my greatest surprise, its not able to replace it saying sy-subrc = 4 ie its not able to locate '#'.

I have observed following:-

1. Suppose L_TEXT = 'corrective action## is that# to be #taken'

then replace all fails.

2. But suppose L_TEXT = 'corrective action # # is that # to be # taken'

then its works.

I tried the option of

REPLACE ALL OCCURRENCES OF REGEX '#*' IN L_TEXT WITH ' '.

But its putting ''#" after every character !!!

And the same functionality works with CRM4.0's ABAP editor but now when i am using it in CRM2007's ABAP editor, its not woking.

I have tried it in ABAP editors of other systems like PRD n all. Its working there too.

Can anybody please shed some light on this?

regards,

Amey Mogare

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,041

Hi Amey,

Try This.

REPLACE ALL OCCURRENCES OF '#' IN L_TEXT WITH SPACE.

Regards,

Chandra Sekhar

8 REPLIES 8
Read only

Former Member
0 Likes
1,041

Hi Amey,

try it with space :

REPLACE ALL OCCURRENCES OF '#' IN L_TEXT WITH     SPACE.

With luck,

Pritam.

Read only

Former Member
0 Likes
1,042

Hi Amey,

Try This.

REPLACE ALL OCCURRENCES OF '#' IN L_TEXT WITH SPACE.

Regards,

Chandra Sekhar

Read only

0 Likes
1,041

Nope...

As per mentioned in the my question post, SY-SUBRC is 4 which means that system is not able to locate character '#'...

And same piece of code is working if i separate the # with leading and trailing spaces !!!

regards,

Amey

Read only

matt
Active Contributor
0 Likes
1,041

Are you sure it's #?

SAP display undisplayable characters, like TAB as #.

In debugger, you can find the hex for the character represented as #. E.g. x10 is TAB. Then you should use, CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB as the string to replace.

matt

Read only

0 Likes
1,041

Yes Matt,

I suspect its not the actual character "#". !!!!

Actually in one of the CRM transaction GUI, there is a Text Box where user can enter his Survey details. In this, if he enters a newline then in FM i'm getting it as "#"... What I mean is if I write :-

Heading 2: h2.

Containment text

is as follows

line 1

line2

Heading 2: h2.

Then in FM's field its represented as

Heading 2: h2.

Containment text# is as follows# line 1# line2

Heading 2: h2.

But this is getting messed up in when we dump it into excel sheet.

So how do i replace these with Spaces?

sample code line would be very helpful.

Thanks a lot for pointing this out.

regards,

Amey

Read only

0 Likes
1,041

there is a Little modification Matt's suggestion , that '#' is coming from New line, So you can replace all New lines using this code.

Using CL_ABAP_CHAR_UTILITIES=>NEWLINE we can replace that '#'.

REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE IN WA_REC WITH SPACE.

Read only

0 Likes
1,041

Thank you so much Vijay and Matt...

Thank you very much...

regards,

Amey Mogare

Read only

Former Member
0 Likes
1,041

hi,

you can try this

Data:

w_char type c.

REPLACE ALL OCCURRENCES OF REGEX w_char IN L_TEXT WITH space.

Regards

Sumit Agarwal