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

Select Single within Loop

Former Member
0 Likes
456

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
Read only

Former Member
0 Likes
427

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
427

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