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: 

Comparing two internal tables

Former Member
0 Kudos
98

Hi all,

I have one internal table itab1 which has contents from legacy system. Now I have another internal table itab2 which has contents from a SAP standard table,i.e. AMPL. I have to compare the contents of these two tables i.e. itab1 and itab2 and add those entries to the AMPL table which are present in itab1 but not in itab2. I can explain it more if anyone helps me out here. Points assured.

Thanks.

2 REPLIES 2

former_member156446
Active Contributor
0 Kudos
55

Hi SAP tech.. use this sample code..

Sort table itab2 by k1 k2 k3..

loop at itab1.

read table itab2 with key k1 = itab1-k1

k2 = itab1-k2 binary search.

if sy-subrc = 0.

delete itab2 index sy-index.

endif.

endloop.

finally itab2 will have that sort of entries which are not in Itab1.

Award points if helpful

Former Member
0 Kudos
55

Hi,

For comparing 2 internal tables first we want to sort the two internal tables.

But in some cases we dont know whether the two tables contain the same number of values(records).So we want to compare a single value to another int table.

If there is any key value means we can check it with that by comparing tht particular value in loop.

loop at itab.

read table itab1 with key field values = itab-keyvalue. / We can also use loop at itab1 where keyvalue = itab-keyvalue.

if sy-subrc = 0.

if it matches we can do wht evr inside this block

endif.

endloop.

reward if useful