‎2008 Apr 24 10:23 AM
Hi all
i want to increase performance in one Existing program..this program is working fine but performance is very poor. we r indexing the required filed.
but i find some nested select loop inside this program...
pls ,,suggest me how can i avoid this kind of nested select loop. instead of loop statement can i user read statement for avoiding the nested loop???
pls check the below code.
if any problem within this logice then change the code.
thanks in advance.
Indu
SORT it_but000 BY partner.
LOOP AT it_ever INTO wa_ever.
LOOP AT it_fkkvkp INTO wa_fkkvkp WHERE vkont = wa_ever-vkonto.
READ TABLE it_but000 INTO wa_but000 WITH KEY partner = wa_fkkvkp-gpart
BINARY SEARCH.
IF sy-subrc = 0.
IF wa_but000-name_org1 IS INITIAL.
CONCATENATE wa_but000-name_first
wa_but000-name_last
INTO wa_final-cust_name SEPARATED BY space.
CONDENSE wa_final-cust_name.
ELSE.
wa_final-cust_name = wa_but000-name_org1.
ENDIF.
wa_final-gpart = wa_fkkvkp-gpart.
MODIFY it_final FROM wa_final TRANSPORTING cust_name gpart WHERE vertrag = wa_ever-vertrag.
ENDIF.
ENDLOOP.
ENDLOOP.
*****************************************************************
LOOP AT it_isu_data.
LOOP AT it_iflot WHERE tplnr = it_isu_data-tplnr.
wa_final-s_o_code = it_iflot-zwst_wtr.
MODIFY it_final FROM wa_final TRANSPORTING s_o_code
WHERE vertrag = it_isu_data-vertrag.
CLEAR wa_final-s_o_code.
ENDLOOP.
******************************************************************
LOOP AT it_final INTO wa_final.
LOOP AT it_erch WHERE vertrag = wa_final-vertrag.
IF it_erch-vertrag = wa_final-vertrag.
SELECT SINGLE tariftyp
branche
FROM eanlh
INTO (l_tariftyp, l_branche)
WHERE ab <= it_erch-erdat AND bis > it_erch-erdat
AND anlage = wa_final-anlage.
IF sy-subrc = 0.
wa_final-t_type = l_tariftyp.
IF l_tariftyp IS NOT INITIAL.
SELECT SINGLE ttypbez
FROM ettat
INTO l_ttypbez
WHERE spras = sy-langu
AND tariftyp = l_tariftyp.
wa_final-c_description = l_ttypbez.
ENDIF.
MODIFY it_final FROM wa_final TRANSPORTING c_description t_type. "sic_code
ENDIF.
CLEAR it_erch.
ENDLOOP.
CLEAR: wa_final, l_tariftyp, l_ttypbez, l_branche.
ENDLOOP.
***********************************************************
DATA : it_egerh TYPE STANDARD TABLE OF ty_egerh,
wa_egerh TYPE ty_egerh.
LOOP AT it_final INTO wa_final.
LOOP AT it_erch WHERE vertrag = wa_final-vertrag.
wa_comb-equnr = wa_final-equnr.
wa_comb-erdat = it_erch-erdat.
APPEND wa_comb TO it_comb.
CLEAR wa_comb.
CLEAR it_erch.
ENDLOOP.
CLEAR wa_final.
ENDLOOP.
*************************************************************
IF it_final[] IS NOT INITIAL.
SELECT anlage
logikzw
bis
preiskla
FROM easts
INTO TABLE it_easts
FOR ALL ENTRIES IN it_final
WHERE anlage = it_final-anlage.
IF sy-subrc = 0.
LOOP AT it_final INTO wa_final.
LOOP AT it_easts INTO wa_easts WHERE anlage = wa_final-anlage.
wa_final-m_size = wa_easts-preiskla.
MODIFY it_final FROM wa_final TRANSPORTING m_size WHERE anlage = wa_final-anlage.
ENDLOOP.
ENDLOOP.
‎2008 Apr 24 10:26 AM
Hi Indu,
if u got Nested Loops then use PARALLEL CURSOR METHOD .
The performance will be very good.
Nested Loops This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.
Program using Normal Nested Loop:
REPORT ZNORMAL_NESTEDLOOP.
TABLES:
likp,
lips.
Data:
t_likp type table of likp,
t_lips type TABLE OF lips.
data:
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I.
START-OF-SELECTION.
select *
from likp
into table t_likp.
select *
from lips
into table t_lips.
get RUN TIME FIELD w_runtime1.
loop at t_likp into likp.
loop at t_lips into lips where vbeln eq likp-vbeln.
endloop.
endloop.
get RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
write w_runtime2.Nested Loop using Parallel Cursor:
REPORT zparallel_cursor2.
TABLES:
likp,
lips.
DATA:
t_likp TYPE TABLE OF likp,
t_lips TYPE TABLE OF lips.
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
INTO TABLE t_lips.
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.
LOOP AT t_likp INTO likp.
LOOP AT t_lips INTO lips FROM w_index.
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
WRITE w_runtime2.Analysis report: Runtime in microseconds:
Iteration No ...... Normal Nested Loop ..... Using Parallel Cursor
1...................... 34,796,147 .........................63,829
2 ..................... 38,534,583 ......................... 56,894
3 ..................... 34,103,426 ......................... 50,510
Please check this link
http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm
reward if helpful
raam.
‎2008 Apr 24 10:44 AM
Hi Indu..
You have given code is half way ...how do I know which internal table is which and how I wil know whcih is Header table and which is Item table..
Plz do loop Item table and Read header table that could be first to be resolved...
regards
sg