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 comparing 2 internal tables

Former Member
0 Kudos
8,053

Hi,

Is there any one line syntax to delete entries from an internal table comparing the fields of another internal table.

Regards

mac

7 REPLIES 7

former_member205763
Active Contributor
0 Kudos
1,270

I dont think you can achieve it using any one line syntax.

u need to use this

DELETE itab [WHERE log_exp].

Use this statement inside another loop with which u want to compare the table whose lines need to be deleted.

кu03B1ятu03B9к

Edited by: Kartik Tarla on Sep 30, 2009 8:19 PM

Former Member
0 Kudos
1,270

Hi

U need to insert the table to be deleted in a loop of main table:

LOOP AT ITAB1.
   DELETE ITAB2 WHERE FIELD = ITAB1-FIELD.
ENDLOOP.

Max

Former Member
0 Kudos
1,270

Solved myself

0 Kudos
1,270

can you please tell me how did you solve it.

Amit91
Participant
0 Kudos
1,270

Hi,

You want to delete all records from it_tab_child which are present in it_tab_parent i.e. child has 100 records but you want to delete 50 records which are present in parent.

SORT it_tab_child BY key_field.

LOOP AT it_tab_parent ASSIGNING <fs_parent>.

"Warning: it_tab_child cannot have duplicate record on key_field!!!

READ TABLE it_tab_child ASSIGNING <fs_child> WHERE key_field = <fs_parent>-key_field

                                                                                                            BINARY SEARCH.

IF sy-subrc EQ 0.

<fs_child>-key_field = space.

ENDLOOP.

DELETE it_tab_child WHERE key_field = space.

***This code has ~40% more efficient than deleting records inside the loop.

matt
Active Contributor
0 Kudos
1,270

Make it_tab_child a HASHED table with a unique key, and it'll be even faster.

SORT/READ/BINARY SEARCH is so last millennium.

kathylau007
Discoverer
0 Kudos
1,270

IF lt_tab1[] IS NOT INITIAL.

DATA(lr_vbeln) = VALUE psi_we_selopt_tt( FOR ls_tab1 IN lt_tab1
( sign = 'I'
option = 'EQ'
low = ls_tab1-vbeln ) ).

DELETE lt_tab2 WHERE vbeln in lr_vbeln.

ENDIF.