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: 

Modify internal table

Former Member
0 Kudos

Hi all,

i got 5 record in my internal table. How can i modify the data in the 4th record.

Assume 4th record now is 'abc'. i want to change it to 'xyz'. My internal still contain 5 records.

How can i do it?

Thks

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos


data: begin of itab occurs 0,
        field1(10) type c,
        end of itab.
data: wa like line of itab.

wa-field1 = 'XYZ'.
modify itab from wa index 4.

Regards,

RIch Heilman

9 REPLIES 9

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos


data: begin of itab occurs 0,
        field1(10) type c,
        end of itab.
data: wa like line of itab.

wa-field1 = 'XYZ'.
modify itab from wa index 4.

Regards,

RIch Heilman

0 Kudos

Okie..What happen if i duno the index no but only a certain value in the itab field

assume i know the field itab-admino

i want to modify the field itab-name from 'gary' to 'peter'.

How can i do it? thks.

0 Kudos

basically the fool proof way is to read the table using the READ statement based on some KEY field, then move the new value to the field, and MODIFY it using the WA and specifing the INDEX.


read table itab into wa with key admino = '12345'.
if sy-subrc  = 0.
   itab-name = 'Peter'.
   modify itab from wa index sy-tabix.
endif.

Regards,

Rich Heilman

0 Kudos

okie.

Can u provide me the data type for wa also. Thanks

0 Kudos

WA would be typed like a line of your internal table. So say that you internal table, ITAB is typed like so..


data: itab type table of t001.

The WA would be typed like line of ITAB


data: wa like line of itab.

Regards,

Rich Heilman

0 Kudos

i test the program. But the value still remain unchanged. Below is my code. Pls help me to look thru . Thk.

Data : Begin of itab occurs 10.

firstname(30) type c,

lastname(30) type c,

End of itab.

Data: wa like line of itab.

*Add some value to the itab

itab-firstname = 'gary'.

itab-lastname = 'chen'.

append itab.

itab-firstname = 'pete'.

itab-lastname = 'zhang'.

append itab.

read table itab into wa with key firstname = 'pete'.

if sy-subrc = 0.

itab-lastname = 'lin'.

modify itab from wa index sy-tabix.

endif.

*check the itab for lastname change

loop at itab.

write: / itab-firstname.

write: itab-lastname.

endloop.

result: i still gt back the lastname as 'zhang' instead of the modify value 'lin'.

Pls help . Thank

0 Kudos

Solved on my own mistake. Thank for the fast reply..

gopi_narendra
Active Contributor
0 Kudos

describe table TAB lines N. " N gives the no of rows in ITAB
read table ITAB index N-1. " supposing that you wnat to edit the last but one record
  IF sy-subrc = 0.
    ITAB-FIELD1 = 'XYZ'.
    modify ITAB.
    clear : ITAB.
  ENDIF. 

Regards

Gopi

former_member589029
Active Contributor
0 Kudos

Assumed your table is itab and the tables workarea is ls_wa

ls_wa = 'xyz'.

modify itab from ls_wa index 4.

That's it.

Regards,

Michael