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 wise which one is better: loop inside select single or select outside loop and reading inside loop

Former Member
0 Likes
645

Hi All,

I am having code like shown below...

loop at it_vbeln.

   SELECT * FROM vbfa  WHERE vbeln = it_vbeln-vbeln.

   SELECT SINGLE * FROM vbkd WHERE vbeln = vbfa-vbelv.

endloop.

whether can i use the select statements outside the loop?

select VBELN

          POSNR

          KDGRP

          PLTYP

from vbfa

into table it_vbfa

for all entries in it_vbeln

where vbeln = it_vbeln-vbeln.

after that...

loop at it_vbeln.

read table it_vbfa into wa_vbaf with key vbeln = it_vbeln-vbeln.

endloop.

Which one is better....inside loop select single is better or use select outside the loop and read the table...

But when i seen the execution time select single inside loop is taking less time as compared with select outside loop and reading inside loop.

Please advise.

Regards

Ram

3 REPLIES 3
Read only

yuri_ziryukin
Product and Topic Expert
Product and Topic Expert
0 Likes
605

Hello Ram,

1) as far as I remember selecting from VBFA with VBELN is bad (no index). There is a good SAP note for this, please study carefully: 185530.

2) Select outside a loop should be better. The other results might be caused by the differences between subsequent executions. Please select outside of loop!

Yuri

Read only

HermannGahm
Product and Topic Expert
Product and Topic Expert
0 Likes
605

additionally make sure it_vbfa is a sorted table (binary search).

in my system there is a delivered non activated index on

MANDT

VBELN

POSNN

vor vbfa (index M01).

check if you need to activate it...

Read only

matt
Active Contributor