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: 

Modifying an internal table

Former Member
0 Kudos

Hi frirnds,

I need to modify a internal table under the loop of a another internal table... Presen, I am doing this as..

loop at itab1.

read table itab2 with key (Some condition)....

itab2-f1 = xxx.

modify itab2 index sy-tabix from itab2.

Is the way i am approaching is correct...Because sy-tabix shows the record no of itab1, but i need to modify itab2.... Should i use sy-tabix or sy-index here....if i wont use any of that its going toshort dump..so i think i need to use an index...Pls sugest me...

Thanks,

Shyam.

5 REPLIES 5

h_senden2
Active Contributor
0 Kudos

In F1 help for statement READ TABLE :

SY-TABIX is set to the index of the entry.

regards,

Hans

Former Member
0 Kudos

Hi,

Store the index directly after the read for use later like.

Loop at itab1.
  read itab2 with key...
  if sy-subrc = 0.
    lv_tabix = sy-tabix.
  else.
   clear lv_tabix.
  endif.
....
...
   if lv_tabix <> 0.
   modify itab2 index lv_tabix.
   endif.
endloop.

Darren

Former Member
0 Kudos

Hi Shyam Prasad,

You can use SY-TABIX.

Because you want the index of the record that satisfies the condition in SECOND internal table.

Initially, SY-TABIX has the index from FIRST inernal table.

After READ in SECOND internal table, it will be changed that is the value we want to modify in it.

Use it within IF SY-SUBRC = 0... ENDIF.

Regards,

R.Nagarajan.

naveen_inuganti2
Active Contributor
0 Kudos

Hi...

Check this code..

Declare one variable..

loop at itab.
 n = n + 1.
read table itab2 with key f1 = itab-f1.
if sy-subrc = 0.
  itab2-f2 = 'XXX'.
  modify itab2 index n.
endif.

Thanks,

Naveen.I

rainer_hbenthal
Active Contributor
0 Kudos

I would do it in a modern way avoiding such discussions and with more performance:


  data:
    tab1 type standard table of t1,
    tab2 type standard table of t2.

  field-symbols:
    <p1> type t1,
    <p2> type t2.

  loop at tab1 assigning <p1>.

    read table tab2 assigning <p2> where.....
    if sy-subrc = 0.
      <p2>-field = 'ABCDE'.
    endif.
  endloop.

No doubt with sy-tabix.