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

Similar Messages

  • 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

  • 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

  • Problem while using SELECT Operation in DB Adapter

    Hi,
    I am trying to use the DB Adapter with SELECT operation on one of the tables in our database. The query looks some thing like,
    SELECT ORDER_HEADER_ID, SHIPPING_GRP_ID, ATG_SHIPPING_GROUP_ID, SO_HEADER_ID, ORDER_NUMBER, SHIP_ITEM_ID FROM <TABLE_NAME> WHERE (<CNAME> = #orderID)
    I have selected order_header_id as the primary key during the creation of my process. And the rest are selected as part of the query.
    The problem that I having is that I am getting the same data for all the rows, the output is as follows
    <root>
    <XxacOrderStatusDetail>
    <orderHeaderId>265</orderHeaderId>
    <shippingGrpId>262</shippingGrpId>
    <ShippingGroupId>sg832798</ShippingGroupId>
    <soHeaderId>4016992</soHeaderId>
    <orderNumber>82555268</orderNumber>
    <ShipItemId>r421379</ShipItemId>
    </XxacOrderStatusDetail>
    <XxacOrderStatusDetail>
    <orderHeaderId>265</orderHeaderId>
    <shippingGrpId>262</shippingGrpId>
    <ShippingGroupId>sg832798</ShippingGroupId>
    <soHeaderId>4016992</soHeaderId>
    <orderNumber>82555268</orderNumber>
    <ShipItemId>r421379</ShipItemId>
    </XxacOrderStatusDetail>
    <XxacOrderStatusDetail>
    <orderHeaderId>265</orderHeaderId>
    <shippingGrpId>262</shippingGrpId>
    <ShippingGroupId>sg832798</ShippingGroupId>
    <soHeaderId>4016992</soHeaderId>
    <orderNumber>82555268</orderNumber>
    <ShipItemId>r421379</ShipItemId>
    </XxacOrderStatusDetail>
    </root>
    For the output above the "ShipItemId" should return different values but it is returning the same for all the results that are returned. As in the first entry should have r421379 then r421380 and then r421381 for the last one.
    When I try including the "ShipItemId" as a primary key I am able to get the correct value but my process will fault in case if there is a null value for the column.
    I wanted to know if there is a way that I can resolve this problem?
    JDeveloper Version: Build JDEVADF_11.1.1.6.0_GENERIC_111205.1733.6192.1
    SOA Version is also 11.1.1.6.0
    Database Driver(Selected during data source creation on WLS) : Oracle's Driver(Thin XA) for Instance connection
    Can anyone please help me with this?
    Thanks.

    Hi,
    You are in a catch 22 situation, it won't work without a proper primary key defined, and a primary key is not suppose to contain nulls...
    This type of case is one of the reasons I always tend to prefer to have surrogate keys on the database... If you had a surrogate key defined your problem just wouldn't exist.
    Some references bellow...
    http://pic.dhe.ibm.com/infocenter/cbi/v10r1m1/index.jsp?topic=%2Fcom.ibm.swg.ba.cognos.ug_ds.10.1.1.doc%2Fc_surrogatekeys.html
    http://en.wikipedia.org/wiki/Surrogate_key
    Cheers,
    Vlad

  • Problem while using select

    I am using the <select>[ tag to display a pull down in my jsp.. I have a menu bar which has another pull down...When i try to select something from the menu if there is a select pull down below it then the select pull down overlaps the menu pull down.How can i remove this problem..

    move the select field.
    I think there's a trick to doing drop-down menus with an iframe in a div as the drop-down part that would cover that up.

  • SMALL PROBLEM IN USING SELECTION-OPTIONS STATEMENT

    Hello ABAP Gurus,
    I am trying to write a simple program that takes 'FROM' and 'TO' dates which will be used to generate a report..
    However the requirement is that the 'FROM' date should have a default value that is read from a file and the 'TO' date should have a default value of today's date. The Client wants to option of changing these dates if needed.
    However, when I wrote the following program, it first doesn't read the text file for the 'FROM' date and therefore it is by default filling only 'TO' date and leaving the 'FROM' field blank. Can some one please let me konw what I am not doing correctly.
    The simple code that i have written is
    =======================================================================================
    REPORT  Z_PROGRAM1.
    DATA: DAYSTMP(40),
          FROMDATE LIKE SY-DATUM.
    DAYSTMP = 'C:\EXTRACTEDDATA\ExtractedDate.txt'.
    OPEN DATASET DAYSTMP FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    READ DATASET DAYSTMP INTO FROMDATE.
    CLOSE DATASET DAYSTMP.
    SELECTION-SCREEN: BEGIN OF BLOCK MAIN WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS:   S_DATE FOR SY-DATUM DEFAULT FROMDATE TO SY-DATUM
    OPTION BT SIGN I.
    SELECTION-SCREEN: END OF BLOCK MAIN.
    ========================================================================================
    Any suggestions/feedback will be greatly appreciated.
    Thanks
    Ram
    Edited by: Prasad Ram on Oct 28, 2009 5:34 PM

    ... and please use the above <<>> code button after selecting the code with the mouse. Then formatting is preserved and readabilty is enabled.
    Many people (including me) refuse to read unformatted coding.
    Regards,
    Clemens

  • 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

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

  • 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

    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

Maybe you are looking for

  • How do I restore the settings for apps using Time Machine?

    I believe there are problems with items within the Library Folder inside the System Folder.  For example, there are two "Frameworks" Folders, but one has "(from old Mac)" after its name.  I dare not try to remove or even move either. Back in the day

  • Resizing JFrame with a Jbutton click

    I've witten a simple GUI program that if you click on one button it increases the size of the JFrame and the other button will decrease it. The problem is I tried using ComponentResize() putting a listener on the buttons,but it wouldn't work. Anybody

  • Can't understand CSS

    I am trying to make an HTML webpage. But I am having a hard time changing the appearance of my menu buttons. The starting point of my work could be seen on this address: http://www.batzorig.com/gallery2 As you can see, at the moment there are only tw

  • HP Evy 15 Laptop

    Hello, I am curretly expericig massive keyoard issues with my laptop. Last ight certai letters whe typed would ecome radom umers ad letters ad as you ca see right ow a few of my letters just wot work (maily the ottom row ad the F keys). Please help!

  • Forgot old appleid to activate iPad after restored

    AA have forgotten my old appleid and password to activate iPad after being restored. Please help urgently