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

Modify statement in internal table

Former Member
0 Likes
1,139

Hi ,

I have internal table it_tab contains data . I have one more internal table IT_TAB2 contains the data .

ITAB1 data:-

MATNR MTART EXTRA

12345 HALB

4567 HALB

ITAB2 data:-

MATNR EXTRA

12345 0678909

12345 0678967

here only MATNR is the key field in both internal tables.

loop at it_tab.

loop at it_tab1 where matnr = it_tab-matnr.

it_tab-extra = it_tab1-extra.

modify it_tab.

endloop.

endloop.

it is diplaying like below

12345 HALB 0678967

12345 HALB 0678967

But I want print like below when I use the modify statement .

12345 HALB 0678909

12345 HALB 0678967

Please help me in this .

regards,

Ajay reddy

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
1,087

you goto mention the index where that record need to be updated..

example : 
modify itab from wa index sy-tabix.

10 REPLIES 10
Read only

former_member156446
Active Contributor
0 Likes
1,088

you goto mention the index where that record need to be updated..

example : 
modify itab from wa index sy-tabix.

Read only

Former Member
0 Likes
1,087

Hi,

Try like below:


data: lv_tabix like sy-index.
loop at it_tab.
lv-tabix = sy-tabix.
read table it-tab1 with key matnr = it_tab-matnr.
if sy-subrc = 0.
it_tab-extra = it_tab1-extra.
modify it_tab index lv-tabix transporting extra.
endif.
endloop.

Regards,

Himanshu

Read only

0 Likes
1,087

Hi ,

Still i am getting the same result. any help.

regards,

Ajay

Read only

0 Likes
1,087

Hi Ajay,

Am still not clear with your question. You have given a sample for itab1 and itab2. What are the contents of itab? Can you explain your requirement?

Read only

0 Likes
1,087

Try this you dont need modify if you do this:

field-symbols: <fs_tab> type line of tab,
<fs_tab1> type line of tab1.

loop at it_tab assigning <fs_tab>.
  loop at it_tab1 assinging <fs_tab1> where matnr = <fs_tab>-matnr.
  if sy-subrc eq 0.
  <fs_tab>-extra = <fs_tab1>-extra.
  endif.
  endloop.
endloop.

Read only

0 Likes
1,087

Hi Vikranth,

I am impoting the values from One Function module.. into both the internal tables.

Just I want update the ITAB1 where the Blank data (EXTRA), need to fill that from ITAB1.

I am trying the options given by our friends....

regards,

Ajay reddy

Read only

0 Likes
1,087

Hi Ajay,

Based on your first post:


ITAB1 data:-
MATNR MTART EXTRA
12345 HALB 
4567 HALB 

ITAB2 data:-
MATNR EXTRA
12345 0678909
12345 0678967

You are looking for a result like below:


12345 HALB 0678909
12345 HALB 0678967

Which is not only updating the extra field but updating extra fields for all extra values in itab2 and removing any lines in itab1 where matnr does not have extra.

So if you want result like this you should refer to my second post which will provide you result like that in the third internal table

Regards,

Himanshu

Read only

Former Member
0 Likes
1,087

Hi,

sort it_tab by matnr.

sort it_tab1 by matnr.

loop at it_tab into ws_itab.

read table it_tab1 into ws_itab1 with key matnr = it_tab-matnr.

if sy-subrc = 0.

ws_tab-extra = ws_tab1-extra.

modify it_tab from ws_itab transporting extra.

endloop.

Regards,

Subramanian

Read only

Former Member
0 Likes
1,087

Hi,

Do as follows:-

loop at it_tab.

READ TABLE it_tab1 into WA1
with key matnr = it_tab-matnr.
if sy-subrc eq 0.
it_tab-extra = wa1-extra.

modify it_tab.

endif.
endloop.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
1,087

Hi,

try like below:

declare one more internal table like itab lets say itab2.


loop at itab.
  loop at itab1 where matnr = itab-matnr.
   move-corresponding itab to itab2.
 itab2-extra = itab1-extra.
append itab2.
  endloop.
endloop.

Regards,

Himanshu