Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

performance issue

Former Member
0 Likes
1,015

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
990

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

9 REPLIES 9
Read only

Former Member
0 Likes
990

Yes. It will result poor performance.

YOu should instead use for all entries.

Read only

Former Member
0 Likes
990

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á

Read only

Former Member
0 Likes
990

It cause performance issue. Better to avoid select & endselect, and also select with in a loop.

Read only

Former Member
0 Likes
990

we should avoid select in loop, in case if you have to use, use for all entries.

Read only

Former Member
0 Likes
990

Hi

Avoid:

select-endselect inside LOOP.

aggregate functions in select statement.

regards,

madhu

Read only

Former Member
0 Likes
990

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

Read only

Former Member
0 Likes
990

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

Read only

Former Member
0 Likes
991

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

Read only

Former Member
0 Likes
990

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.