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 .. EndSelect : inconsistency in selection sequence

navdeep_thakur12
Explorer
0 Likes
1,887

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

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,418

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

4 REPLIES 4
Read only

former_member183073
Active Participant
0 Likes
1,418

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.

Read only

0 Likes
1,418

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

Read only

Former Member
0 Likes
1,418

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,419

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