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

Former Member
0 Likes
1,151

Can we use Select single inside the loop..? will it cause any performance issue....?

Regards,

Murugan Arumugam

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,112

try to avoid select statement inside loop it will decrease the performance

10 REPLIES 10
Read only

Former Member
0 Likes
1,113

try to avoid select statement inside loop it will decrease the performance

Read only

Former Member
0 Likes
1,112

HI,

yaa u can.

but u can select only one row using this.

this is good compared to select * in performance wise.

rgds,

bharat.

Read only

Former Member
0 Likes
1,112

You Can.

Are you using it for validation or reading data. If so then you may wish to use the

AT NEW command

So that you only do the read each time the where condition would change.

Read only

Former Member
0 Likes
1,112

Hi,

Why u use select single in loop statement better write your query befor loop statement and then use read statement for use this data according to key field.

Rewards points if it is useful.

Read only

Former Member
0 Likes
1,112

Hi,

there is no issues using like that.In select single u only have to take care whether the conditions used to fetch includes all primary key fields.

Read only

Former Member
0 Likes
1,112

Hello,

<b>Select statement inside a loop</b> is not a good programming practice. It will make some <b>performance issues</b>. Instead of this u can select the record in to one<b> internal table</b> fist and u can use the <b>read table</b> command inside the loop statement. That is better.

Reward if helpful,

Regards,

LIJO JOHN

Read only

Former Member
0 Likes
1,112

Hi Murugan,

As far as performance is concerned Select single is not advisable. Better would be, you retreive the data outside the loop into a internal table and then use READ statement. But if the amount of data is less then you can go for SELECT SINGLE also. It will serve your purpose.

It is a subjective matter and depends on the amount of data you are handling.

Rewards points if helpful

regards

Sourabh Verma

Read only

Former Member
0 Likes
1,112

Hi,

Avoid select statement using inside loop

it will decrease the performance.

Read only

Former Member
0 Likes
1,112

Hi murugan,

The <i><b>Best answer</b></i> i could get 4 u is this....

if you are 100% sure , you can't code a database join, then :

Theoretically , the "for all entries" clause has an advantage over a loop of select singel by primary key. This is becuase the abap interpreter can group together several rows in the itab into one select (see note <b>48230</b>) so it could get the requested result using less conversations with the database.

The down side is that by doing so, the where predicates will not be a simple equation predicates, they may become "in" predicates and so on (see note <b>48230</b>). This change in the sql may lead to a more costly access path.

So, unfortunatly, you will probably be forced to write and test both options and see which costs less.

  • by costs i mean total getpages or "in db2 time" for the whole workload, and not transaction elapsed time.)

    • as a rule of thumb I would lean to select single by primary key, over "for all entries" ... but as i said, its depends on several factors....

Above article is taken from...

<i><b>http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912</b></i>

Refer that too...

Hope it helps!!!

<i><b>*Reward useful answers*</b></i>

Regards,

<b>Naveenan</b>

Read only

Former Member
0 Likes
1,112

Thanks a lot