09-30-2009 10:30 AM
Please use a meaningful subject in future
Hi friends,
Im having a piece of code as mentioned below,DETAIL table has 1 lak records and IT_MSEG has 20,000 records.
This is taking time and going to dump.please help
SORT IT_MSEG BY BELNR MATNR.
sort detail by belnr matnr.
LOOP AT DETAIL.
READ TABLE IT_MSEG WITH KEY BELNR = DETAIL-BELNR MATNR = DETAIL-MATNR
binary search.
IF SY-SUBRC NE 0.
DELETE DETAIL WHERE BELNR = DETAIL-BELNR AND MATNR = DETAIL-MATNR.
ENDIF.
CLEAR:DETAIL,IT_MSEG.
ENDLOOP.
Please help
Edited by: Neliea on Sep 30, 2009 11:55 AM
Edited by: Matt on Sep 30, 2009 2:20 PM
09-30-2009 11:07 AM
Hi,
the DELETE WHERE on table DETAIL can not be optimized in case it is a standard table.
The SORT for table DETAIL is therefore not necessary.
The DELETE WHERE can only be optimized if you use a SORTED TABLE for DETAIL.
But since you delete the record which currently processed by the loop you can
simply use
delete detail (which deletes the current line without doing a search).
Kind regards,
Hermann
09-30-2009 11:11 AM
Hi,
For better performance, Do Not Delete the entries inside the LOOP-ENDLOOP...
Redundant Sort on DETAIL table...
try this:
SORT IT_MSEG BY BELNR MATNR.
LOOP AT DETAIL into WA_DETAIL.
READ TABLE IT_MSEG WITH KEY BELNR = WA_DETAIL-BELNR MATNR = WA_DETAIL-MATNR
binary search.
IF SY-SUBRC EQ 0. " Move into a local internal table
WA_TEMP = WA_DETAIL
Append WA_TEMP to LT_TEMP.
ENDIF.
ENDLOOP.
If Required...Now Refresh the table IT_MSEG and Fill the data from LT_TEMP.
Refresh IT_MSEG
IT_MSEG = LT_TEMP.
Hope this helps
Regards
Shiva
Edited by: Shiva Kumar Tirumalasetty on Sep 30, 2009 3:41 PM
09-30-2009 11:20 AM
Hi,
What you are trying to do is deleting all entries in detail which have the an entry in IT_MSEG for the combination of belnr and matnr so why dont you try like below:
loop at it_mkpf.
delete detail where belnr = it_mkpf and matnr = it_mkpf-matnr.
endloop.
Regards,
Himanshu
09-30-2009 1:21 PM
Please use a meaningful subject in future
09-30-2009 2:01 PM
Take off the WHERE condition on the DELETE. You don't need it and this is what is slowing you down.
Rob
10-01-2009 10:40 PM
Hi Nelia,
Try this code:
FIELD-SYMBOLS <fs_detail> LIKE LINE OF DETAIL.
SORT IT_MSEG BY BELNR MATNR.
LOOP AT DETAIL ASSIGNING <fs_detail>.
lv_index = sy-tabix.
READ TABLE IT_MSEG WITH KEY BELNR = <fs_detail>-BELNR
MATNR = <fs_detail>-MATNR
BINARY SEARCH
TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
DELETE DETAIL INDEX lv_index.
ENDIF.
ENDLOOP.
- it's necessary only sort IT_MSEG (already mentioned)
- delete direct by index (already mentioned)
- field-symbols isn't mandatory I use it to avoid copy to header-line, minor speed up
- transporting no fields is used for the same reason
Regards, Fernando Da Ró
10-02-2009 3:07 PM
Try using the following logic.
TYPES: BEGIN OF ty_mseg,
...
belnr TYPE mseg-belnr,
...
matnr TYPE mseg-matnr,
...
END OF ty_mseg,
BEGIN OF ty_detail,
...
belnr TYPE mseg-belnr,
...
matnr TYPE mseg-matnr,
...
del(1) TYPE c ,
END OF ty_detail.
DATA: w_detail TYPE ty_detail,
w_index TYPE sy-tabix ,
it_mseg TYPE SORTED TABLE OF ty_mseg
WITH NON-UNIQUE KEY belnr matnr,
it_mseg_tmp TYPE TABLE OF ty_mseg ,
it_detail TYPE TABLE OF ty_detail.
it_mseg_tmp[] = it_mseg[].
DELETE ADJACENT DUPLICATES FROM it_mseg COMPARING belnr matnr.
LOOP AT it_detail INTO w_detail.
w_index = sy-tabix.
READ TABLE it_mseg WITH KEY belnr = w_detail-belnr
matnr = w_detail-matnr
TRANSPORTING NO FIELDS.
CHECK sy-subrc NE 0.
w_detail-del = 'X'.
MODIFY it_detail FROM w_detail
INDEX w_index
TRANSPORTING
del.
ENDLOOP.
DELETE it_detail WHERE del EQ 'X'.
it_mseg[] = it_mseg_tmp[].
10-05-2009 7:32 AM
make IT_MSEG a sorted table
FIELD-SYMBOLS <fs_detail> LIKE LINE OF DETAIL.
LOOP AT DETAIL ASSIGNING <fs_detail>.
lv_index = sy-tabix.
READ TABLE IT_MSEG WITH TABLE KEY BELNR = <fs_detail>-BELNR
MATNR = <fs_detail>-MATNR
BINARY SEARCH
TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
<fs_detail>-delflg = 'X'.
ENDIF.
ENDLOOP.
delete detail where delflg = 'X'.
does detail has multiple entries for it_mseg if so you better loop it_mseg and read detail
.
Thanks
Nafran
10-05-2009 12:10 PM
Hello Neliea,
You are applying loop on internal table and same line you are deleating for which loop is running.Its a wrong procedure you have to take all that records in your new internal table and then you have to delete from your master internal table.
Hope this will help you.
Regards,
Shrikant.
10-06-2009 11:05 PM
Try this....
SORT IT_MSEG BY BELNR MATNR.
sort detail by belnr matnr.
LOOP AT DETAIL.
READ TABLE IT_MSEG WITH KEY BELNR = DETAIL-BELNR MATNR = DETAIL-MATNR
binary search.
IF SY-SUBRC NE 0.
DELETE DETAIL . The conditions will not be required as the cussor will remain at the same place.
ENDIF.
CLEAR:DETAIL,IT_MSEG.
ENDLOOP.
Let me now the results.
Thanks,
Prithwi
10-07-2009 7:56 AM