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: 

Delete entries not in a Table

Former Member
0 Kudos

Hi,

I have 2 tables :

WT_TABLE1

INTRENO | OBJNR

0001 | IS001

0002 | IS002

0003 | IS003

0004 | IS004

0005 | IS001

WT_TABLE2

0001 | IS001

0003 | IS003

I want detele entries in WT_TABLE1 who is not in table WT_TABLE2.

I have a code that work but i need to know if they are instruction with better performance?

LOOP AT WT_TABLE1 into WS_TABLE1

READ TABLE WT_TABLE2 INTO WS_TABLE2

WITH KEY OBJNR = WS_TABLE1-OBJNR.

if sy-subrc <> '0'.

delete wt_contrat.

endif.

ENDLOOP.

Thank you for your reply.

Spawntae

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

This will work fine w/t performance issue.

Regards,

Dhan

4 REPLIES 4

Former Member
0 Kudos

Hi,

This will work fine w/t performance issue.

Regards,

Dhan

0 Kudos

thank you for your reply.

Rewards

Former Member
0 Kudos

Hi It wont affect but change the code as below :-

clear : ws_table1,

ws_table2.

Sort wt_table1 by intreno objnr.

LOOP AT wt_table1 INTO ws_table1.

READ TABLE wt_table2 INTO ws_table2

WITH KEY intreno = ws_table1-intreno

objnr = ws_table1-objnr.

IF sy-subrc NE 0.

DELETE table wt_table1 from ws_table1.

ENDIF.

ENDLOOP.

former_member194613
Active Contributor
0 Kudos

... here everything is wrong, question and answers!


if sy-subrc '0'.
delete wt_contrat.
endif.

???? 2 big bugs !!!, there is wt_contract ! and what is between subrc and 0 ????


* table 2 must be sorted not 1 !!!!
SORT wt_table2 BY objnr.
LOOP AT WT_TABLE1 INTO wa1.
  tabix1 = sy-tabix.

  READ TABLE WT_TABLE2 
            TRANSPORTING NO FIELDS
             WITH KEY OBJNR = wa1-OBJNR
            BINARY SEARCH.

  IF sy-subrc <> 0.
    DELETE wt_table1 INDEX tabix1.
  ENDIF.
ENDLOOP.

ENDLOOP.