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

Problem with replace function

Former Member
0 Likes
1,561

How can I use replace function in an internal table for eg

My internal table contain following entries.

line

my name is xyz

now I want to replace this xyz with priya..how to do that??? Can I use a place holder in internal table and feed data later to it? for eg

line

my name is &

and later add 'priya' in this place holder.

11 REPLIES 11
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,471

Hello,

You can use the REPLACE stmt for this.

REPLACE ALL OCCURRENCES OF '&' IN v_string WITH 'Priya'.

Suhas

Edited by: Suhas Saha on Feb 3, 2009 4:08 PM

Read only

former_member222860
Active Contributor
0 Likes
1,471

hi,

yes, u can do that

my name is &
REPLACE '&'  WITH 'Priya'.

Read only

Former Member
0 Likes
1,471

Hi,

You can use the replace statement

REPLACE sub_string WITH new into text1.

where sub_string = xyz

and text1 = priya.

Thanks & Regards

Read only

Former Member
0 Likes
1,471

Hi,

See the following code:



DATA: name type string VALUE 'xyz',
      name1 TYPE string VALUE 'priya'.


REPLACE name WITH name1 into name.

WRITE:/ name.

Like this u can loop ur internal table and replace the name.

Hope this helps u.

Thanks.

Read only

Former Member
0 Likes
1,471

Hi,

Yes, you can do it.

REPLACE 'xyz' WITH 'Priya'.

Other wise you can use move commad and pass to perticular field and append internal table.

Regards

Md.MahabooobKhan

Read only

0 Likes
1,471

my problem is I am passing an internal table and not a single variable...and it is not working in an internal table

Read only

0 Likes
1,471

Loop at itab.

Move tablename-fieldname to temp var.

replace temp var.

move the temp var back to tablename-fieldname.

modify table.

endloop

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,471

Hello Priya,

What is the structure of your internal table? Can you share this?

Else you can try this:


DATA: V_STR TYPE STRING.

LOOP AT ITAB INTO WA.
MOVE WA TO V_STR.
REPLACE ALL OCCURENECES OF '&' IN V_STR WITH V_TEXT. "You can pass a varaible as well
MOVE V_STR TO WA.
MODIFY ITAB INDEX SY-TABIX.
CLEAR V_STR.
ENDLOOP.

Waiting for your input.

BR,

Suhas

Read only

Former Member
0 Likes
1,471

data: name type TABLE OF string ,

wa_name type string.

wa_name = 'my name is xxx'.

append wa_name to name.

REPLACE ALL OCCURRENCES OF 'xxx'

IN TABLE name WITH 'PRIYA' .

Read only

Former Member
0 Likes
1,471

Hi There,

use modify.

for eg:

123 345 abc

read that particular line with key using read statement.

itab-<filed> = priya.

Modify <itab>.

Reg

Read only

Former Member
0 Likes
1,471

hi,

if you are replacing one reocrd than


    REPLACE FIRST OCCURRENCE OF REGEX 'XYZ' IN wa_t090naz-afasl WITH 'PRIYA'.

If you want to alter all record where is name is XYZ.

than use this code




LOOP AT it_t090naz INTO wa_t090naz.

    " Replacing v to l.

    REPLACE FIRST OCCURRENCE OF REGEX 'XYZ' IN wa_t090naz-afasl WITH 'PRIYA'.
   
   "wa_t090naz-afasl  is the name of work area of internal table and afasl is the name of field,
Endloop.

Hope it will help you.

Thanks

Arun kayal.