2012 Oct 19 7:39 AM
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
2012 Oct 19 8:55 AM
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
2012 Oct 19 8:58 AM
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...
2012 Oct 19 9:50 AM