Shall I use SELECT SINGLE??

Iu2019ve retrieved MSEG-MATNR for the condition mseg-mblnr = material doc no. and mseg-mjahr = mat doc year and mseg-zeile = mat doc item.
And my retrieved data mseg data in i_mseg is like below:
Mblnru2026u2026u2026..mjahru2026..zeilen.u2026u2026.matnr
0049000242....1995......0003........YY-110
0049000242u2026.1995u2026u20260004u2026u2026.YY-120
0049000248....1995u2026u20260001u2026u2026..40-110C
0049000248u2026.1995u2026u20260002........40-200C
0049000248u2026.1995u2026u20260003........40-210
0049000248u2026.1995u2026u20260004........L-40C
Now Iu2019ll have to fetch:
MAKT-MAKTX for the condition MAKT-MATNR=MSEG-MATNR and MAKT-SPRAS = u2018ENu2019.
Shall I use select single or normal select queries for makt-maktx retrieval?
If select single, then why and if not, then why?     
Can anyone please guide?
Regards.

Hi,
It depends of how many records you expect to read. If you have a reduced amount of records I would expect for the join statement to underperform, even if the access to the data bank is faster.
But at a considerable amount of data the join might be a lot faster. Use the tc SM30 to test your code.
This is a test script (for development system):
TABLES: mseg, makt.
SELECT-OPTIONS: s_mblnr FOR mseg-mblnr,
                s_mjahr FOR mseg-mjahr,
                s_zeile FOR mseg-zeile.
PARAMETERS p_join AS CHECKBOX.
DATA: BEGIN OF l_mseg,
        mblnr LIKE mseg-mblnr,
        maktx LIKE makt-maktx,
      END OF l_mseg.
START-OF-SELECTION.
  DO 10000 TIMES.
    IF p_join IS INITIAL.
      SELECT mblnr INTO l_mseg-mblnr FROM mseg WHERE mblnr IN s_mblnr
                            AND mjahr IN s_mjahr AND zeile IN s_zeile.
        SELECT SINGLE maktx INTO l_mseg-maktx FROM makt
                                   WHERE matnr EQ mseg-matnr AND spras = sy-langu.
      ENDSELECT.
    ELSE.
      SELECT mblnr maktx INTO l_mseg
               FROM mseg JOIN makt ON makt~matnr = mseg~matnr
               WHERE mblnr IN s_mblnr AND mjahr IN s_mjahr AND zeile IN s_zeile
               AND spras = sy-langu.
      ENDSELECT.
    ENDIF.
  ENDDO.
regards,
Edgar

