Need to Improve  pefromance for select statement using MSEG table

Hi all,
We are using a select statement using MSEG table
which takes a very long time to run the program which is scheduled in back ground.
Please see the history below.;
1) Previously this program was using SELECT-ENDSELECT statement inside the loop i.e.
LOOP AT I_MCHB.
To get Material Doc. Details
      SELECT MBLNR
             MJAHR
             ZEILE INTO (MSEG-MBLNR,MSEG-MJAHR,MSEG-ZEILE)
             UP TO 1 ROWS
             FROM MSEG
            WHERE CHARG EQ I_MCHB-CHARG
             AND  MATNR EQ I_MCHB-MATNR
             AND  WERKS EQ I_MCHB-WERKS
             AND  LGORT EQ I_MCHB-LGORT.
      ENDSELECT.
Endloop.
The program was taking 1 hr  for  20 k data
2)The above statement was replaced by ALL ENTRIES to remove the SELECT-ENDSELECT from the loop.
***GET MATERIAL DOC NUMBER AND FINANCIAL YEAR DETAILS FROM MSEG TABLE
    SELECT MBLNR
           MJAHR
           ZEILE
           MATNR
           CHARG
           WERKS
           LGORT
               INTO TABLE I_MSEG
               FROM   MSEG
               FOR ALL ENTRIES IN I_MCHB
               WHERE CHARG EQ I_MCHB-CHARG
               AND   MATNR EQ I_MCHB-MATNR
               AND   WERKS EQ I_MCHB-WERKS
               AND   LGORT EQ I_MCHB-LGORT.
3)After getting the further technical analysis from BASIS team , And with the suggestion to optimize the program by changing the INDEX RANGE SCAN to
       MSEG~M.
SELECT MBLNR
           MJAHR
           ZEILE
           MATNR
           CHARG
           WERKS
           LGORT
               INTO TABLE  I_MSEG
               FROM   MSEG
               FOR ALL ENTRIES IN I_MCHB
               WHERE MATNR EQ I_MCHB-MATNR
               AND   WERKS EQ I_MCHB-WERKS
               AND   LGORT EQ I_MCHB-LGORT.
At present the program is taking 3 to 4 hrs in back ground .
The table is complete table scan using index
MSEG~M.
Please suggest to improve the performance of this
many many thanks
deepak

The benchmark should be the join, and I can not see how any of your solutions can be faster than the join
SELECT   .....
              INTO TABLE  ....
              UP TO 1 ROWS
              FROM mchb as a
              INNER JOIN mseg as b
              ON    amatnr EQ bmatnr
              AND  awerks  EQ bwerks
              AND  algort    EQ blgort
              And   acharg  EQ bcharg
              WHERE a~ ....
The WHERE condition must come from the select on MCHB, the field list from the total results
you want.
If you want to compare, must compare your solutions plus the select to fill I_MCHB.
Siegfried
Edited by: Siegfried Boes  on Dec 20, 2007 2:28 PM

