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: 

How to Compare two itab and delete entries....

Former Member
0 Kudos

Hi Experts,

In itab1 table there are following entries.

Vbeln posnr

360 1

360 2

360 3

361 1

361 2

362 1

362 2

363 1.

In itab2 table there are following entries.

Vbeln

360

362

I want to compare both itab and delete all vbeln from itab1 which are not in itab2.

How to write ? Guide me.

Yusuf

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,yusuf.

This is my answer,I tested it,it works.

LOOP AT TAB_TABLE1 INTO WA_TABLE1.

READ TABLE TAB_TABLE2 WITH KEY VBELN = WA_TABLE1-VBELN INTO WA_TABLE2.

IF SY-SUBRC <> 0.

DELETE TABLE TAB_TABLE1 FROM WA_TABLE1.

ENDIF.

ENDLOOP.

Regards,

feng.

11 REPLIES 11

Former Member
0 Kudos

Hi

Try like this

delete itab1 where itab1- field-name1 = itab2-field-name.

Regards

Pavan

former_member386202
Active Contributor
0 Kudos

Hi,

use loop on itab1 and read table itab2 using read statements,

and check sy-subrc if it is not zero then delete the record from itab1.

regards,

Prashant

0 Kudos

Hi Yusuf,

Gowri

0 Kudos

Hi Prashant,

No, it is not working.

Yusuf

aris_hidalgo
Contributor
0 Kudos

Hi,

loop at itab1.

read table itab2 into wa_itab2 with key vbeln = itab1-vbeln.

if sy-subrc <> 0.

delete itab1.

continue.

endif.

endloop.

Hope it helps...

P.S. Please award points if it helps...

Former Member
0 Kudos

try this,

loop at itab1 into w_itab1.

read table itab2 into w_itab2 with key vbeln = w_itab1-vbeln.

if sy-subrc <> 0.

delete itab1.

endif.

endloop.

rewards if useful

kavitha

Former Member
0 Kudos

hi yusuf,

hope this helps u.

loop at itab.

read table itab1 into wa with key vbeln = itab-vbeln.

if sy-subrc <> 0.

delete itab.

continue.

endif.

endloop.

regards,

sohi

aris_hidalgo
Contributor
0 Kudos

Or you can do it like this:

loop at itab2.

wa_vbeln-sign = 'I'.

wa_vbeln-option = 'EQ'.

move itab2-vbeln to wa_vbeln-low.

append wa_vbeln to gr_vbeln.

endloop.

if not gr_vbeln[] is initial.

delete itab1 where vbeln not in gr_vbeln.

endif.

Just declare a range table to hold the VBELN in itab2.

Hope it helps...

P.S. Please award points if it helps...

Former Member
0 Kudos

DATA : ITAB3 LIKE STANDARD TABLE OF ITAB1 WITH HEADER LINE.

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY VBELN = ITAB1-VBELN.

IF SY_SUBRC NE 0.

MOVE-CORRESPONDING ITAB1 to ITAB3.

APPEND ITAB3.

ENDIF.

ENDLOOP.

ITAB3 IS REQUIRED TABLE.

REWARD IF USEFUL.

AMIT SINGLA

Former Member
0 Kudos

Hi,yusuf.

This is my answer,I tested it,it works.

LOOP AT TAB_TABLE1 INTO WA_TABLE1.

READ TABLE TAB_TABLE2 WITH KEY VBELN = WA_TABLE1-VBELN INTO WA_TABLE2.

IF SY-SUBRC <> 0.

DELETE TABLE TAB_TABLE1 FROM WA_TABLE1.

ENDIF.

ENDLOOP.

Regards,

feng.

0 Kudos

Hi Feng,

Ya... It works.

Thanks, Rewarded Full.

Yusuf