MANDT in Select Query  ---- Urgent

Hi,
Will the passing of MANDT field in a select query makes the difference performance wise??
i.e, if I pass the MANDT (key field in all the tables) while querying a table, Will it give me a different result performance wise??
Can you attach some SAP document as a proof for this answer??
With Regards
Jiku

Hi,
There is no need to include this field in the select query and it has nothing to do with improving performance.
I don't think you can find any SAP document for same but you will find same answer from everyone
Reward points if useful.
Regards,
Atish

Similar Messages

  • Need clarification on select query Urgent!!!!!

    Hi ,
    i want clarification about this query , because i want improve performence to report in ST05 it is showing 1,40,250 time so i need to do some thing on this please any body help me out.
    SELECT  matnr  werks  dispo
                 FROM   marc
                 INTO   TABLE  it_marc
                        WHERE  matnr  IN  s_matnr  AND
                               werks  IN  s_werks  AND
                               dispo  EQ  p_dispo.
        DESCRIBE TABLE it_marc  LINES w_lines.
        IF  w_lines  IS INITIAL.
          MESSAGE e518(zv) WITH p_dispo.
        ENDIF.
      ENDIF.
    thanks,
    murali.

    SELECT matnr
      FROM mara
      INTO TABLE it_mara
      WHERE matnr IN s_matnr.
    IF sy-subrc eq 0.
      SELECT matnr werks dispo
        FROM marc
        INTO TABLE it_marc
        FOR ALL ENTRIES IN it_mara
        WHERE matnr = it_mara-matnr
          AND werks IN s_werks
          AND dispo EQ p_dispo.
      DESCRIBE TABLE it_marc LINES w_lines.
      IF w_lines IS INITIAL.
        MESSAGE e518(zv) WITH p_dispo.
      ENDIF.
    ENDIF.
    I am sorry, but I comment also bad recommendations, if I find any. And the above example such
    a bad recommendation.
    SELECT matnr
      FROM mara
      INTO TABLE it_mara
      WHERE matnr IN s_matnr.
    The first select selects much more than you really need, while there is only a select single necessary.
      DESCRIBE TABLE it_marc LINES w_lines.
      IF w_lines IS INITIAL.
    It is also not necessary to count 1000 of lines, if you want to know whether there was at least one records, a check
    of a sy-subrc is much better. This should also be done in the original coding.
    As said above, check what is in s_matnr and s_werks and what is suppossed to come back.
    Siegfried

  • SELECT QUERY-URGENT!!!

    Hi,
    Please respond on this ASAP.
    SELECT SINGLE PRODH FROM MVKE INTO MVKE-PRODH WHERE
    MATNR = VBDPR-MATNR.
    IF SY-SUBRC EQ 0.
    IF MVKE-PRODH NE SPACE.
    IF MVKE-PRODH(5) EQ '00003'.
    V_WINDSHIELDS = V_WINDSHIELDS + V_INV_QTY.
    V_WINDSHIELDS_TOTAL = V_WINDSHIELDS_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00004'.
    V_TEMPERED = V_TEMPERED + V_INV_QTY.
    V_TEMPERED_TOTAL = V_TEMPERED_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00005'.
    V_MOLDINGS = V_MOLDINGS + V_INV_QTY.
    V_MOLDINGS_TOTAL = V_MOLDINGS_TOTAL + V_INV_QTY.
    ENDIF.
    ENDIF.
    ENDIF.
    this is the logic
    i want to know if we are using sel single and
    if there are more entries in MVKE
    then too it will pick 1st always
    then what is the alternate,

    Hi
    When you use select single ,it's always will bring only one result (first that corresponds to selection criteria (in this case MATNR number).
    you can make it for example (make performance modifiation later):
    data:itab type mvke.
    SELECT SINGLE *
    FROM MVKE
    INTO table ITAB
    where MATNR = VBDPR-MATNR.
    IF SY-SUBRC EQ 0
    loop at itab.      (instead of MVKE put ITAB)
    IF MVKE-PRODH NE SPACE.
    IF MVKE-PRODH(5) EQ '00003'.
    V_WINDSHIELDS = V_WINDSHIELDS + V_INV_QTY.
    V_WINDSHIELDS_TOTAL = V_WINDSHIELDS_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00004'.
    V_TEMPERED = V_TEMPERED + V_INV_QTY.
    V_TEMPERED_TOTAL = V_TEMPERED_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00005'.
    V_MOLDINGS = V_MOLDINGS + V_INV_QTY.
    V_MOLDINGS_TOTAL = V_MOLDINGS_TOTAL + V_INV_QTY.
    ENDIF.
    ENDIF.
    endloop.
    so you will get all occurrences which corresponds for the matnr number
    Regards
    Yossi

  • SQL SELECT Query Help   ..Please its very Urgent!!

    Hi All,
    I am having Oracle Database whice is storing 1000's of records daily.
    I need to select some information based on date and time.
    I am having two coloumns for Date and time. The first column(testDate) of type Date stores date as MM/DD/YY format and the second column(testTime)of type Numeric stores the time in seconds.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    How can i write a SELECT Query to get the records of specific date and seconds to next day specific date and seconds.I mean i want all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    If any one helps me in this regard iam very thank full to them.Its very urgent for me.
    Thanks

    Hi m7nra,
    I used the query as
    SELECT * FROM table
    WHERE testDate + (testTime/(24*60*60)) BETWEEN TO_DATE('MM/DD/YYYY','12.11.2002') AND TO_DATE('MM/DD/YYYY','14.11.2002')
    its giving DATE FORMAT NOT RECOGNIZED error.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    infact i need all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    Please help me to find a full query beacuse iam very new to Oracle.
    Thanks,
    S R Mannava

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

  • URGENT: To change the where condition in select query at runtime ?

    Hi,
    I have to develop a report, 4 which I have created a selection screen with 7 Input Parameters whose value is to be filled by the user while executing the report.
    On the basis of this I do the desired selection of output.
    But the problem is that how do I write my select Query(where condition) if the user enetrs only 2 Input parameters or 3 or whatever he feels like.
    Pls help me out...

    hi,
    check this sample code.
    Here i am populating where condition at runtime.
    DATA: V_WHERE TYPE STRING.
    SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN,
                     S_ERDAT FOR VBAK-ERDAT.
    SELECTION-SCREEN END OF BLOCK INPUT.
    START-OF-SELECTION.
      PERFORM POPULATE_WHERE.
      PERFORM GET_VBAK_DATA.
    *&      Form  POPULATE_WHERE
    *       Populate Where
    FORM POPULATE_WHERE .
      IF NOT S_ERDAT[] IS INITIAL.
        CONCATENATE 'VBELN IN S_VBELN'
                    'AND'
                    'ERDAT IN S_ERDAT'
              INTO V_WHERE
              SEPARATED BY SPACE.
      ELSE.
        V_WHERE = 'VBELN IN S_VBELN'.
      ENDIF.
    ENDFORM.                    " POPULATE_WHERE
    *&      Form  GET_VBAK_DATA
    *       GET VBAK DATA
    FORM GET_VBAK_DATA .
      SELECT VBELN
             ERDAT
             VBTYP
             NETWR
             WAERK
             VKORG
             VTWEG
             SPART
        INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
        FROM VBAK
        WHERE VBELN IN S_VBELN
        AND   ERDAT IN S_ERDAT.
       WHERE (V_WHERE).
    endform.
    Regards
    Sailaja.

  • Select query on  CRMD_ORDERADM_H (urgent)

    Hi All,
          I want to retrieve data from CRMD_ORDERADM_H that would fetch all transactions created on the same day before 6pm.
    I also want another internal table that would contain transaction created on the same day between 6pm and 11pm.
    How do I write a SELECT query for the same ????
    Regards,
    Ashish

    Hi
    You can try it out useing the programme below for your requirement.
    data: it_all_orders1 type standard table of CRMD_ORDERADM_H with header line,
          it_all_orders2 type standard table of CRMD_ORDERADM_H with header line.  
    data: to_day type SYDATUM,
          time_stamp1 type COMT_CREATED_AT_USR,
          time_stamp2 type COMT_CREATED_AT_USR,
          time_stamp3 type COMT_CREATED_AT_USR.
    to-day = sy-datum.
    concatenate to-day(2) '.' to-day2(3) '.' to-day5(3) '.' '180.000' into time_stamp1.
    concatenate to-day(2) '.' to-day2(3) '.' to-day5(3) '.' '180.000' into time_stamp2.
    concatenate to-day(2) '.' to-day2(3) '.' to-day5(3) '.' '230.000' into time_stamp3.
    select * from CRMD_ORDERADM_H
             into corresponding fields of table
             it_all_orders1
             where
             CREATED_AT eq time_stamp1.
    select * from CRMD_ORDERADM_H
             into corresponding fields of table
             it_all_orders2
             where
             CREATED_AT between
                 time_stamp2
             and       
                 time_stamp3.
    Reward points if helpful
    Dinaker vikas

  • URGENT - Does Select Query Sort based on RowId ?

    Does Select Query Sort based on RowId ?
    Eg: Select * from Employee;
    RowId primkey name
    aaaa 1 kiran
    aaab 2 kumar
    aaac 3 someone
    Now when i delete the primkey: 2 row.
    I will have:
    RowId primkey name
    aaaa 1 kiran
    aaac 3 someone
    Now when i insert a new record:
    RowId primkey name
    aaaa 1 kiran
    aaac 3 someone
    [Comment: Here the rowid can either be a new one like 'aaad' or 'aaab' is also reused.]
    aaad 4 somename
    My requirement is that the 'aaab' should not be reused.
    Can any one pls suggest some way.

    Dear Friend,
    Plese gothrougth once following steps... (One by One)
    Hope you can understand how Rowid Creating and Updting in you table.
    SQL> select rowid,enumber from t;
    ROWID ENUMBER
    AAAJ4oAABAAAWlyAAA 1
    AAAJ4oAABAAAWlyAAB 2
    AAAJ4oAABAAAWlyAAC 3
    AAAJ4oAABAAAWlyAAD 4
    SQL> select rowid,enumber from t where enumber = 2;
    1 row deleted.
    SQL> insert into t values(9):
    1 row created.
    SQL> select rowid,enumber from t;
    ROWID ENUMBER
    AAAJ4oAABAAAWlyAAA 1
    AAAJ4oAABAAAWlyAAC 3
    AAAJ4oAABAAAWlyAAD 4
    AAAJ4oAABAAAWlyAAE 9
    SQL> delete from t where enumber = 3;
    1 row deleted.
    SQL> insert into t values(3);
    1 row created.
    SQL> select rowid,enumber from t;
    ROWID ENUMBER
    AAAJ4oAABAAAWlyAAA 1
    AAAJ4oAABAAAWlyAAB 3
    AAAJ4oAABAAAWlyAAD 4
    AAAJ4oAABAAAWlyAAE 9
    Regards,
    G V Sreenivasulu

  • Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query

    Hi All,
    There is a Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query in a report painter.
    This query is working fine when executed in 4.7 system where as it is running for more time in ECC6.0.
    Select query is on the table COSP.
    SELECT (FIELD_LIST)
            INTO CORRESPONDING FIELDS OF TABLE I_COSP PACKAGE SIZE 1000
            FROM  COSP CLIENT SPECIFIED
            WHERE GJAHR IN SELR_GJAHR
              AND KSTAR IN SELR_KSTAR
              AND LEDNR EQ '00'
              AND OBJNR IN SELR_OBJNR
              AND PERBL IN SELR_PERBL
              AND VERSN IN SELR_VERSN
              AND WRTTP IN SELR_WRTTP
              AND MANDT IN MANDTTAB
            GROUP BY (GROUP_LIST).
       LOOP AT I_COSP      .
         COSP                           = I_COSP      .
         PERFORM PCOSP       USING I_COSP-_COUNTER.
         CLEAR: $RWTAB, COSP                          .
         CLEAR CCR1S                         .
       ENDLOOP.
    ENDSELECT.
    I have checked with the table indexes, they were same as in 4.7 system.
    What can be the reson for the difference in execution time. How can this be reduced without adjusting the select query.
    Thanks in advance for the responses.
    Regards,
    Dedeepya.

    Hi,
    ohhhhh....... lots of problems in select query......this is not the way you should write it.
    Some generic comments:
    1. never use SELECT
                       endselect.
       SELECT
      into table
       for all entries in table
      where.
       use perform statment after this selection.
    2. Do not use into corresponding fields. use exact structure type.
    3. use proper sequence of fields in the where condition so that it helps table go according to indexes.
        e.g in your case
              sequence should be
    LEDNR
    OBJNR
    GJAHR
    WRTTP
    VERSN
    KSTAR
    HRKFT
    VRGNG
    VBUND
    PARGB
    BEKNZ
    TWAER
    PERBL
    sequence should be same as defined in table.
    Always keep select query as simple as possible and perform all other calculations etc. afterwords.
    I hope it helps.
    Regards,
    Pranaya

  • Select query with secondary index

    hi,
    i have a report which is giving performance issues on a perticular select query on KONH table.
    the select query doesnt use the primary key fields and table already has around 19 million entries.So there was a secondary index created for the fields in the table.
    now, KONH is a client specific table, and hence has MANDT as the first field. when the table is not indexed it is sorted according to the order of fields, like first MANDT, then primary key fields and then remaining fields.. (correct me if i am wrong)
    but the secondary index created doesnt has MANDT in it..(yea, a mistake! )...
    but instead of correccting the secondary index, i am told to change the select query..
    so, i used a "client specific" syntax to sort the issue.. but i dont understand whre i should put the "where mandt eq sy-mandt" clause..
    should i put it right after all my secondary index fields are over? or what happens to the order of fields which are not present in the list of secondary index?
    kindaly help.
    thanx.

    Hi chinmay kulkarni,
    its better if you can ask concerned person to add MANDT field in your  index as well....
    Indexes and MANDT
    If a table begins with the mandt field, so should its indexes. If a table begins with mandt and an index doesn't, the optimizer might not use the index.
    Remember, if you will, Open SQL's automatic client handling feature. When select * from ztxlfa1 where land1 = 'US' is executed, the actual SQL sent to the database is select * from ztxlfa1 where mandt = sy-mandt and land1 = 'US'. Sy-mandt contains the current logon client. When you select rows from a table using Open SQL, the system automatically adds sy-mandt to the where clause, which causes only those rows pertaining to the current logon client to be found.
    When you create an index on a table containing mandt, therefore, you should also include mandt in the index. It should come first in the index, because it will always appear first in the generated SQL.
    Index: Technical key of a database table.
    Primary index: The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The primary index is created automatically when the table is created in the database.
    Secondary index: Additional indexes could be created considering the most frequently accessed dimensions of the table.
    Structure of an Index
    An index can be used to speed up the selection of data records from a table.
    An index can be considered to be a copy of a database table reduced to certain fields. The data is stored in sorted form in this copy. This sorting permits fast access to the records of the table (for example using a binary search). Not all of the fields of the table are contained in the index. The index also contains a pointer from the index entry to the corresponding table entry to permit all the field contents to be read.
    When creating indexes, please note that:
    An index can only be used up to the last specified field in the selection! The fields which are specified in the WHERE clause for a large number of selections should be in the first position.
    Only those fields whose values significantly restrict the amount of data are meaningful in an index.
    When you change a data record of a table, you must adjust the index sorting. Tables whose contents are frequently changed therefore should not have too many indexes.
    Make sure that the indexes on a table are as disjunctive as possible.
    (That is they should contain as few fields in common as possible. If two indexes on a table have a large number of common fields, this could make it more difficult for the optimizer to choose the most selective index.)
    For Example...
    SELECT KUNNR KUNN2 INTO TABLE T_CUST_TERR
    FROM KNVP CLIENT SPECIFIED
    WHERE MANDT = SY-MANDT " here MANDT shd be first
    AND KUNN2 IN S_TERR
    AND PARVW LIKE 'Z%'.
    Accessing tables using Indexes
    The database optimizer decides which index on the table should be used by the database to access data records.
    You must distinguish between the primary index and secondary indexes of a table. The primary index contains the key fields of the table. The primary index is automatically created in the database when the table is activated. If a large table is frequently accessed such that it is not possible to apply primary index sorting, you should create secondary indexes for the table.
    The indexes on a table have a three-character index ID. '0' is reserved for the primary index. Customers can create their own indexes on SAP tables; their IDs must begin with Y or Z.
    If the index fields have key function, i.e. they already uniquely identify each record of the table, an index can be called a unique index. This ensures that there are no duplicate index fields in the database.
    When you define a secondary index in the ABAP Dictionary, you can specify whether it should be created on the database when it is activated. Some indexes only result in a gain in performance for certain database systems. You can therefore specify a list of database systems when you define an index. The index is then only created on the specified database systems when activated
    Also pls have a look on below link
    http://www.sapfans.com/sapfans/forum/devel/messages/30240.html
    Hope it will solve your problem..
    Reward points if useful...
    Thanks & Regards
    ilesh 24x7

  • Select query performance improvement - Index on EDIDC table

    Hi Experts,
    I have a scenario where in I have to select data from the table EDIDC. The select query being used is given below.
      SELECT  docnum
              direct
              mestyp
              mescod
              rcvprn
              sndprn
              upddat
              updtim
      INTO CORRESPONDING FIELDS OF TABLE t_edidc
      FROM edidc
      FOR ALL ENTRIES IN t_error_idoc
      WHERE
      upddat GE gv_date1 AND
      upddat LE gv_date2 AND
      updtim GE p_time AND
      status EQ t_error_idoc-status.
    As the volume of the data is very high, our client requested to put up some index or use an existing one to improve the performance of the data selection query.
    Question:
    4.    How do we identify the index to be used.
    5.    On which fields should the indexing be done to improve the performance (if available indexes donu2019t cater to our case).
    6.    What will be the impact on the table performance if we create a new index.
    Regards ,
    Raghav

    Question:
    1.    How do we identify the index to be used.
    Generally the index is automatically selected by SAP (DB Optimizer )  ( You can still mention the index name in your select query by changing the syntax)
      For your select Query the second Index will be called automatically by the Optimizer, ( Because  the select query has u2018Updatu2019 , u2018uptimu2019 in the sequence before the u2018statusu2019 ) .
    2.    On which fields should the indexing be done to improve the performance (if available indexes donu2019t cater to our case).
    (Create a new Index with MANDT and the 4 fields which are in the where clause in sequence  )
    3.    What will be the impact on the table performance if we create a new index.
    ( Since the index which will be newly created is only the 4th index for the table, there shouldnu2019t be any side affects)
    After creation of index , Check the change in performance of the current program and also some other programs which are having the select queries on EDIDC ( Various types of where clauses preferably ) to verify that the newly created index is not having the negative impact on the performance. Additionally, if possible , check if you can avoid  into corresponding fields .
    Regards ,
    Seth

  • Select query in driver program for sapscript

    Hi All,
    I want to select buzei, zuonr,sgtxt,meins from bseg ,temp (a temporary variable of type p deciamls 2), tmp (another temporary variable) and dmbtr from HBSEG (a structure of type bseg) . under the cond
    koart ne 's' or
    xauto ne 'x' or
    buzid ne 't'.
    I have to write this select query usinf a WORKAREA . After this select query i give WRITE_FORM as i call there vairables in script.Its very urgent.
    thanks much

    Hi,
    You can use inner join. Consider this simple example.
    data : a type zvijirank occurs 10 with header line,
              b type zvijirank1 occurs 10 with header line.
    data : name like zvijirank-name,
           total like zvijirank1-total,
           reg_no like zvijirank.
    *       regno type i.
    data : begin of wa,
           name type zvijirank-name,
           total type zvijirank1-total,
           branch type zvijirank1-branch,
           reg_no type zvijirank-reg_no,
    *       FNAME TYPE ZVIJIRANK2-F_NAME,
    *       MNAME TYPE ZVIJIRANK2-M_NAME,
    *       CITY TYPE ZVIJIRANK2-CITY,
    *       TEL_NO TYPE ZVIJIRANK2-TEL_NO,
           end of wa.
    data : it like standard table of wa with header line,
             it1 like standard table of wa with header line.
    call selection-screen 9010.
    select a~name b~total b~branch a~reg_no into table it from zvijirank as a inner join zvijirank1 as b on a~reg_no = b~reg_no .
    loop at it.
    if it-reg_no eq regno.
    write : 'NAME   :', it-name,
            'REG_NO :', it-reg_no,
             'TOTAL :', it-total.
    ENDIF.
    endloop.
    Thanks,
    Reward If Helpful.

  • BSAD table is taking more time in select query.

    Hi ,
    The below SELECT query is taking more time , there is no any secondary index is there .
    Can anybody suggest how to improve it .
    SELECT bukrs
             kunnr
             augdt
             augbl
             gjahr
             belnr
             budat
             bldat
             waers
             xblnr
             BLART
             monat
             shkzg
             gsber
             DMBTR
             WRBTR
             prctr
             FROM  BSAD INTO TABLE gt_bsad
             WHERE  bukrs  = p_bukrs
             AND    kunnr  IN so_kunnr
             AND    budat  IN so_budat
             AND    xblnr  IN so_xblnr
             AND  ( blart  EQ 'DA' OR
                    blart  EQ 'DZ' OR
                    blart  EQ 'ZP' OR               "D03K904574
                    blart  EQ 'KZ' OR               "D03K904574
                    blart  EQ 'DP' )
             AND   PRCTR IN R_PC.
    Thanks in advance
    Regards
    chetan

    Hi Chetan ,
    I will suggest you two things :
    1. Try to add Secondary ( Non-unique) index on table BSAD with fields : mandt,bukrs,kunnr,budat,xblnr,blart,prctr.
        but before adding this index test the selectivity of this index by going to Tcode DB05
    2. In the select query you have used OR condition for blart. Instead of this try to create a ranges table for blart and append the  values 'DA','DZ','ZP','KZ','DP' and use this in the select query. This will improve the performance for sure.
    Hope this will help to ypu.
    Regards,
    Nikhil

  • Secondary Index Picked with one field short in select query

    Hi,
    We have a select query as follows
    select  single lgort       vgbel        vgpos
        into   (lips-lgort,lips-vgbel,lips-vgpos)
        from    lips
       where         vbeln          Eq p_zlcpp-vbeln
         and         matnr          Eq p_zlcpp-matnr
         and         charg          Eq p_zlcpp-charg
    The secondary index ZB has the fields as follows:
    MANDT     Client
    MATNR     Material Number
    CHARG     Batch Number
    BWART     Movement Type (Inventory Management)
    When seen in the trace it seems the select query picks this secondary index. Whether it is correct? since i find no BWART in the select query. Because of this index the query take large time. I used the Hint statement as follows:
    select  single lgort       vgbel        vgpos
        into   (lips-lgort,lips-vgbel,lips-vgpos)
        from    lips
       where         vbeln          Eq p_zlcpp-vbeln
         and         matnr          Eq p_zlcpp-matnr
         and         charg          Eq p_zlcpp-charg   %_HINTS ORACLE 'INDEX("LIPS" "LIPS~0")' .
    and it now works fast. Please advice the best way to make the select query work on itself without using the hint statement to pick the index LIPS~0 instead of the invalid secondary index ZB.
    Thanks & Regards,
    Selvakumar M.
    Edited by: Selva on Jun 17, 2011 7:35 PM

    Hello Selva,
    your problem here is the decision of the optimizer that does not exactly know the selectivity of the fields.
    If your deliveries are normally small (not too many items), then selecting via the document number will be relatively fast.
    And selecting via the material number + batch will be slow in case if many deliveries are having same product from the same batch delivered.
    I assume that the latest is the case in your system. That's why the selection with ZB index is slow.
    If the data distribution is as I described above, then your hint is quite OK and I advise you to stick to the hint.
    From my PoV this is the better solution rather changing the coding and throwing out MATNR field from the WHERE clause to filter later in ABAP.
    Another solution would be trying to play with histograms. But you'll need %SUBSTITUTE VALUES% or %SUBSTITUTE LITERALS% hint anyway, so I find your solution better.
    So, please stay with hint. Even SAP standard development does it for some select statements.
    Regards,
      Yuri

  • SELECT query takes too much time! Y?

    Plz find my SELECT query below:
    select w~mandt
    wvbeln wposnr wmeins wmatnr wwerks wnetwr
    wkwmeng wvrkme wmatwa wcharg w~pstyv
    wposar wprodh wgrkor wantlf wkztlf wlprio
    wvstel wroute wumvkz wumvkn wabgru wuntto
    wawahr werdat werzet wfixmg wprctr wvpmat
    wvpwrk wmvgr1 wmvgr2 wmvgr3 wmvgr4 wmvgr5
    wbedae wcuobj w~mtvfp
    xetenr xwmeng xbmeng xettyp xwepos xabart
    x~edatu
    xtddat xmbdat xlddat xwadat xabruf xetart
    x~ezeit
    into table t_vbap
    from vbap as w
    inner join vbep as x on xvbeln = wvbeln and
    xposnr = wposnr and
    xmandt = wmandt
    where
    ( ( werdat > pre_dat ) and ( werdat <= w_date ) ) and
    ( ( ( erdat > pre_dat and erdat < p_syndt ) or
    ( erdat = p_syndt and erzet <= p_syntm ) ) ) and
    w~matnr in s_matnr and
    w~pstyv in s_itmcat and
    w~lfrel in s_lfrel and
    w~abgru = ' ' and
    w~kwmeng > 0 and
    w~mtvfp in w_mtvfp and
    x~ettyp in w_ettyp and
    x~bdart in s_req_tp and
    x~plart in s_pln_tp and
    x~etart in s_etart and
    x~abart in s_abart and
    ( ( xlifsp in s_lifsp ) or ( xlifsp = ' ' ) ).
    The problem: It takes too much time while executing this statement.
    Could anybody change this statement and help me out to reduce the DB Access time?
    Thx

    Ways of Performance Tuning
    1.     Selection Criteria
    2.     Select Statements
    •     Select Queries
    •     SQL Interface
    •     Aggregate Functions
    •     For all Entries
    Select Over more than one internal table
    Selection Criteria
    1.     Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement. 
    2.     Select with selection list.
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Select Statements   Select Queries
    1.     Avoid nested selects
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
    2.     Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    3.     When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
    To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
    4.     For testing existence, use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. 
    SELECT * FROM SBOOK INTO SBOOK_WA
      UP TO 1 ROWS
      WHERE CARRID = 'LH'.
    ENDSELECT.
    The above code is more optimized as compared to the code mentioned below for testing existence of a record.
    SELECT * FROM SBOOK INTO SBOOK_WA
        WHERE CARRID = 'LH'.
      EXIT.
    ENDSELECT.
    5.     Use Select Single if all primary key fields are supplied in the Where condition .
    If all primary key fields are supplied in the Where conditions you can even use Select Single.
    Select Single requires one communication with the database system, whereas Select-Endselect needs two.
    Select Statements SQL Interface
    1.     Use column updates instead of single-row updates
    to update your database tables.
    SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
      SFLIGHT_WA-SEATSOCC =
        SFLIGHT_WA-SEATSOCC - 1.
      UPDATE SFLIGHT FROM SFLIGHT_WA.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    UPDATE SFLIGHT
           SET SEATSOCC = SEATSOCC - 1.
    2.     For all frequently used Select statements, try to use an index.
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE MANDT IN ( SELECT MANDT FROM T000 )
        AND CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    3.     Using buffered tables improves the performance considerably.
    Bypassing the buffer increases the network considerably
    SELECT SINGLE * FROM T100 INTO T100_WA
      BYPASSING BUFFER
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    The above mentioned code can be more optimized by using the following code
    SELECT SINGLE * FROM T100  INTO T100_WA
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    Select Statements  Aggregate Functions
    •     If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
    Some of the Aggregate functions allowed in SAP are  MAX, MIN, AVG, SUM, COUNT, COUNT( * )
    Consider the following extract.
                Maxno = 0.
                Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
                 Check zflight-fligh > maxno.
                 Maxno = zflight-fligh.
                Endselect.
    The  above mentioned code can be much more optimized by using the following code.
    Select max( fligh ) from zflight into maxno where airln = ‘LF’ and cntry = ‘IN’.
    Select Statements  For All Entries
    •     The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
         The plus
    •     Large amount of data
    •     Mixing processing and reading of data
    •     Fast internal reprocessing of data
    •     Fast
         The Minus
    •     Difficult to program/understand
    •     Memory could be critical (use FREE or PACKAGE size)
    Points to be must considered FOR ALL ENTRIES
    •     Check that data is present in the driver table
    •     Sorting the driver table
    •     Removing duplicates from the driver table
    Consider the following piece of extract
              Loop at int_cntry.
      Select single * from zfligh into int_fligh
      where cntry = int_cntry-cntry.
      Append int_fligh.
                          Endloop.
    The above mentioned can be more optimized by using the following code.
    Sort int_cntry by cntry.
    Delete adjacent duplicates from int_cntry.
    If NOT int_cntry[] is INITIAL.
                Select * from zfligh appending table int_fligh
                For all entries in int_cntry
                Where cntry = int_cntry-cntry.
    Endif.
    Select Statements Select Over more than one Internal table
    1.     Its better to use a views instead of nested Select statements.
    SELECT * FROM DD01L INTO DD01L_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND AS4LOCAL = 'A'.
      SELECT SINGLE * FROM DD01T INTO DD01T_WA
        WHERE   DOMNAME    = DD01L_WA-DOMNAME
            AND AS4LOCAL   = 'A'
            AND AS4VERS    = DD01L_WA-AS4VERS
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.
    The above code can be more optimized by extracting all the data from view DD01V_WA
    SELECT * FROM DD01V INTO  DD01V_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT
    2.     To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    3.     Instead of using nested Select loops it is often better to use subqueries.
    SELECT * FROM SPFLI
      INTO TABLE T_SPFLI
      WHERE CITYFROM = 'FRANKFURT'
        AND CITYTO = 'NEW YORK'.
    SELECT * FROM SFLIGHT AS F
        INTO SFLIGHT_WA
        FOR ALL ENTRIES IN T_SPFLI
        WHERE SEATSOCC < F~SEATSMAX
          AND CARRID = T_SPFLI-CARRID
          AND CONNID = T_SPFLI-CONNID
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    The above mentioned code can be even more optimized by using subqueries instead of for all entries.
    SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                         WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    1.     Table operations should be done using explicit work areas rather than via header lines.
    READ TABLE ITAB INTO WA WITH KEY K = 'X‘ BINARY SEARCH.
    IS MUCH FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY K = 'X'.
    If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
    2.     Always try to use binary search instead of linear search. But don’t forget to sort your internal table before that.
    READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
    3.     A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
    4.     A binary search using secondary index takes considerably less time.
    5.     LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
    LOOP AT ITAB INTO WA WHERE K = 'X'.
    ENDLOOP.
    The above code is much faster than using
    LOOP AT ITAB INTO WA.
      CHECK WA-K = 'X'.
    ENDLOOP.
    6.     Modifying selected components using “ MODIFY itab …TRANSPORTING f1 f2.. “ accelerates the task of updating  a line of an internal table.
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
    The above code is more optimized as compared to
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1.
    7.     Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
    Modifying selected components only makes the program faster as compared to Modifying all lines completely.
    e.g,
    LOOP AT ITAB ASSIGNING <WA>.
      I = SY-TABIX MOD 2.
      IF I = 0.
        <WA>-FLAG = 'X'.
      ENDIF.
    ENDLOOP.
    The above code works faster as compared to
    LOOP AT ITAB INTO WA.
      I = SY-TABIX MOD 2.
      IF I = 0.
        WA-FLAG = 'X'.
        MODIFY ITAB FROM WA.
      ENDIF.
    ENDLOOP.
    8.    If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
    LOOP AT ITAB1 INTO WA1.
      READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
      IF SY-SUBRC = 0.
        ADD: WA1-VAL1 TO WA2-VAL1,
             WA1-VAL2 TO WA2-VAL2.
        MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
      ELSE.
        INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
      ENDIF.
    ENDLOOP.
    The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
    LOOP AT ITAB1 INTO WA.
      COLLECT WA INTO ITAB2.
    ENDLOOP.
    SORT ITAB2 BY K.
    COLLECT, however, uses a hash algorithm and is therefore independent
    of the number of entries (i.e. O(1)) .
    9.    "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”
    APPEND LINES OF ITAB1 TO ITAB2.
    This is more optimized as compared to
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    10.   “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
    This is much more optimized as compared to
    READ TABLE ITAB INDEX 1 INTO PREV_LINE.
    LOOP AT ITAB FROM 2 INTO WA.
      IF WA = PREV_LINE.
        DELETE ITAB.
      ELSE.
        PREV_LINE = WA.
      ENDIF.
    ENDLOOP.
    11.   "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “  DO -DELETE-ENDDO”.
    DELETE ITAB FROM 450 TO 550.
    This is much more optimized as compared to
    DO 101 TIMES.
      DELETE ITAB INDEX 450.
    ENDDO.
    12.   Copying internal tables by using “ITAB2[ ] = ITAB1[ ]” as compared to “LOOP-APPEND-ENDLOOP”.
    ITAB2[] = ITAB1[].
    This is much more optimized as compared to
    REFRESH ITAB2.
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    13.   Specify the sort key as restrictively as possible to run the program faster.
    “SORT ITAB BY K.” makes the program runs faster as compared to “SORT ITAB.”
    Internal Tables         contd…
    Hashed and Sorted tables
    1.     For single read access hashed tables are more optimized as compared to sorted tables.
    2.      For partial sequential access sorted tables are more optimized as compared to hashed tables
    Hashed And Sorted Tables
    Point # 1
    Consider the following example where HTAB is a hashed table and STAB is a sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    This runs faster for single read access as compared to the following same code for sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE STAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    Point # 2
    Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
    LOOP AT STAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.
    This runs faster as compared to
    LOOP AT HTAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.

Maybe you are looking for

  • Resource Related Billing - DP81/82/DP91 - Exit to transfer pricing fields

    Dear SAP Experts, I'm facing this requirement where by I needed to push some information from a custom field in a WBS Project into Quotations and Billing Requests created during DP81/DP82 and DP91. These fields will then be a parameter for pricing an

  • Weird Behaviour on Catalyst 2950

    Dear all, Need your comment in this problem. Yesterday , while users were connected to the network,suddenly they experienced a drop of connection ; i.e they were disconnected from the network.Upon observation, we realised that the 2950 catalyst switc

  • Before updating to Maverick?

    i dont have a external HD do i need to do  complete  external back up of my Imac HD before updating to maverick? is it risky to loose some date if not doing it Imac 2,4 Ghz intel core 2 duo 2 Go RAM running on 10,6,8 thanks

  • Adobe reader version suitable for ipad 1 free download

    I need acrobat on my ipad 1. Which version can be downloaded successfully. Pl guide.

  • Help with Cluster install

    I installed obiee 11g on a server1. There was a sql server installed on port 7001. So, the admin server was installed on port 7002. Now, I can access the EM,Console from port 7002. Now, i want to install to do a cluster installation on server2. The a