Application Development 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: 

Select Single within Loop

Former Member
0 Kudos

Hi,

Is it acceptable to use SELECT SINGLE statement within a LOOP? Or is it very bad for the performace?

Is there any alternative (better way) for this?

I can't use READ because don't have any fields to compare in the WITH KEY section..

Thanks,

Mohit

2 REPLIES 2

Former Member
0 Kudos

Hi

Its very bad for performance as every time it will Read database.

If you dont have any vale to compae that SELECT SINGLE also gives you same value every time otherwise you can use FOR ALL ENTRIES claues.

Regards

Aditya

raymond_giuseppi
Active Contributor
0 Kudos

If you have the keys used in the SELECT in the table looped, use a FOR ALL ENTRIES IN itab, then in the loop use a READ TABLE.

If not, perform a first loop, collect the needed keys in a second itab, at the end of the first loop perform the SELECT FOR ALL ENTRIES, then perform a second loop with the READ TABLE.

LOOP/SELECT SINGLE/ENDLOOP is only advisable if you are sure that only a few records will be read, like in a screen dynpro without ALV or views.

Regards