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 from itab if it doesn't exists in dbtable

0 Kudos
183

Hi , I want to delete ''if (itab-belnr ne bseg-BELNR)''

if it exists in my itab but doesn't exists in dbtable(bseg) delete from itab.

4 REPLIES 4

matt
Active Contributor
95

That's nice. But what, exactly, is your problem? What have you tried?

0 Kudos
95

I couldn't anything. Should I nested loops ? but that wouldn't be efficient.

touzik_itc
Active Participant
0 Kudos
95

By small internal tables, you can try something like this:

TYPES: BEGIN OF t_data,
         belnr LIKE bseg-belnr,
       END OF t_data,
       tt_data TYPE TABLE OF t_data WITH EMPTY KEY.
DATA(lt_data) = VALUE tt_data( ( belnr = '1' ) ( belnr = '2' ) ( belnr = '3' ) ).

TYPES tt_range TYPE RANGE OF bseg-belnr.
DATA(lt_range_db) = VALUE tt_range( FOR <wa> IN lt_data ( sign = 'I' option = 'EQ' low = <wa>-belnr ) ).
DATA(lt_range_itab) = VALUE tt_range( ).

SELECT 'I' AS sign, 'EQ' AS option, belnr AS low FROM bseg
  INTO TABLE @lt_range_itab WHERE belnr IN @lt_range_db.

IF sy-subrc = 0 .
  DELETE lt_data WHERE belnr NOT IN lt_range_itab.
ELSE.
  CLEAR lt_data.
ENDIF.

sathyags
Active Participant
0 Kudos
95

Select BELNR from BSEG for all entries in your itab to poulate a range table.

Then, delete itab where BELNR not in Range table.