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

Comparing SELECT SINGLE Vs SELECT.. EXIT.. ENDSELECT for getting single row

Former Member
0 Likes
5,379

Hi,

I have a database table with 7 key fields. I need to fetch a single row using 4 of the keys.

Which is the best way out of below two and why?

1. select single * from table where key 1 key 2 key 3 key 4 are known.

2. select * from table where key 1 key 2 key 3 key 4 are known.

exit.

end select.

3. Select upto 1 row.

Please advise.

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,835

Performance point of view - Select single is best than others ( Here you get extened sysntx error since you do not have key fields in where clause ,other way use select upto 1 rows.

Thanks

Seshu

6 REPLIES 6
Read only

Former Member
0 Likes
2,836

Performance point of view - Select single is best than others ( Here you get extened sysntx error since you do not have key fields in where clause ,other way use select upto 1 rows.

Thanks

Seshu

Read only

Wil_Wilstroth
Active Participant
0 Likes
2,835

Hi Shreyas,

When you use SELECT * ... END SELECT statement to access your table, the system will access the database for value each time you loop. This will cause the traffic to increase and memory usage. Though you may be using it to select one row but its always good practice to avoid using this searching method unless situation needs you to do so.

However, if you use SELECT SINGLE and using KEYS, this will limit the search and keep the memory usage low plus reducing the execution time.

Definitely SELECT SINGLE will improve your program performance.

You can use performance tool like SE30 or ST05 to check out your SINGLE SEARCH...

I hope my explanation is correct.

Thanks

William Wilstroth

William Wilstroth
Read only

Former Member
0 Likes
2,835

Hi, some days ago, I have the same problem, and I found an article in the WIKI : [ Difference between select single and select upto.|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/difference%2bbetween%2bselect%2bsingle%2band%2bselect%2bupto.]. Hope this can help you.

In that article, the author compares the difference between SELECT SINGLE and SELECT UP TO, and I think 'SELECT SINGLE' and 'SELECT * .EXIT. ENDSELECT. ' have the same effect.

Regards,

feng.

Read only

abdul_hakim
Active Contributor
0 Likes
2,835

Hi Shreyas,

SELECT SINGLE is the best way to go here(in view of performance!!!)

Please try to include the other key fields(complete key) in the WHERE clause

to fetch the unique entry exactly!!!!

Cheers,

Abdul Hakim

Mark all useful answers!!!

Read only

Former Member
0 Likes
2,835

TOPIC :- Use select up to 1 rows instead of select single.

TIP :-

Its very usefull to use select upto 1 rows instead select single statement,

For example you can check it out with this code.

REPORT z_test1.

data: ls1 type sflight-fldate,

ls2 type sflight-fldate,

a type i,

b type i,

c type i.

get run time field a.

select single fldate

from sflight

into ls1

where carrid = 'LH' and connid eq '400'.

get run time field b.

c = b - a.

write:/ 'runtime for select single:',c.

write:/ ls1.

get run time field a.

select fldate

from sflight

into ls2

up to 1 rows

where carrid = 'LH' and connid eq '400'.

endselect.

get run time field b.

c = b - a.

write:/ 'runtime for upto 1 rows:',c.

write:/ ls2.

Rewards if useful.........

Minal

Read only

jayakummar
Active Participant
0 Likes
2,835

hai,,

please use select single............

it will give a better performance......

jai.m