‎2007 Mar 29 11:56 AM
hi,
Iam using select endselect within a loop . will that cause an performance issue?
loop at vbap.
SELECT SUM( omeng ) INTO t_select-open_ord_qty FROM vbbe
WHERE vbeln EQ t_vbap-vbeln
AND posnr EQ t_vbap-posnr
GROUP BY vbeln posnr.
ENDSELECT.
APPEND t_select.
endloop.
‎2007 Mar 29 4:47 PM
Hi Neha,
I think the below code will meet the required functionality.
i_select is type sorted table with key vbeln posnr.
if not vbap is initial.
SELECT vbeln posnr omeng FROM vbbe INTO table i_select
FOR ALL ENTRIES IN vbap
WHERE vbeln EQ vbap-vbeln
AND posnr EQ vbap-posnr.
if sy-subrc = 0.
Loop at i_select assigning <fs_select>.
tot_omeng = tot_omeng + <fs_select>-omeng.
at end of posnr.
l_wa_select = <fs_select>.
l_wa_select-omeng = tot_omeng.
append l_wa_select into t_select.
clear: tot_omeng, l_wa_select .
endat.
endloop.
endif.
endif.
Regards
Poorna
‎2007 Mar 29 11:59 AM
Yes. It will result poor performance.
YOu should instead use for all entries.
‎2007 Mar 29 11:59 AM
Hi!
This coding will surely have bad performance.
Try to select data outside of the loop, into a table, with the FOR ALL ENTRIES command, then use an another LOOP inside the other LOOP.
Regards
Tamá
‎2007 Mar 29 12:00 PM
It cause performance issue. Better to avoid select & endselect, and also select with in a loop.
‎2007 Mar 29 12:10 PM
we should avoid select in loop, in case if you have to use, use for all entries.
‎2007 Mar 29 12:45 PM
Hi
Avoid:
select-endselect inside LOOP.
aggregate functions in select statement.
regards,
madhu
‎2007 Mar 29 1:46 PM
Hi Neha,
Using of SELECT...ENDSELECT inside LOOP...ENDLOOP will definitely cause performance issue. It causes you the performance very poor. So, avoid SELECTs inside LOOP..ENDLOOP.
Retrive VBBE data into an interntal table with the vbeln,posnr and omeng fields and use this internal table inside your LOOP..ENDLOOP AT VBAP to meet your requirement.
Thanks,
Vinay
‎2007 Mar 29 3:15 PM
Hi Neha,
There are three things where you are going wrong
1. Using select end-select
2. Using aggregate functions like SUM
3. and doing all this inside a loop
You can do it like this.
if not vbap is initial "This is very important to chk this
select vbeln posnr omeng into i_tab
for all entries in vbbe
where vbeln = vbap-vbeln
and posnr = vbap-posnr.
endif.
now you can sort the table and then loop at it to calculate the sum.
Regards,
Pankaj Sharma
‎2007 Mar 29 4:47 PM
Hi Neha,
I think the below code will meet the required functionality.
i_select is type sorted table with key vbeln posnr.
if not vbap is initial.
SELECT vbeln posnr omeng FROM vbbe INTO table i_select
FOR ALL ENTRIES IN vbap
WHERE vbeln EQ vbap-vbeln
AND posnr EQ vbap-posnr.
if sy-subrc = 0.
Loop at i_select assigning <fs_select>.
tot_omeng = tot_omeng + <fs_select>-omeng.
at end of posnr.
l_wa_select = <fs_select>.
l_wa_select-omeng = tot_omeng.
append l_wa_select into t_select.
clear: tot_omeng, l_wa_select .
endat.
endloop.
endif.
endif.
Regards
Poorna
‎2007 Apr 02 12:13 PM
Hi
Use select statment with forall entries before loop. Inside the loop use READ statment with binary search. Before using binary search need to sort the internal table.