Similar Messages

  • Performance tunning for select statements using likp lips and vbrp

    Dear all,
      I have a report where i am using select statements using first on likp the for all entries of likp  i am taking data from lips and then for all entries in lips i am taking data from vbrp by matching VGBEL and VGPOS. Now the problem is that when it fetches data from vbrp it is taking lot of time around 13mins. to fetch data from vbrp. How can i overcome the problem.
    regards
    Amit

    Hi,
    there is also no secondary index for preceding document in VBFA table.
    You will also have to create it here.
    Regards,
    Przemysław

  • How to get accurate values for select statement using single column

    Hi All,
    Below is my query which runs fine
    Select Distinct Top 4
    FiscalYearId,
    FiscalMonthOfYearId
    From ODS.Common.tODS_Date
    Inner Join
    UTL.Utility.tUTL_ProcessDate
    On tODS_Date.DateShort < tUTL_ProcessDate.ProcessDate
    And tUTL_ProcessDate.DatabaseName = 'ODS'
    Order By
    FiscalYearId Desc,
    FiscalMonthOfYearId Desc
    Below is the generate output
    FiscalYearId FiscalMonthOfYearId
    2014 2
    2014 1
    2013 12
    2013 11
    But i want to use this query in one of my where clause condition as its being used in the where clause it can only return 1 row.So, i tried something like this
    Select Distinct Top 4
    FiscalMonthOfYearId
    From ODS.Common.tODS_Date
    Inner Join
    UTL.Utility.tUTL_ProcessDate
    On tODS_Date.DateShort < tUTL_ProcessDate.ProcessDate
    And tUTL_ProcessDate.DatabaseName = 'ODS'
    Order By
    FiscalMonthOfYearId Desc
    And the result set of this one gives me the output like
    FiscalMonthOfYearId
    12
    11
    10
    9
    Which is not correct,( if you see the result set above). 
    Can someone please help me with any ides on this.

    If you want to use this query in the WHERE clause, then use it with EXISTS option which allows to return more than 1 column. 
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to improve Performance for Select statement

    Hi Friends,
    Can  you please help me in improving the performance of the following query:
    SELECT SINGLE MAX( policyterm ) startterm INTO (lv_term, lv_cal_date) FROM zu1cd_policyterm WHERE gpart = gv_part GROUP BY startterm.
    Thanks and Regards,
    Johny

    long lists can not be produced with  a SELECT SINGLE, there is also nothing to group.
    But I guess the SINGLE is a bug
    SELECT MAX( policyterm ) startterm
                  INTO (lv_term, lv_cal_date)
                  FROM zu1cd_policyterm
                  WHERE gpart = gv_part
                  GROUP BY startterm.
    How many records are in zu1cd_policyterm ?
    Is there an index starting with gpart?
    If first answer is 'large' and second 'no'   =>   slow
    What is the meaning of gpart?  How many different values can it assume?
    If many different values then an index makes sense, if you are allowed to create
    an index.
    Otherwise you must be patient.
    Siegfried

  • Select statement using BSEG table

    Hello SAPinas,
    I am using the following lines of code in one of my program. Becuase of that code I am getting Performance issue.
    Note : BSEG is Cluster Table.
    Could you please help me how I will use in another way
    loop at t_hdr.
        select buzei buzid koart shkzg mwskz dmbtr hwbas sgtxt vbund kostl
               aufnr anln1 anln2 hkont kunnr lifnr matnr werks ebeln ebelp
               zekkn rewrt prctr txjcd projk
        into (t_item-buzei, t_item-buzid, t_item-koart, t_item-shkzg,
              t_item-mwskz, t_item-dmbtr, t_item-hwbas, t_item-sgtxt,
              t_item-vbund, t_item-kostl, t_item-aufnr, t_item-anln1,
              t_item-anln2, t_item-hkont, t_item-kunnr, t_item-lifnr,
              t_item-matnr, t_item-werks, t_item-ebeln, t_item-ebelp,
              t_item-zekkn, t_item-rewrt, t_item-prctr, t_item-txjcd,
              t_item-projk)
        from bseg
       where bukrs  = t_hdr-bukrs
         and belnr  = t_hdr-belnr
         and gjahr  = t_hdr-gjahr
         and hkont in s_hkont
         and mwskz in s_mwskz
         and kostl in s_kostl
         and prctr in s_prctr
         and werks in s_werks.
    Skip record if not in selection screen range for state
          check t_item-txjcd(2) in s_state.
          if t_item-shkzg  = c_debit.  "S
          endif.
          if t_item-shkzg  = c_credit. "H
            t_item-dmbtr = t_item-dmbtr * ( -1 ).
            t_item-rewrt = t_item-rewrt * ( -1 ).
            t_item-hwbas = t_item-hwbas * ( -1 ).
          endif.
    **&MWB 04/08/2005 ... add additional US Bayer Tax dept requested fields
          clear: t_item-basetax, t_item-accrtax, t_item-vendtax,
                 t_item-taxrate, t_item-invbase, t_item-invtax.
    **&MWB ... end insert 04/08/2005
          clear t_item-hwbas.
          move-corresponding t_hdr to t_item.
          append t_item.
          clear  t_item.
        endselect.
      endloop.
    Thank you very much Advance.............:-)

    As BSEG is in a cluster table RFBLG, the only index available is the primary one, so only BUKRS, BELNR and GJAHR keys are actually available. So for other criteria resolution, the program will read the whole cluster, unpacking the records and executing the selection. When most criteria come from BKPF header, you may select from BKPF and then from BSEG using the full key of the cluster, and using a [FOR ALL ENTRIES|http://help.sap.com/abapdocu/en/ABENOPEN_SQL_PERFO.htm] IN a table with the keys from BKPF.
    Try to use one or more of the secondary indexes provide by SAP
    - BSAD Accounting: Secondary Index for Customers (Cleared Items)
    - BSAK Accounting: Secondary Index for Vendors (Cleared Items)
    - BSAS Accounting: Secondary Index for G/L Accounts (Cleared Items)
    - BSID Accounting: Secondary Index for Customers
    - BSIK Accounting: Secondary Index for Vendors
    - BSIM Secondary Index, Documents for Material
    - BSIS Accounting: Secondary Index for G/L Accounts
    These indexes are actual tables, so you may create/use indexes, they are also easily appended, as they are filled via move-corresponding statements.
    Try a little search at sdn on keywords like [BSEG, cluster and performance|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=bsegclusterperformance&adv=false&sortby=cm_rnd_rankvalue].
    Regards

  • Select statement using 2 tables

    Hi Experts,
    In the following code, i have to select "v_likp-charg" into the "concatenate" statement.
    could you please let me know, how can i do that.
    help is appreciated,
    code:
    <b>data: i_kna1 type t_kna1 occurs 0,
          v_kna1 type t_kna1,
          i_likp type t_likp occurs 0,
          v_likp type t_likp.
    data: begin of t_kna1,
            kunnr like kna1-kunnr,
            name1 like kna1-name1,
           end of t_kna1.
    data: begin of t_likp,
            matnr like likp-matnr,
            charg like likp-charg,
            kunnr like likp-kunnr,
          end of t_likp.
    data: begin of v_output,
             record(500),
          end of v_ouput.
    loop at i_kna1 into v_kna1.
    concatenate: v_kna1-kunnr
                 v_kna1-name1
    i want "v_likp-charg" to be here..******
          into v_output seperated by c_tab.
    append v_ouput.</b>
    thanks,

    You need to make a connection to the customer master file.  In this case, you will have a 1 to many relationship with KNA1 and LIKP.  Do you want to output only one record for each customer number?
    Assuming that you already have the v_likp internal table, you can just read it with key.
    loop at i_kna1 into v_kna1.
    clear v_likp.
    read table i_likp into v_likp with key kunnr = v_kna1-kunnr.
    concatenate: v_kna1-kunnr
    v_kna1-name1
    v_likp-charg
        into v_output seperated by c_tab.
    append v_ouput.
    Regards,
    Rich Heilman

  • 'Missing select' error for update statement using WITH clause

    Hi,
    I am getting the below error for update statement using WITH clause
    SQL Error: ORA-00928: missing SELECT keyword
      UPDATE A
      set A.col1 = 'val1'
         where
      A.col2 IN (
      WITH D AS
      SELECT col2 FROM
      (SELECT col2, MIN(datecol) col3 FROM DS
      WHERE <conditions>
        GROUP BY PATIENT) D2
      WHERE
      <conditions on A.col4 and D2.col3>

    Hi,
    The format of a query using WITH is:
    WITH  d  AS
        SELECT  ...  -- sub_query
    SELECT  ...   -- main query
    You don't have a main query.  The keyword FROM has to come immediately after the right ')' that ends the last WITH clause sub-query.
    That explains the problem based on what you posted.  I can't tell if the real problem is in the conditions that you didn't post.
    I hope this answers your question.
    If not, post a complete test script that people can run to re-create the problem and test their ideas.  Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Dynamic sql for select statement

    Hi,
    Please help me with the below code:
    It is updating null if the select statment returns one values. If it fetches multiple values then it throughs the below error msg when running the program.
    Please let me know how to modify the below code. Or let me know is there anyother way to write this code.
    Logic for development:
    * View name should be passed as dynamic.
    CREATE OR REPLACE
    PROCEDURE "PKEP_LOAD_SO_EU" (p_var1 IN VARCHAR2)
    IS
    lv_sql VARCHAR2 (4000);
    lv_name VARCHAR2 (20);
    BEGIN
    lv_sql :=
    ' SELECT DISTINCT LEVEL2
    FROM BIIO_SALES_OB_IMPORT_'|| p_var1;
    EXECUTE IMMEDIATE lv_sql
    INTO lv_name;
    BEGIN
    UPDATE BIIO_SALES_OB_IMPORT_NA2 --table name for updation
    SET SOB_1 = NULL,
    SOB_DATE_1 = NULL
    WHERE level2 = lv_name; -- validation ( eg. Select distinct level2 from biio_sales_ob_import_'||p_var1)
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line (SQLERRM);
    NULL;
    END;
    END;
    BEGIN
    PKEP_LOAD_SO_EU ('NA1');
    end;
    Error report:
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at "DEMANTRA.PKEP_LOAD_SO_EU", line 11
    ORA-06512: at line 2
    01422. 00000 - "exact fetch returns more than requested number of rows"
    *Cause:    The number specified in exact fetch is less than the rows returned.
    *Action:   Rewrite the query or change number of rows requested
    Thanks.
    Padma

    Padu wrote:
    Please let me know whether is anyother way to write this code as im a beginner for SQl.You dont need to have a seperate SELECT statement. Just a single UPDATE will do the job for you.
    create or replace procedure pkep_load_so_eu
       p_var1 in varchar2
    as
    begin
       lSql := ' update biio_sales_ob_import_na2               ' ||
               '    set sob_1      = null                    ' ||
            '      , sob_date_1 = null                    ' ||
            '  where level2 in (                         ' ||
            '                    select level2               ' ||
            '                      from biio_sales_ob_import_'       || p_var1 ||
       execute immediate lSql;
    end;

  • Timesten create a lock for select statement through sqldev

    When use ttisql connect to TimesTen Release 7.0.6.15.0 at autocommit=1, there is no lock for select statement.
    but when I use sql developer (driver is ttjdbc5.jar, regardless of version) to connect, even with autocommit=1, there will be locks for select statement.
    Is it a bug? How can I achieve the same no locks for select statement through sql developer?Thanks.

    -your update tells me that you are connected to a remote timesten data store using the client driver
    -the ttXactAdmin output indicates that SqlNavigator has a shared lock on the database itself: this will not interfere with anybody else' read operations, and I believe that until such time as you actually attempt some kind of DML against the data store that th IX lock on the database lock will not interfere with any other DML either.
    -a shared database lock will always be acquired for any transaction in TimesTen. You can test this for yourself from ttisql: set autocommit off, perform a simple update and do not commit the transaction. Then open a separate session and execute ttxactadmin - you will the IX database lock as well as the various locks on tables and indexes.
    -I believe this pretty much proves my original thinking: that sqlDeveloper attaches to TimesTen in transaction mode. However, the IX lock on the database will not interfere with anybody else's work and should not be a problem.

  • WHAT ABOUT FACE TIME?  I'D LIKE TO KNOW IF YOU NEED A PHONE NUMBER FOR YOURSELF TO USE IT TO CALL FROM YOUR COMPUTER

    WHAT ABOUT FACE TIME?  I'D LIKE TO KNOW IF YOU NEED A PHONE NUMBER FOR YOURSELF TO USE IT TO CALL FROM YOUR COMPUTER

    Do you have iMessage? I think as long as that person has iMessage you can use Face Time to call each other.

  • Where all we not needed  ENDSELECT ... in select statements.

    explain the scenarios...

    Hi,
    It is always advised to avoid using ENDSELECT statment and it can be avoided also.
    For example:
    when you want to get data into internel table with a SELECT query, use <b>TABLE</b> keyword before internal table name.
    OR if you want to get data into a work area then,
    Use <b>SELECT SINGLE</b> statment.
    Regards,
    Amit

  • Create new tag for selected text using API?

    Hello,
    I want to add new tag for the selected text just like 'Create Tag from selection' .
    is it possible to create tag for selected text using acrobat api?
         please,help me.

    As per sample of snippetRunner for adding tag for selected text.
    I tried below code
    PDPage pg;
    AVDoc avDoc = AVAppGetActiveDoc();
    PDDoc pd = AVDocGetPDDoc(avDoc);
        pg = PDDocAcquirePage(pd, 0);
    ASAtom theSelectionType = AVDocGetSelectionType(avDoc);
    if (theSelectionType == ASAtomFromString("Text")){
        PDTextSelect ts = static_cast<PDTextSelect>(AVDocGetSelection(avDoc));
        PDSTreeRoot pdsTreeRoot;
        CosObj pageObj = PDPageGetCosObj (pg);
        PDSElement newElem;
        PDSElementCreate(pd, &newElem);
        char buf1[64];
        strcpy (buf1, "A new structure element");
        // set its type as "Document" standard type
        PDSElementSetType(newElem, ASAtomFromString ("Document"));
        // set its title
        PDSElementSetTitle(newElem, reinterpret_cast<const ASUns8*> (buf1), strlen(buf1));
        PDSTreeRootInsertKid (pdsTreeRoot, aElem, kPDSAfterLast);
        PDSElementInsertMCAsKid // here something i have to add
    If i have PDTextSelect how i can add tag for selected text.like user add tag using "CreateTagForSelectedText" option.
    please,help me.
    thanks.

  • How to write SELECT statement using tables ekko,ekpo and eket?

    Hi,
    I got a problem in  performance tuning using below tables?
    how to write SELECT statement using tables EKKO,EKPO and EKET and in conditon ( WHERE clause)  use only fields 
                        ekko~ebeln       IN ebeln
                       ekko~loekz       EQ ' '
                       ekko~lifnr       IN lifnr
                       ekko~ekorg       IN ekorg
                      ekko~ekgrp       IN ekgrp          
                       ekpo~werks       IN werks
                       ekpo~pstyp       EQ  '3'
                       ekpo~loekz       EQ  space
                       ekpo~elikz       EQ  space
                       ekpo~menge       NE  0
                     eket~rsnum       NE space.
    Thanks in Advance.
    bye.

    Hi,
    ekko~ebeln IN ebeln
    ekko~loekz EQ ' '
    ekko~lifnr IN lifnr
    ekko~ekorg IN ekorg
    ekko~ekgrp IN ekgrp
    ekpo~werks IN werks
    ekpo~pstyp EQ '3'
    ekpo~loekz EQ space
    ekpo~elikz EQ space
    ekpo~menge NE 0          " Remove this from where clause
    eket~rsnum NE space.    " Remove this from where clause
    ' instead delete the entries after fetching into the table
    DELETE it_itab WHERE menge EQ '0' AND rsnum EQ ' '.
    Regards
    Bala Krishna

  • Hello, I bought my iphone in japan. And now I'm in Brazil and I use it here, I need the unlock code for me to use here. please

    Hello, I bought my iphone in japan. And now I'm in Brazil and I use it here, I need the unlock code for me to use here. please

    williamjapa wrote:
    Hello, I bought my iphone in japan. And now I'm in Brazil and I use it here, I need the unlock code for me to use here. please
    Only the carrier to which the phone is locked can authorize an unlock. None of the Japanese carriers will do that. Sell the phone and buy one that works in Brazil.

  • I would like to take excel classes / tutorials (intermediate to advanced) and practice on this computer. Could someone clarify, what software and operating system is needed? Can I just use numbers? Do I need to download Excel for Macs and use Camp Boot?

    I would like to take excel classes / tutorials (intermediate to advanced) and practice on this computer. Could someone clarify, what software and operating system is needed? Can I just use numbers? Do I need to download Excel for Macs and use Camp Boot?

    Numbers is a joke compared to Excel. If I were you I would find a class/tutorial first, find out what they use (and it won't be Numbers) and see if you need the Mac or Windows version of Excel. Note that Excel is not sold as a seperate product from the Microsoft Office suites.
    Clinton

Maybe you are looking for