Select Single * and Select upto one row

Hi all,
Can anybody tell me what is difference between Select single * and select upto one row?
And which one is better?
Thanks in advance.......

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 is the best one compared to UPto one rows.
Select Single will get the first record from the table which satisfies the given condition.So it will interact once with the database.
UTO 1 rows will get the list of the records for the given match and iwll show the first record from the list.So it will take time to get the record.
SELECT SINGLE VBELN from VBAK
where MATNR = '1M20'.
---Thjis will get the first matched record and will display the record
SELECT VBELN from VBAK
where MATNR = '1M20' upto 1 rows.
---Thjis will get the list of matched records and will display the first record
The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
Thus Select Single will take much processing time when compare with Select UPTO 1 rows.
Also
check these threads..
Difference between Select Single and Selct upto 1 row
Difference between Select Single and Select upto 1 row
Difference between select single and select upto one row
Difference between 'select single *' and 'select upto 1 rows'
difference between select single and select up to 1 rows
regards,
srinivas
<b>*reward for useful answers*</b>

Similar Messages

  • Regarding select single and select upto 1 rows

    hi experts,
                 plz let me know about difference between select single and select upto 1 rows with small eg...
    thnx in advance.

    Hi Ravi,
    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 is the best one compared to UPto one rows.
    Select Single will get the first record from the table which satisfies the given condition.So it will interact once with the database.
    UTO 1 rows will get the list of the records for the given match and iwll show the first record from the list.So it will take time to get the record.
    SELECT SINGLE VBELN from VBAK
    where MATNR = '1M20'.
    ---Thjis will get the first matched record and will display the record
    SELECT VBELN from VBAK
    where MATNR = '1M20' upto 1 rows.
    ---Thjis will get the list of matched records and will display the first record
    The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
    Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
    Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
    Thus Select Single will take much processing time when compare with Select UPTO 1 rows.
    Also
    check these threads..
    Difference between Select Single and Selct upto 1 row
    Difference between Select Single and Select upto 1 row
    Thanks,
    Reward If Helpful.

  • Diff bw select single *  and select upto one row

    hai,
        what is the difference  between select single *  and select upto one row.

    hi,
    ex code
    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.
    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 hlped pls mark points

  • Select single and select upto 1 rows

    Hi
    What is the difference between select single and select upto 1 rows
    Performance wise which one is the best
    Regards,
    Maya

    Hi,
    Difference Between Select Single and Select UpTo One Rows
    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.
    reward points if useful
    regards,
    ANJI

  • Defference between select single and select upto 1 row?

    What is the Defference between select single and select upto 1 row?

    Hi,
    Difference Between Select Single and Select UpTo One Rows
    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.
    Regards,
    Priya.

  • Diff between select single and select upto 1 rows.

    Hello aLL,
    PL tell what is technical diff between select single and select upto 1 rows and how it is affecting the performance.
    Rushikesh

    Hi
    Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS
    A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. 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
    SELECT SINGLE field INTO w_field FROM table.
    and
    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 memory usage and they may be worlds apart.
    Why is this ?? The answer is simple.
    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.
    Get the difference ??
    If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :
    Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.
    Then run the program shown below:
    Code:
    Program: Z_Difference
    Purpose: A program that demonstrates the difference
    between SELECT SINGLE and SELECT UP TO n ROWS.
    This program requires the data table Z_DIFFERENCE
    to have been created according to the structure
    outlined in the text above and populated with
    at least 10 records.
    Creation Date: 21/04/2004
    Requested By:
    Reference Doc:
    Author: R Harper
    Modification History:
    Date Reason Transport Who
    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.
    You should see the output:
    Select single: 000001
    Up to 1 rows : 000010
    The first 'SELECT' statement selected the first record in the database according to any selection criterion in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result.
    In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower.
    Note that this causes a problem in the Extended Program Check if the full key is not specified in a 'SELECT SINGLE'. Replacing the 'SELECT SINGLE' by an "UP TO 1 ROWS" will give the same exact results without any warning but the program will run slower and consume more memory. This is a good example of a warning that we should ignore... considering you are sure of what you are doing !!

  • Select single and select upto

    what is the difference of select single and select upto statements

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

  • Regarding select single and select upto???

    HI All,
    Cud u pls let me know the differences between select single and select upto??
    and which is the better option?? pls its quite urgent..plss plss
    plss
    Thanx in Advance
    Prasad

    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.
    Check this example ...
    DATA: gv_vbeln TYPE vbak-vbeln,
    gv_erdat TYPE vbak-erdat.
    SELECT SINGLE vbeln erdat
    FROM vbak
    INTO (gv_vbeln, gv_erdat)
    WHERE erdat = '12/01/2006'.
    SELECT vbeln erdat
    FROM vbak UP TO 1 ROWS
    INTO (gv_vbeln, gv_erdat)
    <b>ORDER BY erdat ASCENDING</b>.
    ENDSELECT.
    *In the example, the select single gets the first record that satisfies the WHERE clause unlike in the UP TO 1 ROWS where it sorts the database records by the earliest date and gets its VBELN.
    <b>Try using the ORDER BY clause in SELECT SINGLE .. It gives an error !! U cannot use that with SELECT SINGLE</b>
    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.
    Hope u understood !!
    reward if it helps u..
    sai ramesh

  • Select single and select

    hi everybody
    what is the exact difference between select single vbeln  and select vbeln
    In what situations i should use these select single vbeln or select vbeln
    regards
    hridhayanjili.

    Hai
    Go through the following Document
    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
    Regards
    Sreeni

  • Diffrence b/w select single & select upto one row

    hi
       wat is the diffrence b/w select single & select upto one row?
    deepak

    Hi,
    Select single has to be used with a where condition that has all the key fields:
    It will always return a unique record(If a match is found).
    Select upto 1 rows would get your the first record if multiple matches are found.
    and select up to has to be end with endselect statements.
    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.
    When you say SELECT SINGLE, it means that you are expecting only one row to be present in the database for the condition you're going to specify in the WHERE clause. so that means, you will have to specify the primary key in your WHERE clause. Otherwise you get a warning.
    SELECT UP TO 1 ROWS is used in cases where you just want to make sure that there is at least one entry in the database table which satisfies your WHERE clause. Generally, it is meant to be used for existence-check.
    You may not want to really use the values returned by the SELECT statement in this case (thought this may not necessarily be so).And in each case the database optimizer may choose a different strategy to retrieve the data.
    Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS
    A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. 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
    SELECT SINGLE field INTO w_field FROM table.
    and
    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 memory usage and they may be worlds apart.
    Why is this ?? The answer is simple.
    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.
    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.
    http://sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm
    Check these links -
    The specified item was not found.
    diff between select single and up to one row
    diff b/w SECELT SINGLE *   AND SELECT UPTO ONE ROW
    Regards,
    Priyanka.

  • Diff between select single * or upto one row

    Hi,
    what is the difference between select single *   and   select upto one row.
    regards
    krishna

    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.
    Regards,
    Bhaskar

  • Select  single  n   select upto

    frends please provide me the detail document and scenarios where we use with examples about select single and select upto n rows ?

    Hi,
    A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. 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
    SELECT SINGLE field INTO w_field FROM table.
    and
    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 memory usage and they may be worlds apart.
    Why is this ?? The answer is simple.
    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.
    Get the difference ??
    If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :
    Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.
    Then run the program shown below:
    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.
    You should see the output:
    Select single: 000001
    Up to 1 rows : 000010
    The first 'SELECT' statement selected the first record in the database according to any selection criterion in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result.
    In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower.
    Note that this causes a problem in the Extended Program Check if the full key is not specified in a 'SELECT SINGLE'. Replacing the 'SELECT SINGLE' by an "UP TO 1 ROWS" will give the same exact results without any warning but the program will run slower and consume more memory. This is a good example of a warning that we should ignore... considering you are sure of what you are doing !!
    Regards,
    Ferry Lianto

  • Select single * & Select  * upto one row

    What is the difference between Select single * & Select * upto one row?Performance wise which is a better one?

    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
    Regards

  • Select Single Vs Select upto 1 row

    Hi All,
    Please tell me which of the two statements is better if we want to retrieve only one record from a table.
    Select single or Select upto 1 rows?
    Regards,
    Saurabh

    There is a lot of confusion in the replies and also in the other thread.
    If yoou ask 'A versus B' then this implies that you can use both for the same task, which is here not really true.
    SELEC SINGLE should be used for SELECT with full primary key. where only 1 record CAN come back.
    UP TO 1 ROWS is the special case of UP TO n ROWS can be used with any WHERE condition and gives you the first record which is found.
    >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.
    This in incorrect, the UP TO n ROWS does not read all, only if the ORDER BY is added, then you will get the first records in sort order which requires that all rfecords are read.
    If you use UP TO 1 ROWS with a WHERE condition which is fulfilled by many records, then the first record is usually found very fast, even faster than a SELECT SINGLE.
    If you use UP TO 1 ROWS or SELECT SINGLE with the same WHERE condition, then both are more or less the same.
    Siegfried

  • "select count(*)" and "select single *" returns different result

    Good day!
    product version SAP ECC 6.0
    oracle10
    data transfers from external oracle db into customer tables using direct oracle db link
    sometimes I get case with different results from 2 statements
    *mytable has 10 rows
    *1st statement
    data: cnt type I value 0.
    select count( * ) into cnt from mytable WHERE myfield_0 = 123 and myfield_1 = '123'.
    *cnt returns 10 - correct
    *2nd statement
    select single * from  mytable WHERE myfield_0 = 123 and myfield_1 = '123'.
    *sy-dbcnt returns 0
    *sy-subrc returns 4 - incorrect, 10 rows are "invisible"
    but
    1. se16 shows correct row number
    2. I update just one row from "invisible" rows using se16 and 2nd statement returns correct result after that
    can not understand why
    thank you in advance.

    Thank you, Vishal
    but,
    general problem is that
    1. both statements have the same WHERE conditions
    2. 1st return resultset with data (sy-dbcnt=10), 2nd return empty dataset, but must return 1 in sy-dbcnt
    Yes, different meaning, you are right, but must 2nd must return 1, because of "select single *" construction, not 0.
    Dataset to process is the same, WHERE conditions are equal...
    I think the problem is that how ABAP interperets select count(*) and "select single *".
    Maybe "select count (*)" scans only PK from index page(s)? and "select single *" scans data pages? and something is wrong with that?
    I'm new in SAP and didn't find any SAP tool to trace dump of data and indexes pages with Native SQL.
    se16 shows all records.
    And why after simple manual update of just one record using se16 "select single *" returns 1?
    I've just marked one row to update, didn't change any data, then pressed "save".

Maybe you are looking for

  • TS3276 Can't open web addresses from an email-get an ERROR message saying-no application could be found

    Can't open web addresses from an email-get an ERROR message saying-no application could be found

  • Synching contacts with Outlook does not work

    I have a Mac (with the contacts application), an iPhone and an iPad as well as an iCloud account. Synching contacts between all 4 of them works perfectly. However, synching contacts with Outlook 2011 does not work anymore. It used to, then I had some

  • Tax condition in quotation

    hi all, can u please explain me i have to maintaion tax condition in quotation maintenance in $ sign only discount related condition are avl where should i maintain tax related conditions regards, sujit

  • Mobile enable portlet

    Hi ! I need your help if you can help me. I have a portlet done in jdeveloper retrieving student information and i want to convert it be mobile enabled portlet so as student can view with their mobile. I deploy to portal builder but seems like i keep

  • RFC Destination issue

    Hi I am facing an issue  while providing destination for RFC function module.I dont know  how to get the destination. Many of friends suggested me that we can get it through SM59. As I dont have authorisations for SM59,I could'not do. Is there any ta