03-23-2007 9:13 AM
If i want to delete all entries in one internal tables for which entries are not there in another internal table based on one field, how to do it.
03-23-2007 9:15 AM
Hi,
Please check the code below:
LOOP AT gt_itab1 INTO gs_itab1.
READ TABLE gt_itab2 INTO gs_itab2 WITH TABLE KEY mandt = gs_itab1-mandt
lifnr = gs_itab1-lifnr
vbeln = gs_itab1-vbeln
posnr = gs_itab1-posnr
augru = gs_itab1-augru
cdate = gs_itab1-cdate
kunnr = gs_itab1-kunnr
kunwe = gs_itab1-kunwe
bstkd = gs_itab1-bstkd
docid = gs_itab1-docid
ean11 = gs_itab1-ean11
part_debit = gs_itab1-part_debit
errcode = gs_itab1-errcode.
IF sy-subrc EQ gc_zero_num.
MOVE-CORRESPONDING gs_itab2 TO gs_error1.
gs_error1-message = text-036.
APPEND gs_error1 TO gt_error1.
CLEAR gs_error1.
DELETE TABLE gt_itab2 FROM gs_itab2.
ENDIF.
ENDLOOP.
Regards
Kannaiah
03-23-2007 9:17 AM
loop at itab1.
delete table itab2 where field1 ne itab1-field1.
endloop.
03-23-2007 9:17 AM
Hi,
Say two int tables ITAB1 and ITAB2.
Both have some common fields.
Loop at ITAB1`.
read table itab2 with key f1 = itab1-f1.
if sy-subrc <> 0.
delete itab1 index sy-tabix.
endif.
endloop.
deletes all the enteries in ITAB1 which are not present as that of ITAB2,
reward if useful
regards,
Anji
03-23-2007 9:18 AM
Hi Nikhil,
Considering performance also u can do this:
Sort the table to be deleted by the field on which you are performing the check.
Sort the table to be checked by the field on which you are performing the check.
Then
LOOP AT <itab_delete>.
READ TABLE <itab_check_against> WITH KEY <check_field> = <itab_delete>-<check_field> TRANSPORTING NO FIELDS.
IF SY-SUBRC <> 0.
DELETE <itab_delete> WHERE <check_field> = <itab_delete>-<check_field>.
ENDIF.
ENDLOOP.
If the <check_field> is the first field in <itab_delete> table then u can also perform the logic within the loop in a AT NEW <check_field> .... ENDAT event to improve performance (reduce number of redundant loops).
Hope this helps.
Regards,
Aditya
03-23-2007 9:26 AM
dont u think delete inside a loop is a performance issue. is there any other method
03-23-2007 9:33 AM
Hi,
Here is an example:
just loop through your first itab then check itab2 whether it has same entries in itab1 if not then delete.
Hope this helps...
P.S. Please award points for useful answers...
Message was edited by:
viraylab
03-23-2007 9:38 AM
Hi ,
If two table itab1 and itab2 to be considered
Read Table itab2 with key itab2-field1 = itab1-field1 and itab2-field2 = itab1-field2 .
If sy-subrc EQ 0 ,
DELETE itab2 where condition..... .
Endif .
Thanks ..
03-23-2007 10:09 AM
hi dear,
you have to delete the records of one internal table ,u hav to use the FOR ALL ENTERIES of one internal table to other for the specified key.
this will give u the robust solution.
loop at internal table 1.
delete the record for all enteries for internal table 2 with the specified key.
modify internal table one
reward points if useful
regards
Amit Singla
07-29-2020 11:30 AM
Hi,
Deleting within loop may cause performance issue. instead you can use field-symbols.
Itab1 - from which you want to delete
itab2 - check table.
field1 - comparing field
use below code:
FIELD-SYMBOLS: <lfs_itab1> like itab1.
LOOP AT itab1 ASSIGNING <lfs-itab1>.
READ TABLE itab2 INTO wa_itab2 WITH KEY field1= <lfs_itab1>-field1.
IF sy-subrc NE 0.
CLEAR: <lfs_itab1>-field1.
ENDIF.
CLEAR: wa_itab2.
ENDLOOP.
DELETE itab1 WHERE field1 IS INITIAL.