Skip to Content


Jun 21, 2017 at 10:26 AM


avatar image
Former Member

Hi Experts,

we are doing a ECC migration to HANA DB.

As part of custom code remediation process we used FUNCTIONAL_DB variant in ATC.

In few programs the existing code was written using SELECT SINGLE without passing full primary key.

We are replacing the select single statements with SELECT up to 1 rows but when I used select up to 1 rows, the results are not matching with the old system as we know the data in tables will be in sorted order in non-HANA system but in HANA because of column architecture the sort order will be different.

I want to know whether I have to use ORDER BY PRIMARY KEY or ORDER BY <FIELDS in SELECT List>


Pawan Akella

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Horst Keller
Jun 21, 2017 at 12:26 PM
10 |10000 characters needed characters left characters exceeded
Matthew Billingham
Jun 21, 2017 at 12:12 PM

1. In all except very old systems, SELECT UP TO 1 ROWS )without ORDER BY) will behave exactly the same as SELECT SINGLE. There is no point whatsoever in changing your programs. The SQL optimiser causes exactly the same SQL to be executed on the database. See here: which says

It used to be the case that SELECT SINGLE, and SELECT UP TO 1 ROWS had performance considerations. In most  modern database systems (e.g. Oracle) this is no longer the case - the two work identically. SELECT SINGLE is to be preferred as it is simpler coding.

2. In a relational database there is no concept of record order. That means if there are number of different records that match the WHERE clause, you might get any of them. If your programs were depending on the record order when you used SELECT SINGLE, then your programs were incorrectly written, and the fact that they worked is pure luck - it was a disaster waiting to happen.

3. There is no generic answer to your question "I want to know whether I have to use ORDER BY PRIMARY KEY or ORDER BY <FIELDS in SELECT List>" - what you do depends on the required logic.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

+1. I honestly see no point in such replacement all over the board. When I use partial key and don't specify anything else it means I don't care and any record will do. If it's not the case then the code was already incorrect. And even broken clock is right 2 times a day.

@Pawan - I believe you need to read ABAP Help for your release. It should be explained very clearly there what commands do what. From there you should be able to figure out what is applicable to your case.