04-11-2006 8:37 AM
Hello experts,
I have 2 internal tables, it_ekpo and it_mseg2. now, what I want to do is delete records from itab it_ekpo that doesn't exist in itab it_mseg2. Bewlo is the code that I made. Please let me know if it's wrong or if it can be done in a better way. Thank you guys and take care!
LOOP AT it_ekpo.
READ TABLE it_mseg2 WITH KEY ebeln = it_ekpo-ebeln.
IF sy-subrc <> 0.
DELETE it_ekpo.
CLEAR it_ekpo.
ENDIF.
ENDLOOP.
04-11-2006 8:43 AM
just make one more internal table it_ekpo1
of same type it_ekpo.
sort it_mseg2.
LOOP AT it_ekpo.
READ TABLE it_mseg2 binary search WITH KEY ebeln = it_ekpo-ebeln.
IF sy-subrc = 0.
it_ekpo1 = it_ekpo.
append it_ekpo1.
clear it_ekpo1.
ENDIF.
ENDLOOP.
04-11-2006 8:39 AM
Hello,
Try like this...
LOOP AT it_ekpo.
READ TABLE it_mseg2 WITH KEY ebeln = it_ekpo-ebeln.
IF sy-subrc <> 0.
DELETE it_ekpo.
<b>continue.</b>
ENDIF.
ENDLOOP.
Regards,
Naimesh
Reward points, if it is useful
04-11-2006 8:42 AM
You should use Binary Search to speed up the read statement. Also if we are trying to remove the amount of lines of code being executed then you should use: -
LOOP AT it_ekpo.
READ TABLE it_mseg2 WITH KEY ebeln = it_ekpo-ebeln
BINARY SEARCH
CHECK sy-subrc <> 0.
DELETE it_ekpo.
ENDLOOP.
Make sure the table it_mseg2 is sorted to enable the binary search to work.
Thanks
Martin
04-11-2006 8:41 AM
Hi,
I think what you have done is right. Just a small change.
DELETE it_ekpo index sy-tabix.
Regards,
Ravi
Note : Please mark the helpful answers
04-11-2006 8:41 AM
hi viray,
i think it would be better if u wud write as
DELETE it_ekpo index sy-tabix.
or
DELETE it_ekpo where ebeln = it_ekpo-ebeln.
hope this helps,
priya.
04-11-2006 8:43 AM
just make one more internal table it_ekpo1
of same type it_ekpo.
sort it_mseg2.
LOOP AT it_ekpo.
READ TABLE it_mseg2 binary search WITH KEY ebeln = it_ekpo-ebeln.
IF sy-subrc = 0.
it_ekpo1 = it_ekpo.
append it_ekpo1.
clear it_ekpo1.
ENDIF.
ENDLOOP.