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: 

difference between select single and select upto 1 row

Former Member
0 Kudos

difference between select single and select upto 1 row

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Hi,

According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.

The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.

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.

Mainly: to read data from

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.

Reward if useful!

8 REPLIES 8

Former Member
0 Kudos

Hi,

Hi,

According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.

The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.

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.

Mainly: to read data from

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.

Reward if useful!

Former Member
0 Kudos

Hi,

According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

Select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

The best way to find out is through sql trace or runtime analysis.

Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.

The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.

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.

Mainly: to read data from

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.

Mainly: to check if entries exist.

Select Single

You need to mention all the key fields of the table.

No END SELECT required.

More performance compared to upto 1 row.

Where as UP to 1 row.

YOu can use if you do not have all the primiary key fields available.

END SELECT requeired.

Since all keys are not passing, possiblities of have other rows which satisfies the condition.

Select Statement with EndSelect is a loop, which in a single run retrieves a single Record. This Record has to be stored in a Work Area and then appended into an Internal Table.

Select Statements without EndSelect is not a loop and it retrieves the whole Record set matching the Criteria in a single shot and has to be Stored in an Internal Table Directly.

The most important thing to remember about the SELECT SINGLE is

There are several things to remember:

1) It retrieves only one row

2) It does not need an ENDSELECT statement

3) THE FULL KEY OF THE TABLE MUST BE INCLUDED IN

THE WHERE CLAUSE OF THE SELECT STATEMENT

<b>Reward points</b>

Regards

Former Member
0 Kudos

hi,

there is no diff technically between select single and select up to 1 row. Its just using select single considered to be of a good performance.

regards,

Navneeth K.

Former Member
0 Kudos

Hi,

According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

The best way to find out is through sql trace or runtime analysis.

Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.

The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.

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. Mainly: to read data from

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. Mainly: to check if entries exist.

Hope this helps.

Reward if helpful.

Regards,

Sipra

former_member219399
Active Participant
0 Kudos

hi,

If you want to check an entry existing or not you willl use select upto 1 row. Its like a validation.this is like, if you want to check whether any documents exist in table LIKP with plant 0001. then u will give select upto 1 row. if sy-subrc = 0. you will process further else you can raise a message and come out of this. With select upto 1 row you can specify conditions also.

It fetches first record if the condition specified in the where clause is satisfied, otherwise it doesn't fetch any record.

if you want to check exact entry like, in T001w whether the plant is there are not you will write code as select single * from T001W where werks = '0001'.

remeber with select single you shd supply full primery key. otherwise inconsistencies will be there.

with regards,

Vamsi

Former Member
0 Kudos

The <b>'SELECT SINGLE'</b> 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 <b>'SELECT .... UP TO 1 ROWS'</b> 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.

reward points if it is usefull ....

Girish

Former Member
0 Kudos

<b>Whats The Difference. SELECT SINGLE or UP TO 1 ROWS, Whats The Difference ?</b>

A lot of people use the <b>SELECT SINGLE</b> statement to check for the existence of a value in a database prior to running a large report. Select singles are also used to look up values from a database where that value is going to be constant for the duration of the program run, or the value is being used to validate some user entry.

Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.

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

If you're considering the statements

Code:

SELECT SINGLE field 
  INTO w_field 
  FROM table.

and

Code:

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 memeory usage and they may be worlds apart.

The <b>'SELECT SINGLE'</b> 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<b> 'SELECT .... UP TO 1 ROWS'</b> statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause or lack of, applies any aggregate, ordering or grouping functions to them and then returns the first record of the resultant result set.

reward points if it is usefull ... ....

Girish

Former Member
0 Kudos

<u>SELECT SINGLE</u>

If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.

When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.

SELECT SINGLE is also used mainly for validation

SELECT SINGLE * FROM DTAB INTO DTAB WHERE CONDITION

SELECT SINGLE COMES UNDER SINGLE BUFFERING

<u>SELECT UP TO N ROWS</u>

This addition restricts the number of rows in the result set. A data object of the Type i is expected for n. A positive number in n indicates the maximum number of rows in the result set. If n contains the value 0, all selected rows are passed to the result set. If n contains a negative number, an exception that cannot be handled is raised.

If the addition ORDER BY is also specified, the rows of the hit list are sorted on the database server and only the number of sorted rows specified in n are passed to the result set. If the addition ORDER BY is not specified, n is filled with any number of rows in the result set that meet the WHERE condition.

SELECT UP TO COMES UNDER FULL BUFFERING