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 statement in loopu0085.. endloop --> wt happens actually ????

Former Member
0 Likes
1,406

Do you use select statement in loop….. endloop, how will be the performance?

how To improve the performance?

9 REPLIES 9
Read only

Former Member
0 Likes
1,379

every time the loop will start ...u r select query retrive the data from database.....

it will highly decrease the performance ...........in case if data is huge , it may go to dump

reward points if helpful...

Read only

Former Member
0 Likes
1,379

every time the loop will start ...u r select query retrive the data from database.....

it will highly decrease the performance ...........in case if data is huge , it may go to dump

reward points if helpful...

Read only

Former Member
0 Likes
1,379

Hi

suppose that loop executes for 100 times then ur select statement will execute 100 time

where exactly u needed this condition tell me

i will tell you

Read only

Former Member
0 Likes
1,379

Hi Sarit,

The disadvantage of this is that in the loop you have one value and depending on this value you select so you hit the database just for this single value and during the next loop again it fetches one value. So lot of database hits are wasted just for reading one record.

It can be avoided by using for all entries stmt in select query.

ex:

select field1 field2

from table1

into table it_table1

where select-options.

now imagine you want to extract data from table2 depending on table 1 for all entries then use this select query for table2 instead of using loop.

select field1 field2

from table2

into table it_table2

for all entries in it_table1.

This would seriously improve the performance.

Reward Points if useful.

Thanks,

Tej..

Read only

Former Member
0 Likes
1,379

Hi,

NOTE : Don't use Select statement with in loop it causes number of hits on database, so it decrease the performance.

Suppose if interna table contain 1lack records

Now if use select with loop internal table (1 lacks records) then program should hit the database 1 lack times and retrieview data.

At this situation, use the <b>for all entries to select</b> the data corresponding internal table before the loop.

with in loop we can use <b>READ</b> statement to get records form itab.... which <b>increase the performance.</b>

<b>Reward with points if helpful</b>.

Regards,

Vijay

Read only

Former Member
0 Likes
1,379

It's not really the number of database hits that causes the problem, it's the number of trips from the application server to the database server.

For example in a loop that executes a select statement 100 times, SAP goes from you application program to the database 100 times. If you have a table with 100 entries and execute FOR ALL ENTRIES, SAP will probably goe to the database only once to get all your entries and return them to your program. (I say probably because this may be dependent on both your release of R3 and your database system.)

Rob

Read only

Former Member
0 Likes
1,379

Hi Sarit,

Usually we always avoid the use of SELECT in LOOP or even SELECT..ENDSELECT..

Instead we use FOR ALL ENTRIES

The reason is that the Application server, where the ABAP programs are executed, is very very fast as compared to the Database server, which actually fetches the data from the database and return to the application server..

If you use SELECT in a LOOP, for each loop pass the application server will request the database server for data.. and every time, the application server will need to wait.. so, it will become very bad by performance..

Thanks and Best Regards,

Vikas Bittera.

**Reward if useful**

Read only

Former Member
0 Likes
1,379

hi sarit,

The performance would all depend on the number of entries u have in the table....If the entries are less in number, it should not be a major concern, but ifur table has like a lakh records, then try to avoid this.

is ur query solved?

thanks

regards

nayan

Read only

Former Member
0 Likes
1,379

ok