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 all occurences

Former Member
0 Likes
1,807

Hi gurus,

I have a problem with this statement..

I just give the code: REPLACE ALL OCCURRENCES OF '##' IN l_comment WITH ' '.

when l_comment value is testing##replace, after reach this command, the result should be testing replace, but after i debugged it the result become testingreplace. Is there any symbol for the ' ', except space.. when i use space in the command.. the result still has no space. Thanks..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,778

U can use

TRANSLATE / REPLACE commands

Narendra

12 REPLIES 12
Read only

Former Member
0 Likes
1,778

are you sure there is no additonal CONDENSE statement which you may have overseen?

Read only

0 Likes
1,778

No condense for the statement replace occurences.. and i need space, not to omitted the space.

Read only

Former Member
0 Likes
1,778

Hi,

Try this

Constants: lv_new_line type c value 'CL_ABAP_CHAR_UTILITIES=>NEWLINE'.

REPLACE ALL OCCURRENCES OF lv_new_line IN l_comment WITH space.

Regards,

Satish

Read only

0 Likes
1,778

Cannot do that, the data consists of ##.. so u must replace the ## with space.. The result still the same, no space between two words.

Read only

0 Likes
1,778

well normally i´d say the replace commanbd got to work, but this wont help you.

what about doing the thing by hand?

search your_string for '##'.

then the position of ## is beeing stored in sy-fdpos.

you can now split the string into two strings.

lv_fdpos = sy-fdpos + 2.

lv_string1 = your_string(sy-fdpos).

lv_string2 = your_string+lv_fdpos.

and now :

concatenate lv_string1 lv_string2 into your_string separated by space.

Read only

0 Likes
1,778

Hi,

'##' Represents New Line only. So, better Split the data and move to an internal table.

SPLIT text AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TABLE itab.

If it doesn't work, try these also cl_abap_char_utilites=>cr_lf & cl_abap_char_utilities=>linefeed.

Regards,

Satish

Read only

0 Likes
1,778

Thank you for ur reply.. put it into internal table.. but doesnt it will time consuming? i already loop the internal table.. the comment is just part of the internal table itself, so by putting into internal table, do u say i must loop the internal table again. And what is the type for the internal table?

Read only

0 Likes
1,778

do.

REPLACE '##' WITH new INTO lv_c.

FIND FIRST OCCURRENCE OF '##' IN lv_c.

IF sy-subrc IS NOT INITIAL.

EXIT.

ENDIF.

enddo.

Read only

Former Member
0 Likes
1,779

U can use

TRANSLATE / REPLACE commands

Narendra

Read only

0 Likes
1,778

The Data can be Hello##World##Many##obstacle..

U cannot use just replace or translate. Thats why i'm using replace all occurences, but the problem is, after replace the '##' with space, the word doesnt have space between them.

Read only

0 Likes
1,778

Hi,

If so do split it to an itab and concatenate:

like:

DATA:

itab TYPE TABLE OF string,

text TYPE string.

text = `What#a#drag##t is getting old`.

SPLIT text AT '##' INTO TABLE itab.

Regards,

Renjith Michael.

Read only

Former Member
0 Likes
1,778

Hi,

You cannot replace entries with SPACE.

Instead try like:

split l_comment at '##' into str1 str2.

clear l_comment.

concatenate str1 str2 into l_comment separated by SPACE.

Hope this will solve ur problem.

Regards,

Renjith Michael.