Application Development 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: 

[Experts Only] Which of this methods has better performance ?

Rodrigo-Giner
Active Contributor
0 Kudos

SELECT SINGLE

or

UP TO 1 ROWS

Pls justify your answers.

Thx

1 ACCEPTED SOLUTION

abdul_hakim
Active Contributor
9 REPLIES 9

Former Member
0 Kudos

Hi,

If all the primary keys are known than SELECT SINGLE gives better performance than UPTO 1 ROWS otherwise it is difficult to say.

Thank you,

Ramu N

Former Member
0 Kudos

Hello,

In programming we dont use those statements for performance because there is no difference in performance between those statements.

UP TO n ROWS .....is the one when we need n rows in an internal table.

If you want only 1 row....you can use SELECT SINGLE.....or UPTO 1 ROW, but there is no difference in performance. They take the same resources.

I am very keen to hear what forum EXPERTS have to say about this )

Thanks,

Message was edited by: Naren Somen

0 Kudos

HI,

You can use either of these statements for fetching a single record. Hope we cannot compare these statements in terms of performance.

Here is the demonstration

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.

So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?

If you're considering the statements

SELECT SINGLE field INTO w_field FROM table.

and

SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT.

then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memory usage and they may be worlds apart.

Why is this ?? The answer is simple.

The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

Get the difference ??

If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :

Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.

Regards,

Santosh

Former Member
0 Kudos

SELECT SINGLE is used only if you have the full primary key and will give you unique resultant record. This is always the fastest since you are using the primary index.

Now it is not uncommon though, for people to use SELECT SINGLE to get one record that matches the criteria. In this case, system will work just like the UP TO 1 ROWS except one key difference. UP TO 1 ROWS introduces a SELECT ... ENDSELECT loop, which inherently has back and forth database/network overhead added to it. So that way SELECT SINGLE is still the better one. But in reality, you will not see much difference if you are not using SELECT SINGLE for its original purpose of getting a unique record based on primary key index search.

0 Kudos

You have the right to deny points to anyone who you think hasn't given you an <b><u>expert</u></b> opinion, but putting <b>'Experts Only'</b> in the subject doesn't go well with everyone(including experts, if there are any). Please desist from using such terms.

0 Kudos

ex·pert ( P ) Pronunciation Key (kspûrt)

noun


A person with a high degree of skill in or knowledge of a certain subject.

The highest grade that can be achieved in marksmanship.
A person who has achieved this grade.

adjective

(kspûrt, k-spûrt)

Having, involving, or demonstrating great skill, dexterity, or knowledge as the result of experience or training.

Just for fun!

Regards,

Rich Heilman

0 Kudos

My intention for putting expert was just to get a quick and accurate anwser.

Thx u all.

PD: Rich ... LOL _

0 Kudos

Please make sure that you reward points to these <i><b>experts</b></i> for their helpful answers. Thanks.

Regards,

Rich Heilman

abdul_hakim
Active Contributor