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: 

Performance issue in report in SAP

0 Kudos

SORT it_outputmseg BY mblnr aufnr.

SORT it_msegtemp BY smbln aufnr.

LOOP AT it_outputmseg INTO DATA(wa_outputmseg).
READ TABLE it_msegtemp INTO DATA(wa_msegtemp) WITH KEY smbln = wa_outputmseg-mblnr aufnr = wa_outputmseg-aufnr BINARY SEARCH.
IF sy-subrc = 0.
DELETE it_msegtemp WHERE smbln = wa_outputmseg-mblnr AND aufnr = wa_msegtemp-aufnr. "msegtemp
DELETE it_msegtemp WHERE mblnr = wa_msegtemp-smbln AND aufnr = wa_msegtemp-aufnr. "mblnr_mseg
ENDIF.
CLEAR wa_msegtemp.
ENDLOOP.

Hello everyone this loop is taking so much time to process if data is around 55k. Is there any alternate way to do same.

6 REPLIES 6

FredericGirod
Active Contributor

Why did you do a READ TABLE it_msegtemp ?

Sandra_Rossi
Active Contributor

Your "READ TABLE itab" is fine for performance as you do a binary search.

But your "DELETE itab WHERE" is awful for performance because it does a full lookup.

If you define a sorted key for the internal table, both READ TABLE itab (no need to indicate BINARY SEARCH then, consider that it's almost deprecated anyway) and DELETE itab would use the sorted key if you mention the full key after WITH or WHERE.

I'm not sure what you want to do, depends on your specific context and requirement, but it looks like that you want to delete one line by index (use of SY-TABIX after LOOP AT and READ TABLE, and DELETE ... INDEX ...)

Try to learn more from the ABAP documentation, that will help you a lot.

Although I'm trying hard, I cannot see the logic behind that code snipet (not yours, the OP's one). I'm (almost) sure it works, but the thing is: if someone has troubles seeing the logic, probably it's because the logic is wrong (or because I'm bad at it, it could be because that too).

If you are using BINARY SEARCH, your tables might be SORTED ones, so... why the SORT TABLE prior the LOOP?

You can, also, add both DELETE's in one, by using

WHERE aufn = temp-aufnr AND ( smbln = out-mblnr OR mblnr = temp-smbln ).

But I cannot be sure of it, because my eyes are bleeding and my head aches for the effort of trying to understand your code.

HINT: edit your post, select the code text and press the CODE button, you will save us from some pain.

matt
Active Contributor

Use the CODE button

SORT it_outputmseg BY mblnr aufnr.

SORT it_msegtemp BY smbln aufnr.

LOOP AT it_outputmseg INTO DATA(wa_outputmseg).
  READ TABLE it_msegtemp INTO DATA(wa_msegtemp) WITH KEY smbln = wa_outputmseg-mblnr aufnr = wa_outputmseg-aufnr BINARY SEARCH.
    IF sy-subrc = 0.
      DELETE it_msegtemp WHERE smbln = wa_outputmseg-mblnr AND aufnr = wa_msegtemp-aufnr. "msegtemp
      DELETE it_msegtemp WHERE mblnr = wa_msegtemp-smbln AND aufnr = wa_msegtemp-aufnr. "mblnr_mseg
    ENDIF.
   CLEAR wa_msegtemp.
ENDLOOP.

See how much easier it is to read?

matt
Active Contributor
0 Kudos

If you're using BINARY SEARCH you're using the wrong types of tables. Try rewriting your code using a HASHED table or a SORTED tablr.

Why are so many newbies using ideas that were fine 30 years ago, but are out of date now? Is this a reflection of the training material they're using?

VXLozano
Active Contributor
0 Kudos

Yes, they are. Way back in 2004, when I joined my first ABAP "training", the first sentence I was taught was TABLES. Few days later, when I joined my second one (a long trip in a place called SAPF*ns), I realized that that sentence was at least, deprecated.

I see a lot of people using it DAILY.