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..
SELECT ANLN1 into (IT_ASSET-anln1)
if sy-subrc = 0.
select single CAUFN into it_asset-CAUFN
where anln1 = it_asset-anln1
and werks = 'T401'.
New Query which is optimized by me..
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'.
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.