Application Development 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: 

about replace sentence

Former Member
0 Kudos
181

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

Former Member
0 Kudos
115

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

former_member181962
Active Contributor
0 Kudos
115

Try this.

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

condense string.

jayanthi_jayaraman
Active Contributor
0 Kudos
115

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.

former_member189059
Active Contributor
0 Kudos
115

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

Former Member
0 Kudos
116

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.

Former Member
0 Kudos
115

Hi

Check this..also from 4.6C

REPLACE ',' WITH ' ' INTO H_FIELD.

Hope this Helps.

Praveen

former_member402443
Contributor
0 Kudos
115

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