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

abap st.

Former Member
0 Likes
1,298

Hi ,

In the internal table i have the following fields .

INTERNAL TABLE

FIELD1 FIELDS2 FIELD3

X1 ABCDF Y1

X2 TRSRT Y2

X3 TX ABCD TX ABCD

need to replace 'ABCDF' with 'RRRRRRRRRR' where every 'ABCD' text occurs in the internal table

USING 'search' and 'replace' commands only.

thxs,

Vind

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,258

Something like this might do it.



LOOP AT itab.
  REPLACE ALL OCCURRENCES OF 'ABCDE' IN itab WITH 'RRRRR'.
modify itab.
ENDLOOP.


Regards,

RIch Heilman

Hi ,

In the internal table i have the following fields .

INTERNAL TABLE

FIELD1 FIELDS2 FIELD3

X1 ABCDF Y1

X2 TRSRT Y2

X3 TX ABCD TX ABCD

need to replace 'ABCDF' with 'RRRRRRRRRR' where every 'ABCD' text occurs in the internal table

USING 'search' and 'replace' commands only.

thxs,

Vind

10 REPLIES 10
Read only

Former Member
0 Likes
1,258

Use the below code...

loop at itab.

if itab-field2 CS 'ABCD'.

itab-field2 = 'RRRRRRRRRR'.

modify itab index sy-tabix.

endif.

endloop.

Read only

former_member491305
Active Contributor
0 Likes
1,258

Hi ,

Use like this...

loop at it_data itno x_data.

REPLACE ALL OCCURrENCES OF 'ABCD' IN x_data-maktx

WITH 'RRRRRRRRRRR'.

modify it_data from x_data.

endloop.

Read only

Former Member
0 Likes
1,258

Hi Vind,

<b>

Here t_table is a internal table with header line :</b>

data:

t_table LIKE

STANDARD TABLE

OF <abc_structure>

WITH HEADER LINE.

LOOP AT t_table.

IF t_table-field co 'ABCDF'.

t_table-field = 'RRRRRRRRRRR'.

MODIFY t_table.

ENDIF.

ENDLOOP.

<b>

Reward all helpful answers</b>

Regards,

V.Raghavender.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,259

Something like this might do it.



LOOP AT itab.
  REPLACE ALL OCCURRENCES OF 'ABCDE' IN itab WITH 'RRRRR'.
modify itab.
ENDLOOP.


Regards,

RIch Heilman

Read only

0 Likes
1,258

Or this may be the fool proof way.



FIELD-SYMBOLS: <fs>.
LOOP AT itab.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE itab TO <fs>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    REPLACE 'ABCDE' IN <fs> WITH 'RRRRR'.
  ENDDO.
  MODIFY itab.
ENDLOOP.

Regards,

RIch Heilman

Read only

0 Likes
1,258

Hi Rich ,

I am using the below code , but it resulted in an ABAP dump saying .

Error Analysis :

The argument <FS> can only take a character -type data object.

In this case , the operand <FS> has the non-character type 'F'.

May i know how to recity this ??

thanks,

Vind

Read only

0 Likes
1,258

Ooops, try this.



FIELD-SYMBOLS: <fs>.
LOOP AT itab.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE itab TO <fs>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    DATA: field_type TYPE string.
    DESCRIBE FIELD <fs> TYPE field_type.
    IF field_type = 'C'.
      REPLACE 'ABCDE' IN <fs> WITH 'RRRRR'.
    ENDIF.
  ENDDO.
  MODIFY itab.
ENDLOOP.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,258

Hi,

loop at internal_table.

replace 'ABCDF' with 'RRRRRRRRR' into internal_table-field1.

replace 'ABCDF' with 'RRRRRRRRR' into internal_table-field2.

replace 'ABCDF' with 'RRRRRRRRR' into internal_table-field3.

modify internal_table.

endloop.

regards,

Read only

Former Member
0 Likes
1,258

Hi,

Loop at Itab.

search itab for 'ABCD'.

if sy-subrc = 0.

replace all occurrences 'ABCD' in itab with 'RRRRRRRRRRR'.

endif.

modify itab index sy-tabix.

endloop.

Read only

Former Member
0 Likes
1,258
loop at itab into wa_itab.
  search wa_itab-field2 for 'ABCD'.
    if sy-subrc eq 0.
        replace 'ABCD'  in wa_itab-field2 with 'RRRRRRRR'.
        modify itab from wa_itab.
    endif.
endif.