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

HI all!

I have two internal tables with single field values as below :

1st Internal Table : A,B,C,D

2nd Internal Table : A,B,C,D,E,F,G,

Now I want to compare these two Int. tables and delete the second int. table with values which are not there in the first int. table.Any simple logic to get this.

Regards

Pavan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

loop at itab_old.

DELETE TABLE itab WITH TABLE KEY k1 = itab_old-k1 ... kn = itab_old-kn.

endloop.

9 REPLIES 9

Former Member
0 Kudos

loop at itab_old.

DELETE TABLE itab WITH TABLE KEY k1 = itab_old-k1 ... kn = itab_old-kn.

endloop.

Former Member
0 Kudos

Hi

LOOP AT ITAB2.

READ TABLE ITAB1 WITH KEY FIELD = ITAB2-FIELD.

IF SY-SUBRC <> 0. DELETE ITAB2. ENDIF.

ENDLOOP.

max

Former Member
0 Kudos

hi

DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.

or

loop at itab2.

read table itab1 with key f1 = itab2-f1.

if sy-subrc <> 0.

delete itab2.

endif.

endloop.

Former Member
0 Kudos

loop at itab2.

read table itab1 with key colum1 = itab2-column1 column2 = column2.

if sy-subrc = 0.

delete itab2.

endif.

endloop.

Regards,

Ravi

Note : Please mark the helpful answers

nishanthbhandar
Contributor
0 Kudos

Sort internal table 1 by A B C D.

Now ..

copy contents of 2nd table to a temp table.

loop at 2nd internal table.

read 1st internal table with key a = 2internal table a

b = 2internal table b

c = 2internal table c

d = 2internal table d.

if sy-subrc ne 0.

delete entry from temp table.

now refresh table 2.

copy contents of temp to table 2.

Guys,

I guess DELETING THE SAME TABLE WITHIN A LOOP .. ENDLOOP is not advisable.Please correct me if i m wrong.

endif.

endloop.

Message was edited by: Nishanth Bhandar

Message was edited by: Nishanth Bhandar

Former Member
0 Kudos

HI Kumar,

Try with following code.

ITAB1 FIELD1 FIELD2 FIELD3 FIELD4

1stIT A B C D

ITAB2 FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7

2ndIT A B C D E F G

<b>LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY FIELD1 = ITAB1-FIELD1 FIELD2 = ITAB1-FIELD2 FIELD3 = ITAB1-FIELD3 FIELD4 = ITAB1-FIELD4.

IF SY-SUBRC <> 0.

DELETE ITAB2.

ENDIF.

ENDLOOP.</b>

Thanks,

Vinay

Former Member
0 Kudos

Hi pavan,

Please check this code.

loop at tab1.

read table tab2 with key field1 = tab1-field1.

if sy-subrc ne 0.

delete tab2.

modify tab2.

endif.

endloop.

Hope this will help u.

Former Member
0 Kudos

Hi pavan,

I hope this works for ur criteria...

Loop at itab1.

Delete Itab2 where field_1 <> itab1-field_1

and field_2 <> itab1-field_2

and field_3 <> itab1-field_3

Endloop.

regards,

Kiran B

Former Member
0 Kudos

Hi,

try this,,

sort: it1 , it2 ,

loop at it1.

read table it2 with key pernr = it1-pernr

FAC_C = it1-FAC_C

binary search.

if sy-subrc eq 0.

write: / it1-pernr, it1-fac_c.

endif.

endloop.

or

User Corresponding field option

or

if it1[] = it2[].

If it helps reward points

Regards,

Nandha