‎2007 Nov 20 5:34 AM
‎2007 Nov 20 5:39 AM
hi
see example
To restrict the database access, you can select the records from mara for the common conditions and the read/ loop according to the specific conditions.
Ex:
suppose :
select * from mara into lt1_mara where matnr in s_matnr.
loop lt1_mara.
.....
endloop.
.......
.......
select * from mara where meins in s_meins.
loop lt2_mara.
.....
endloop.
......
select * from mara where matkl in s_matkl.
loop lt3_mara.
.....
endloop.
.......
instead of the above you can use:
select * from mara into lt_mara where matnr in s_matnr
or meins in s_meins
or matkl in s_matkl.
loop at lt_mara where matnr in s_matnr.
......
endloop.
.....
.....
loop at lt_mara where meins in s_meins.
......
endloop.
.....
.....
loop at lt_mara where matkl in s_matkl.
......
endloop.
...............
....................
the above will misimise your database access.
‎2007 Nov 20 5:57 AM
hi santanu,
Most common performance problem that occurs in ABAP programs are because of huge number of records in the internal tables. The problem complexifies if program has huge nested internal tables. How much ever efficient data selects routines are, data processing routines would be contibuting significantly for the bad performance. The root cause for the same when analysed would be revealed that, the where condition that are used in inner loops expend significant amount of processing time. The idea is avoid where conditions in the inner loops by maintaining the loop indexes manually.
<b>Conventional Method Code for nested loops</b>
loop at lt_vbpa into wa_vbpa.
loop at lt_kna1 into wa_kna1 where kunnr = wa_vbpa-kunnr.
Your Actual logic within inner loop ******
endloop.
endloop.
<b>Preferred Method Parallel Cursor method </b>
sort: lt_vbpa by vbeln, "Sorting by key is very important
lt_kna1 by kunnr. "Same key which is used for where condition is used here
loop at lt_vbpa into wa_vbpa.
read lt_kna1 into wa_kna1 " This sets the sy-tabix
with key kunnr = wa_vbpa-kunnr
binary search.
if sy-subrc = 0. "Does not enter the inner loop
v_kna1_index = sy-tabix.
loop at lt_kna1 into wa_kna1 from v_kna1_index. "Avoiding Where clause
if wa_kna1-kunnr <> wa_vbpa-kunnr. "This checks whether to exit out of loop
exit.
endif.
Your Actual logic within inner loop ******
endloop. "KNA1 Loop
endif.
endloop. " VBPA Loop
‎2009 Jun 15 12:13 PM