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

Replace field in internal table

Former Member
0 Likes
999

Hi gurus,

I have an internal table in which I need to replace a field with a different value. I have tried the REPLACE __ IN TABLE __ WITH statement, but it did not seem to work.

Also, I cannot use a SORT TABLE statement because the record needs to be at a certain index in the table.

Any suggestions? <REMOVED BY MODERATOR>

Thanks in advance!

Edited by: Alvaro Tejada Galindo on Aug 14, 2008 3:03 PM

1 ACCEPTED SOLUTION
Read only

former_member585060
Active Contributor
0 Likes
919

Try tis

Loop At it_Itab into wa_itab.

if wa_itab = 'ABCE'.

wa_itab-field = '1234'.

MODIFY it_itab FROM wa_itab TRANSPORTING field.

endif.

endloop.

For using sorting the sorting field must be first feild in the internal table while declaring.

Edited by: Bala Krishna on Aug 15, 2008 12:09 AM

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
919

Try like this:


LA_WORK-MATNR = 'TEST'.
MODIFY ITAB FROM LA_WORK TRANSPORTING MATNR WHERE MATNR = '12345'.

Regards,

Naimesh Patel

Read only

former_member585060
Active Contributor
0 Likes
920

Try tis

Loop At it_Itab into wa_itab.

if wa_itab = 'ABCE'.

wa_itab-field = '1234'.

MODIFY it_itab FROM wa_itab TRANSPORTING field.

endif.

endloop.

For using sorting the sorting field must be first feild in the internal table while declaring.

Edited by: Bala Krishna on Aug 15, 2008 12:09 AM

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
919

Hi. If you know the exact field in the exact row of the table, you could do something like this. This is direct access to the field without having to use the MODIFY statement.

REPORT  zrich_0001.

TYPES: BEGIN OF ttab,
       fld1 TYPE c,
       fld2 TYPE c,
       fld3 TYPE c,
       END OF ttab.

DATA: itab TYPE TABLE OF ttab.
DATA: wa LIKE LINE OF itab.
FIELD-SYMBOLS: <wa> LIKE LINE OF itab.

* fill ITAB with data.
wa-fld1 = 'A'.
wa-fld2 = 'B'.
wa-fld3 = 'C'.
APPEND wa TO itab.
wa-fld1 = 'D'.
wa-fld2 = 'E'.
wa-fld3 = 'F'.
APPEND wa TO itab.
wa-fld1 = 'G'.
wa-fld2 = 'H'.
wa-fld3 = 'I'.
APPEND wa TO itab.

* Now access FLD2 of row 2, and change the value to X
READ TABLE itab ASSIGNING <wa> INDEX 2.
IF sy-subrc  = 0.
  <wa>-fld2 = 'X'.
ENDIF.

Regards,

Rich Heilman