‎2006 Sep 19 7:39 AM
Hi,
I am working with MARA Table, I would like to use select single statement, how can I use this to get the data into internal table and display it.
I would also like to know the difference between select single statement and select upto 1 row
Can anybody help me out.
Thanks & regards
Pavan
098 49 93 63 53.
‎2006 Sep 19 7:56 AM
Hi,
check this simple program
tables:mara.
data:begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
select-options:s_matnr for mara-matnr.
select single matnr
from mara
into itab
where matnr in s_matnr.
append itab.
loop at itab.
write:/ itab-matnr.
endloop.
SELECT SINGLE
when you use <SINGLE> option in select stmt,it is mandatory to provide all the primary keys in the where clause.
whereas in UP TO <n rows>
this option used generally to fetch the reqd. no. of records. you want to display.
there is no need to supply the keys specifically.
regards,
sowjanya.
‎2006 Sep 19 7:42 AM
Report Z_Difference
Message-id 38
Line-Size 80
Line-Count 0
No Standard Page Heading.
*
Start-Of-Selection.
Data: w_Single type Posnr,
t_Rows type standard table of Posnr
initial size 0
with header line.
*
Select single Posnr
from zDifference
into w_Single.
*
Select Posnr
into table t_Rows
from zDifference
up to 1 rows
order by Posnr descending.
*
Write :/ 'Select single:', w_Single.
Skip 1.
Write :/ 'Up to 1 rows :'.
Loop at t_Rows.
Write t_Rows.
EndLoop.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.
‎2006 Sep 19 7:46 AM
But is not select single having only on DB hit as compared to select up to 1 row which is having 2 DB hit.
So I guess if you are using the primary keys then you should use Select single otherwise you should use Select up to 1 row.
Regards
Nishant
‎2006 Sep 19 7:42 AM
Hi,
Select single will select the first record that satisfies the condition(SUBRC value differs).. select upto one row will select any one record in random(SUBRC is alway 0)
syn:
select single * from mara into table t_mara
where matnr = s_matnr.
select * from mara into table t_mara upto 1 row
where matnr = s_matnr.
Regards
Divakar
‎2006 Sep 19 7:43 AM
HI,
data: itab type standard table of mara.
SELECT SINGLE * FROM MARA
INTO TABLE itab
WHERE MATNR = '90909000'.
<b>SELECT SINGLE</b>
The result of the selection should be a single entry. If it is not possible to identify a unique entry, the system uses the first line of the selection.
UP TO 1 ROWS.
Select a dataset form the database satisfying the query and returs the first row of this dataset.
Regards,
‎2006 Sep 19 7:45 AM
hi.
1.issue.
tables mara.
data : itab type table of mara occurs 0 with header line.
select single * from mara into itab where ur_condition.
if subrc = 0.
append itab.
clear itab. " clear th header
endif.
but to display all the datas
******************************
select * from mara into <b>table</b> itab where ur_condition.
loop at itab.
write : the required fileds.
endloop.
2. issue
********************
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.
You can refer to the below link..
http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm
rgds
anver
if hkped mark points
‎2006 Sep 19 7:48 AM
Hi,
The main diff b/w select single and select upto is
in select single you have to specify all the key fields in the where clause, in select upto one row we need not give all the key fields and it retrieves the first record from the set of records based on the where clause.
My advice is don't use internal table in select single or select upto one rows,always use work area(performance issue).
cheers,
Harsha
‎2006 Sep 19 7:51 AM
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.
Difference is select upto 1 row will select all the records in that condition and then does some grouping or sorting and then outputs the record. Takes more time.
But select single selects the forst row which meets that condition and gives the result.
For more details check blogs there is an article.
Keyword Performance tuning.
Regards
‎2006 Sep 19 7:56 AM
Hi,
check this simple program
tables:mara.
data:begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
select-options:s_matnr for mara-matnr.
select single matnr
from mara
into itab
where matnr in s_matnr.
append itab.
loop at itab.
write:/ itab-matnr.
endloop.
SELECT SINGLE
when you use <SINGLE> option in select stmt,it is mandatory to provide all the primary keys in the where clause.
whereas in UP TO <n rows>
this option used generally to fetch the reqd. no. of records. you want to display.
there is no need to supply the keys specifically.
regards,
sowjanya.
‎2006 Sep 19 8:05 AM
hi,
the above code is wrong.
still u gave points!!!!
kindly chk the code. it will not display anything at all.
look at the bold part. this is the right code
tables:mara.
data:begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
select-options:s_matnr for mara-matnr.
select matnr
from mara
into <b>table</b> itab
where matnr in s_matnr.
loop at itab.
write:/ itab-matnr.
endloop.
rgsd
anver
‎2006 Sep 19 9:48 AM
hi sowjanya suggula ,
thats gr8888!!!!
u edited ur code.
rgds
anver