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 sentence

Former Member
0 Likes
663

hi,

now i want replace , with space in string ,i use replace sentence,ie

REPLACE ALL OCCURRENCES OF REGEX ',' IN string WITH ''.

at ecc6.0 this sentence is ok ,but at 4.6c it has error.

can you help me ? my sap edition s 4.6c .

regards

sophia

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
597

Hi,

REPLACE syntax in 4.6c is

REPLACE f ...WITH g

...INTO h.

Replaces the first occurrence of the contents of field f in field h with the contents of field g.

If you want to replace all the commas with blank space ,

DO.

REPLACE ',' WITH ' ' INTO l_f_string.

if sy-subrc <> 0.

exit.

endif.

ENDDO.

6 REPLIES 6
Read only

Former Member
0 Likes
597

Try this.

REPLACE ALL OCCURRENCES OF ',' WITH ' ' IN string .

condense string.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
597

Hi,

You cannot use Replace all occurences in 4.6c.You can use replace.

data str(5) value '34,45'.

REPLACE ',' WITH '' into str.

condense str no-gaps.

write str.

Read only

former_member189059
Active Contributor
0 Likes
597

Replace all occurrences doesn't work in 4.6c

what you can do is a

while sy-subrc = 0.

replace ',' into regex with ''.

endwhile.

condense regex no-gaps.

Edited by: Kris Donald on Dec 20, 2007 8:31 AM

Read only

Former Member
0 Likes
598

Hi,

REPLACE syntax in 4.6c is

REPLACE f ...WITH g

...INTO h.

Replaces the first occurrence of the contents of field f in field h with the contents of field g.

If you want to replace all the commas with blank space ,

DO.

REPLACE ',' WITH ' ' INTO l_f_string.

if sy-subrc <> 0.

exit.

endif.

ENDDO.

Read only

Former Member
0 Likes
597

Hi

Check this..also from 4.6C

REPLACE ',' WITH ' ' INTO H_FIELD.

Hope this Helps.

Praveen

Read only

former_member402443
Contributor
0 Likes
597

Hi Sophia,

In place of replace statement you can also use Translate statement.

Example:

DATA : v_text(4) value ', '.

Data : v_str type string.

string = 'This is, one, of the, demo, of, translate,statement'.

TRANSLATE v_str USING v_text.

Here v_text contain the pattern in which you want to covert the string . so in this example all the , are replace by space.

Reward points,if useful.

Regards,

Manoj Kumar