‎2015 Sep 14 3:43 PM
Hi All,
I came across a strange behavior of select.. endselect query.
want to know the sequence in which this will select data from DB tables?
eg:
select * from vbfa where vbeln = 'XXXXX'
.................
..................
..................
endselect.
there are 5 records that meets the where condition.
that are stored in DB table as 1
2
3
4
5
but its fetching first 5th record then 1-2-3-4.in sequence.
not able to get the sequence logic in selecting these records.
thanks and regards
‎2015 Sep 15 7:50 AM
As soon as you don't use a ORDER BY option, SQL optimizer will usually read data in an unpredictable order, can also be complexified for buffered tables. In most database the assertion "as it is present in XXX table" is false or non-sense. In your example you are not selecting using first primary keys, so optimize may use some other secondary index, or even temporary hash table or buffer created during previous SQL execution.
Hint: Also read 185530 - Performance: Customer developments in SD if you didn't already create an index on VBELN.
Regards,
Raymond
‎2015 Sep 14 3:55 PM
The Data in Database table will not be stored in sequence, it is the output in which it will be sorted and presented, Basically your se11 or se16 output is also a program which fetches the data and presents it.
If you want to get in sequence you can use ORDER BY Clause with select statement.
‎2015 Sep 15 7:06 AM
Hi Syed,
thanks for your response.
it means select.... endselect will fetch record randomly from vbfa table??
since for most of the time select...endselect fetches record in the same sequence as it is present in VBFA table.
Regards
‎2015 Sep 14 9:25 PM
Navdeep - SAP selects and then sorts in order to show the display. In you program as well, you need to explicitly sort or order (as Syed suggested).
We had a similar issue where the primary keys were not sorted and our Binary READ was failing. SAP suggests, explicit sort.
Regards,
Raju.
‎2015 Sep 15 7:50 AM
As soon as you don't use a ORDER BY option, SQL optimizer will usually read data in an unpredictable order, can also be complexified for buffered tables. In most database the assertion "as it is present in XXX table" is false or non-sense. In your example you are not selecting using first primary keys, so optimize may use some other secondary index, or even temporary hash table or buffer created during previous SQL execution.
Hint: Also read 185530 - Performance: Customer developments in SD if you didn't already create an index on VBELN.
Regards,
Raymond