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: 

Dump

former_member377111
Participant
0 Kudos

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

11 REPLIES 11

former_member192616
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

matt
Active Contributor
0 Kudos

Please use a meaningful subject in future

Former Member
0 Kudos

Take off the WHERE condition on the DELETE. You don't need it and this is what is slowing you down.

Rob

former_member182114
Active Contributor
0 Kudos

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ó

Former Member
0 Kudos

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[].

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

former_member377111
Participant
0 Kudos

Solved