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: 

Help regarding the Syntax "REPLACE"

Former Member
0 Kudos

Dear Experts,

I'm stuck with a problem..... i am trying to REPLACE ALL OCCURRENCES OF 'AND' WITH 'AND datab LE' INTO s_where-low

and since im working with 4.6 this syntax gives me an syntax error as it wont recognize "ALL OCCURRENCES OF" as valid syntax,

Can someone plssss give me an alternative to achieve the above...

Regards,

Goldie.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

do like this

REPLACE 'AND' WITH 'AND datab LE' INTO s_where-low.

reward if it helps,

Satish

8 REPLIES 8

Former Member
0 Kudos

Hi,

do like this

REPLACE 'AND' WITH 'AND datab LE' INTO s_where-low.

reward if it helps,

Satish

0 Kudos

thank u satish but this syntax only replaces the first occurrence i want to replace all the occurrence's of the word!

former_member386202
Active Contributor
0 Kudos

Hi,

try like this.

REPLACE ALL OCCURRENCES OF 'AND' IN s_where-low WITH ''AND datab LE'.

Regards,

prashant

0 Kudos

Thank u Prashant Sriram and Bharat the syntax still gives me an error im workin on 4.6 and i think "ALL OCCURRENCES OF" addition to the REPLACE syntax results in an error .... im looking for an alternative solution.

Former Member
0 Kudos

Hi,

See the example below :

DATA: c4(4) TYPE C. 
c4 = 'abab'. 
REPLACE ALL OCCURRENCES OF 'ab' IN c4 WITH 'CCC'.

Thanks,

Sri.

Former Member
0 Kudos

HI,

see this example.u have to write like this.

DATA: text1 TYPE string VALUE 'I know you know',

sub_string TYPE string VALUE 'know',

new TYPE string VALUE 'should know that'.

REPLACE ALL OCCURRENCES OF sub_string in text1 with new.

write:/ text1.

rgds,

bharat.

Former Member
0 Kudos

Hi Goldie,

You can do it like below:

Do.

REPLACE f ...WITH g ...INTO h.

if sy-subrc = 0.

else.

exit.

endif.

Enddo.

This will keep on replacing the field with new one till it exists and when not it will exit out of loop.

Please reward points if reply is helpful.

Regards,

Ruchi

Former Member
0 Kudos

Hi

Check Possible Operations of REPLACE below "

  • replacing values

DATA: t4(10) TYPE c VALUE 'abcdefghij',

string4 LIKE t4,

str41(4) TYPE c VALUE 'cdef',

str42(4) TYPE c VALUE 'klmn',

str43(2) TYPE c VALUE 'kl',

str44(6) TYPE c VALUE 'klmnop',

len4 TYPE i VALUE 2.

string4 = t4.

WRITE string4.

REPLACE str41 WITH str42 INTO string4.

WRITE / string4.

string4 = t4.

REPLACE str41 WITH str42 INTO string4 LENGTH len4.

WRITE / string4.

string4 = t4.

REPLACE str41 WITH str43 INTO string4.

WRITE / string4.

string4 = t4.

REPLACE str41 WITH str44 INTO string4.

WRITE / string4.

Praveen

Hope it Helps .