05-27-2008 2:27 PM
Hi All,
Where we r using the below statements
Select single * from
and
Select * from table up to 1 row
Reward points for helpful answer
I look forward to your reply
Regards
SEK
05-27-2008 2:34 PM
Hi,
select single is best used when you have the full key to identify the unique record.
When you have partial key and have to get only one record, you use the up to 1 row.
Regards.
05-27-2008 2:36 PM
Learn to use the search function of this forum - this question has been asked hundreds of times before. Also try using the F1 help in the ABAP editor.
05-27-2008 2:37 PM
Hi,
Please search in SDN forum, you will get many threads.
Thanks,
Sriram Ponna.
05-27-2008 2:37 PM
HI
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.
http://www.sapdevelopment.co.uk/tips/tips_select.htm
http://iorboaz.blogspot.com/2005/07/sap-abap-select-statement-lesson-1.html
05-27-2008 2:38 PM
SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there are more matching rows for the given condition.
SELECT ... UP TO 1 ROWS retrieves all the matching records and applies aggregation and ordering and returns the first record.
Inorder to check for the existence of a record then it is better to use SELECT SINGLE than using SELECT ... UP TO 1 ROWS since it uses low memory and has better performance.
Plz Reward
Regards
Anbu
05-27-2008 2:39 PM
Hi Raja Sekhar,
Select single * from KNA1 where clause
---It fetches single record from the database, based on the condition you specified in the where clause.
Where as select * from kna1 up to 1 row
---Fetches first record if the condition specified in the where clause is satisfied, otherwise it doesn't fetch any record.
Whats The Difference. SELECT SINGLE or UP TO 1 ROWS, Whats The Difference ?
A lot of people use the SELECT SINGLE 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 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' 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 '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 or lack of, applies any aggregate, ordering or grouping functions to them and then returns the first record of the resultant result set.
The difference between select * upto 1 row and select single is that select up to one rows is much quicker that select single as your not really using the all the key fields. Select single is a construct that is designed primarily to read database records with a primary key. If there is no primary key available then at the most it might end up doing a perfunctory sequential search. However in the case of select up to one rows it will assume that there is no primary key and will automatically search for the most appropriate index.
In select * single only a single record is fetched that is whichever one will come first in the data base query. But in the case of select one rows all the records will be fetched and stored in a buffer which pertain to the where condition in the Data base theory.
Best regards,
raam