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: 

What is the use of additon in up to 1 rows in SELECT statement

Former Member
0 Kudos

Hi All,

What is the use of up to 1 rows in select statement.

for example

SELECT kostl

FROM pa0001

INTO y_lv_kostl UP TO 1 ROWS

WHERE pernr EQ pernr

AND endda GE sy-datum.

ENDSELECT.

I'm unable to get in wat situations we hav to add up to 1 rows

please help me out...

Thanks,

santosh.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Up to 1 rows - it gets the single record from the database table based on where condition,normally i use select single if i have proper where condition ,if i do not have where condition ( Primary key) then i will use Select up to 1 rows.

Requiment would be - you have all materials in internal table,then you need to get material description for each material then i will use select up to 1 row or select single ..

Hope you got it

Thanks

Seshu

4 REPLIES 4

Former Member
0 Kudos

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.

select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

Former Member
0 Kudos

Hi Dear,

Select upto One row will improve your performanance when you have to select one row in table inspite of selcting all to know more abt this check in trips and tricks given in sap.

Reward Points if useful

Bohra.

Former Member
0 Kudos

Hi,

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 .... 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.

Regards,

Bhaskar

Former Member
0 Kudos

Up to 1 rows - it gets the single record from the database table based on where condition,normally i use select single if i have proper where condition ,if i do not have where condition ( Primary key) then i will use Select up to 1 rows.

Requiment would be - you have all materials in internal table,then you need to get material description for each material then i will use select up to 1 row or select single ..

Hope you got it

Thanks

Seshu