Skip to Content
0
Nov 19, 2012 at 06:01 AM

Performance issue with ANLA / ANLZ selection

501 Views

Dear Experts,

There was a query which was working and taking time and fetching unnecessary data, I have now optimized it and now its fetching exact data required

but it is taking much more time than the older one despite of optimizing it. Please suggest if there are any changes required in the query optimized..

Old Query which was taking time..

{Code}

SELECT ANLN1 into (IT_ASSET-anln1)
from ANLA.
if sy-subrc = 0.
select single CAUFN into it_asset-CAUFN
from anlz
where anln1 = it_asset-anln1
and werks = 'T401'.
append it_asset.
clear it_asset.
endif.
ENDSELECT.


{Code}

New Query which is optimized by me..

{Code}

SELECT bukrs anln1 anln2 FROM anla
INTO TABLE it_anla.

IF it_anla[] IS NOT INITIAL.
SORT it_anla BY anln1.
DELETE ADJACENT DUPLICATES FROM it_anla COMPARING anln1.
SELECT bukrs anln1 anln2 bdatu caufn FROM anlz
INTO TABLE it_anlz FOR ALL ENTRIES IN it_anla
WHERE anln1 = it_anla-anln1
AND werks = 'T401'.
ENDIF.
SORT it_anlz BY anln1.
LOOP AT it_anla ASSIGNING <fs_wa>.
ASSIGN COMPONENT 'ANLN1' OF STRUCTURE <fs_wa> TO <field1>.

READ TABLE it_anlz INTO wa_anlz WITH KEY anln1 = <field1> BINARY SEARCH.
IF sy-subrc = 0.
wa_asset-anln1 = wa_anlz-anln1.
wa_asset-caufn = wa_anlz-caufn.
APPEND wa_asset TO it_asset.
ENDIF.
UNASSIGN: <field1>.
CLEAR: wa_anlz.
ENDLOOP.

{Code}

Regards,

Paavan