Similar Messages

  • Problem in using Select Single

    Hi Experts,
    This is Prabhakar
    The following requirement is giving littlebit trouble to me. Here I don't know how to use Select single for selecting maktx field from MAKT table and how to link it to MARC and MBEW tables. How i will write code using without headerline.
    <b>Requirement is :</b>
    What this is asking is to create a report that contains the following fields in both the Selection Screen and in the report output:
    •     Material Number  -  MARC-MATNR
    •     Material Description  -  *
    •     Warehouse Cycle Count Indicator  -  MARC-ABCIN
    •     Standard Cost  -   MBEW-STPRS**
    •     Profit Center  -  MARC-PRCTR
    Use the following code to get Material Description (RESULT is the material that results from selecting from MARC):
    FORM GET_MATERIAL_DESCRIPTION.
      CLEAR MAKT.
      SELECT SINGLE MAKTX INTO MAKT-MAKTX FROM MAKT
                          WHERE MATNR = RESULT-MATNR
                          AND   SPRAS = SY-LANGU.
    ENDFORM.                               " GET_MATERIAL_DESCRIPTION
    For now, select standard price with the following criteria:
          SELECT SINGLE STPRS
                 FROM MBEW
                WHERE MATNR = RESULT-MATNR
                AND   BWTAR = SPACE.
    There is another field in the key to MBEW – it is BWKEY, and it is related to plant.
    So, first select from MARC, and with the results of MARC, select from MBEW

    Hi,
    It is advisable that dont include Material Description(MAKTX_ and Cost(STPRS), as, if you miss a single letter in material description in the selection screen you will not get your required data, Cost is also same like that so many materials will having same cost and validating will become difficult. If you include these two unnessesarily you are increasing your program complexity. See the code below which satisfy your requirement with good performance.
    Hope This Info Helps YOU.
    <i>Reward Points If It Helps YOU.</i>
    Regards,
    Raghav
    TABLES : mara,marc,mbew,makt.
    DATA : BEGIN OF itab OCCURS 0,
           matnr LIKE  marc-matnr,
           prctr LIKE  marc-prctr ,
           abcin LIKE  marc-abcin,
           maktx LIKE  makt-maktx,
           stprs LIKE  mbew-stprs,
           END OF itab.
    DATA : BEGIN OF itab1 OCCURS 0,
           matnr LIKE marc-matnr,
           stprs LIKE mbew-stprs ,
           END OF itab1.
    DATA : BEGIN OF itab2 OCCURS 0,
           matnr LIKE mara-matnr,
           maktx LIKE makt-maktx,
           END OF itab2.
    *Selection Screen
    SELECTION-SCREEN BEGIN OF BLOCK b1.
    SELECT-OPTIONS : s_matnr FOR marc-matnr,
                     s_prctr FOR marc-prctr,
                     s_abcin FOR marc-abcin.
    SELECTION-SCREEN END OF BLOCK b1.
    *Validations of the selection-screen
    AT SELECTION-SCREEN.
    PERFORM selection_screen_validation.
    START-OF-SELECTION.
      SELECT matnr
             prctr
             abcin
             INTO TABLE itab
             FROM marc
             WHERE matnr IN s_matnr
             AND abcin IN s_abcin
             AND prctr IN s_prctr.
    if not itab[] is initial.
      SELECT matnr
             maktx
             INTO TABLE itab2
             FROM makt
             for all entries in itab
             WHERE matnr = itab-matnr
             AND spras = sy-langu.
    endif.
    if not itab[] is initial.
      SELECT matnr
             stprs
             INTO TABLE itab1
             FROM mbew
             for all entries in  itab
             WHERE matnr = itab-matnr.
    endif.
    sort itab by matnr.
    sort itab1 by matnr.
    sort itab2 by matnr.
    clear : itab, itab1, itab2.
      LOOP AT itab.
        READ TABLE itab2 WITH KEY matnr = itab-matnr BINARY SEARCH .
        if sy-subrc eq 0.
          itab-maktx = itab2-maktx.
        endif.
        READ TABLE itab1 WITH KEY matnr = itab-matnr BINARY SEARCH .
        if sy-subrc eq 0.
          itab-stprs = itab1-stprs.
        endif.
        MODIFY itab.
        clear: itab, itab1, itab2.
      ENDLOOP.
    END-OF-SELECTION.
      LOOP AT itab.
        WRITE : /  itab-matnr,
                   itab-maktx,
                   itab-abcin,
                   itab-stprs,
                   itab-prctr.
      ENDLOOP.
    *&      Form  selection_screen_validation
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form selection_screen_validation .
    data : v_matnr type mara-matnr,
           v_prctr type cepc-prctr,
           v_abcin type t159c-abcin.
    ** validations for material number
    if not s_matnr[] is initial.
       select matnr from mara
                    into v_matnr
                    up to 1 rows
                    where matnr in s_matnr.
       endselect.
       if sy-subrc = 0.
          message e001 with ' Material '.
       endif.
    endif.
    ** validations for Profit Center
    if not s_prctr[] is initial.
       select prctr from cepc
                    into v_prctr
                    up to 1 rows
                    where prctr in s_prctr.
       endselect.
       if sy-subrc = 0.
          message e001 with ' Profit Center '.
       endif.
    endif.
    ** validations for Cycle Count Indicator
    if not s_abcin is initial.
       select abcin from t159c
                    into v_abcin
                    up to 1 rows
                    where abcin in s_abcin.
       endselect.
       if sy-subrc = 0.
          message e001 with ' Count Indicator '.
       endif.
    endif.
    endform.                    " selection_screen_validation

  • Problem while using select single

    Hii,
    I am using a select single command, My code is
    Select single * from zbe_gpfd_comment into wa_gpfd_comment where program_name = program
                                              and  box_type = box_type
                                              and     box_name = box_name.
    even though the required data is in the database still nothing is retrived in wa_gpfd_comment.No problem with datatype, I have checked them all..but still I am not able to get where the problem is?
    PS : program_name,box_type,box_name are primary key of the table zbe_gpfd_comment.

    Hi Priya,
    Did u checked what values are u passing in where condition for program , box_type , box_name .
    are there any values in the above the fields ,
    or just try to check once by hardcoding the values of the above 3 like 
    Select single * from zbe_gpfd_comment into wa_gpfd_comment where program_name = 'ZABC'
    and box_type = 'CUBE'
    and box_name = 'NOKIA'.
    give the 3 values which are existing in your zbe_gpfd_comment table .
    if it works then nothing wrong with select query ,
    and check the values in debugging whether the values are coming in :  program , box_type , box_name .
    I guess in ur query all the values are null or space , so it is not retriving values.
    check subrc also for the query.
    Regards,
    Aby

  • Select Single & Select upto -- req when to use?

    Hi Guys!
         Can u pls tell me when to use select single * & when to use select upto 1 rows. with eg.
      Thanks.

    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
    to say in simple
    SELECT SINGLE:
    1. Select single is based on PRIMARY KEY
    2. It will take the first record directly without searching of all relevant records.(Though you have lot of records for given condition)
    SELECT UPTO 1 ROW :
    It will check all records for given condition and take the first record .
    It means in select single no searching, where as other searching.
    Therefore, select single more efficient than UPTO 1 ROW.

  • What can be used for replacing SELECT SINGLE *   ?

    What can be used for replacing SELECT SINGLE *  for improving the performance in the following statements?
    SELECT SINGLE * FROM REGUV
       WHERE LAUFD = G_WLAUFD "RUN DATE ,SY-DATUM
         AND LAUFI = P_LAUFI.  "IDENTICATION NO
    SELECT SINGLE * FROM T100
       INTO CORRESPONDING FIELDS OF G_T100_WA
        WHERE SPRSL = G_T_IALLMESS-MSGSPRA
          AND ARBGB = G_T_IALLMESS-MSGID
          AND MSGNR = G_T_IALLMESS-MSGNR.
    SELECT SINGLE * FROM TBTCO
       INTO CORRESPONDING FIELDS OF TBTCO
        WHERE JOBNAME = FS_JOBNAME.

    If you need all the fields and you know that only one record exists then u need to use select single * only. You can improve the performance by specifying key fields in the where clause of select statements. If the structure of the work area or internal table in which you are fetching the data is same as that of the database table then no need to use corresponding fields clause.
    Best Regards,
    Vibha
    *Please mark all the helpful answers

  • Diff b/w select single * .... and select....up to 1 row

    Hi Abapers,
    What is the diff b/w Select single * from.... and select * ...up to 1 row.
    Thanks in advance.
    Subbu.

    Select SINGLE...
    SINGLE
    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. If you use the FOR UPDATE addition, the selected entry is protected against parallel updates from other transactions until the next database commit (see LUW and database lock mechanism). If the database system identifies a deadlock, a runtime error occurs.
    ... UP TO n ROWS
    Effect
    The set of results is restricted to a maximum of nrows.
    Example
    To output a list of the 3 business customers with the greatest discount:
    DATA WA_SCUSTOM TYPE SCUSTOM.
    SELECT * FROM SCUSTOM INTO WA_SCUSTOM UP TO 3 ROWS
             WHERE CUSTTYPE = 'B'
             ORDER BY DISCOUNT DESCENDING.
      WRITE: / WA_SCUSTOM-ID, WA_SCUSTOM-NAME, WA_SCUSTOM-DISCOUNT.
    ENDSELECT.
    Notes
    If you use an UP TO n ROWS addition in an ORDER-BY clause , the lines read are sorted into the correct order. The first n lines are then displayed. The system may need to read more than n lines from the database to be able to do this.
    If n = 0, all selected lines are displayed.
    n < 0 results in a runtime error.
    <b>Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS</b>
    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.
    <b>So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?</b>
    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 !!
    Message was edited by:
            Judith Jessie Selvi

  • Select single

    Hi experts,i have a query,plz help me.
    can i use select single in the below condition.
    crmd_link---table(key fields: guid_hi,guid_set)
    crmd_cancel---table(key fields:guid)
    SELECT SINGLE a~cancparty
                        a~canc_reason
                  INTO (l_canc_party,l_canc_reason)
                  FROM crmd_cancel AS a INNER JOIN crmd_link AS b
                  ON aguid = bguid_set
                  WHERE b~guid_hi = '32134241324'.
    on the above  statement can i use select single????????

    Hi Sravan,
    You can use either of the following:
    a) TRANSLATE : This command will change your 'T' to 'A' if its ZZXG1T. If its not, it will leave it as it is.
    SELECT SINGLE * FROM T881 WHERE RLDNR = P_RLDNR.
    DATA: WA_CHANGE(2) VALUE 'TA'.
    TRANSLATE T881-TAB USING WA_CHANGE.
    b) RELPACE : This too will perform the same function.
    REPLACE 'T' WITH 'A' INTO T881-TAB.
    The only difference between the two is that TRANSALTE replaces all occurances of a character with the one succeeding it in WA_CHANGE, while REPLACE will replace only the 1st occurance of the character.
    Hope this helps,
    Regards,
    Madhur
    NB: Please do award points if found helpful.
    Message was edited by: Madhur Chopra

  • When to use SELECT and END SELECT in the query.

    hi all,
    When to use SELECT and END SELECT in the query.
    regads,
    Venkata Suresh Penke.

    Hi Suresh..
    When do we need to use SELECT .. ENDSELECT
    Usually we will never use SELECT .. ENDSELECT as it gives very poor performance.
    But whenever we read a single Record we will use it as an alternative for SELECT SINGLE in some scenarios.
    Eg: When the Full primary key is not specified in the WHERE clause.
    SELECT * FROM MARC INTO WA_MARC UP TO 1 ROWS WHERE MATNR = P_MATNR.
    ENDSELECT.
    And other scenario is when we perform AGGREGATE OPERATIONS.when the Result is only one row.
    SELECT SUM( LABST ) FROM MARD INTO V_LABST UP TO 1 ROWS
    WHERE MATNR = P_MATNR.
    ENDSELECT.
    Note: In The Above scenario we cannot use SELECT SINGLE..
    <b>REWARD IF HELPFUL.</b>

  • Select single query working unexpectedly

    Hi all,
    I have used below select single * query as shown :
    I have data in my table S022 as shown below, it has 2 records for material and aufnr combination :
    WERKS  ARBPL    kapar    MATNR                AUFNR      
    w1        ar1        004          mat1             000300156789
    w1        ar2                        mat1             000300156789
    The code used :
    select single *               
       from s022                   
      where werks = itab-ltap-werks  "w1
        and matnr = w_matnr         "mat1
        and aufnr = w_aufnr. " 000300156789
    runtime select query is picking second record i.e of ar2.
    I hope it should have picked ar1 record but its doesnt .
    Also sometimes it picks 1st record for different data and for this data it picks the second record.
    Kindly help me to explain why its not picking the first record.
    Regards.

    ujjwal_d15 wrote:
    It is as per the data in the table . The records are one below the another in database table.
    > So i feel it should have picked the first record.
    Hello Ujjwal,
    The records shown in the databrowser is a snapshot of the entries in the DB & not how the recs are actually stored!
    In RDBMS the sequence of entries is not defined at the DB layer. In SELECT SINGLE the 1st rec to be hit is returned to the result set. In your case this is the 2nd rec.
    BR,
    Suhas

  • MIN in select SINGLE  query.

    I need to find a single record with lowest DDUP.
    If there are 2 records exist, then i need a single record with lowest DDUP.
    loop at it_mara.
      SELECT SINGLE EKORG MATNR MFRPN ZEINR KUNNRS MIN( DDUP ) DCURR
                      FROM ZNVT_PRICE
                      INTO CORRESPONDING FIELDS OF LW_ZNVT_PRICE
                      WHERE EKORG  EQ P_EKORG       AND
                            MATNR  EQ IT_MARA-MATNR AND
                            MFRPN  EQ IT_MARA-MFRPN AND
                            ZEINR  EQ IT_MARA-ZEINR AND
                            KUNNRS EQ IT_MARA-KUNNR AND
                            DATAB  LE SY-DATLO      AND
                            DATBI  GE SY-DATLO
                      GROUP BY EKORG MATNR MFRPN ZEINR KUNNRS DCURR.
    endloop.
    there is only one record in the table ZNVT_PRICE. (1234.00)
    Some times i am getting 1234.
    Some times 0.00.
    I need to find a single record with lowest DDUP.
    If there are 2 records exist, then i need a single record with lowest DDUP.
    if I do not use GROUP BY i am getting error.
    I have to use SELECT SINGLE.
    Guys...please help me to write reliable query.

    Hi,
    Instead of SELECT SINGLE use
    SELECT.. UP TO 1 ROWS
    ENDSELECT.
    It will also be very fast and suit your requirement.
    Regards,
    Atish

  • IS ITCOMPULSARY  TO USE SELECT ENDSELETC IN LDB

    Hello All,
    Am freshaer in ABAP . In a code we use a LDB named PNM . in that LDB there is a table named PLPOD from this table we get the workcentre number then from it we will be going to database table crhd and crtx to get the description of that particular work centre . While selecting the data it is asking for endselect statement though i use  the target as a interanl table .

    Hi,
    if u want multiple entries of description ,U can use
    Select with into table it statement. then it do not ask u for endselect.
    for eg.
      SELECT
      matnr mtart mbrsh matkl
      FROM mara
      INTO CORRESPONDING FIELDS OF TABLE it
      WHERE matnr IN p_matnr.
    if u want single entries of description , u can use
    select single statement.
    For eg.
        select single KWERT
        from KONV
        into IT-ZADM
        where KNUMV = IT-KNUMV
          and KPOSN = IT-POSNR
          and KSCHL = 'ZADM'.
    Regards,
    Digesh Panchal

  • Select single problem...

    hi all,
    i have to take first value of table BSIS according to condition. i m using select single statement in table BSIS, but problem is that i m getting the value only in header by which i m not able to apply loop at itab. can anyone please help me?
    code.
    SELECT single bukrs hkont gjahr monat shkzg prctr FROM bsis INTO itab
                                    WHERE hkont IN hkont
                                    AND   bukrs IN bukrs
                                    AND   prctr IN prctr
                                    AND   gjahr IN gjahr
                                    AND   monat IN monat.
    here sy-subrc is 0. but value is only in header.
    regards saurabh.

    Hi Saurabh,
    i don't know what your program does but if you process the data you retrieve from table bsis more than once, it may be useful to create your internal table identical to table bsis;
    data: itab like bsis occurs 0 with header line.
    then get all the data from table bsis to your internal table at once.
      select * from bsis
        into table itab.
    then process itab with your selection criteria as you wish.
    avoid using the statement ...into corresponding fields of table (i assume you already are not using this)
    well i don't know what else you can do..
    regards;
    Murat Kaya

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

  • 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 1 ROW

    Dear All,
    I want to optimise the Code performance.
    I don't have full table key. So, what is better to use - SELECT SINGLE or SELECT UPTO 1 ROW?
    Please ASAP.
    Thanks in advance.
    Prasad.

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

Maybe you are looking for

  • Using Flex 3D Charts in Flex Builder 3

    Hi all, has anyone successfully used the Flex 3D Charts library in FlexBuilder 3? The component is at http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=1047 990 and having trawled back there was some chatter about

  • Is there a way to create a recurring revenue/billing event in Projects (r12)?

    Is there any way to create a revenue/billing event in Projects that can be scheduled (billed monthly until a specified end date) other than a customization?

  • Moni message status

    Hi, Iam getting message status in moni (Transport acknowledgement ) it tells acknowledgment not possible. So the reason is messages got stucked up. Is that only reason or are there are any reasons? what to do now?   Because of that i cannot able to r

  • How long to partition a 500mb drive

    I just bought a Seagate FreeAgent 500mb drive that needed to be partitioned because it came formatted NTFS for PCs. How long should this take? The progress bar has not hardly moved. Thanks.

  • Sizing changes on computer when I click on Adobe

    When I click on Adobe it asks if I want to let the changes be made then everything on the computer is HUGE for a few minutes.  Plus everything I upload the thumbnails are all hour glasses.  This is very frustrating!!  HELP!! Thanks! Stacy