2008 May 14 5:45 AM
Hi All,
I have used a SELECT SUM(field) ... inside a loop.
The table in use is BSID.
Will it hamper the performance or is it OK ?
Regards,
Ashish
2008 May 14 5:48 AM
hi,
Never use select statement inside a loop endloop .... try filtering the data outside it ...
Hi All,
I have used a SELECT SUM(field) ... inside a loop.
The table in use is BSID.
Will it hamper the performance or is it OK ?
Regards,
Ashish
2008 May 14 5:47 AM
Always try and avoid doing SELECTS within loops, this will definetly have a (major) impact on performance.
2008 May 14 5:48 AM
hi,
Never use select statement inside a loop endloop .... try filtering the data outside it ...
2008 May 14 5:52 AM
But how will SELECT SUM() make a difference ?
I am not selecting any records .... just a single SUM() of some records based on condition.
Regards,
Ashish
2008 May 14 5:55 AM
the select will still have to go through the (entire) data base records the sum the data.
2008 May 14 5:56 AM
so what is the solution option to NOT using SELECT SUM() inside loop ?
2008 May 14 6:33 AM
First you will have to select all the necessary data from this table (which is a very BIG table normally), according to the data in your internal table used for LOOPing.
Select * (or some fields only) from BSID into itab
for all entries in itab
where ..... =
and......... =
2008 May 14 6:33 AM
Hi Ashish,
Of course, you can use select sum() in a loop run. But it's causing huge performance problems. Therefore don't use it! Also don't use any select .... in a loop run.
I recommend to take a look at all of your select statements!
Good luck,
Heinz
2008 May 14 8:00 AM
I am wondering, why nobody tells you how to avoid it. Maybe, because there is no alternative?
To move selects out of a loop you usually use FOR ALL ENTRIES. However, FAE can not be used with aggregate functions!
And it is definitely not recommended to read all data and do the summation by yourself, if an aggregate function could do the same.
Your question would be easier to understand, if you add a bit of coding. I assume the following
loop itab into wa
select sum(field1)
into
from db-tab
where key1 = wa-key1.
endloop
key1 is not the full key of the db-table so there some or even many record for which the field1 is summed up.
Siegfried
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |