Optimization of Join statement between MKPF and MSEG table for improving pe

Hi All,
I had a issue where we are executing one custom report and it is getting timed out after 45 minutes. We further executed with trace on and got to the conclusion with the help of BASIS that about 42 minutes of the 45 minutes tracetime are spent by a join over the tables  MKPF en MSEG.
This join is done by the abap statement:
  SELECT mkpf~mblnr
         mkpf~mjahr
         mkpf~bldat
         mkpf~blart
         mseg~matnr
         mseg~werks
    INTO CORRESPONDING FIELDS OF TABLE i_matdoc_we
    FROM mkpf INNER JOIN mseg ON mkpfmblnr = msegmblnr
                             AND mkpfmjahr = msegmjahr
FOR ALL entries IN i_list
   WHERE mkpf~mblnr BETWEEN lv_interval-fromnumber
                        AND lv_interval-tonumber
     AND mkpf~blart = 'WE'
     AND mkpf~bldat LE gv_last_day_fisc_period
     AND mseg~matnr = i_list-matnr
     AND mseg~werks IN s_werks.
Here, I_LIST comprises of stock for specific period as entered in the selection screen for that particular Material and plant
LV_INTERVAL is range of all goods receipts for material and gv_last_day_fisc_period is current date.
During the tracetime this statement was executed  more than 20.000 times, until the transaction timed out.
The individual executions of this select stmnt  varied (roughly) between 50 and 1200 miliseconds. (depends wheter the requested database block is in the buffercache or must be read from disk).
The acesspath used to execute the query ( see below) is optimal, given the present indexes.
Index MSEG~M is covering al the specified selection criteria for  MSEG.
Index MKPF-0 is used  to search the specified MBLNR criterium in MKPF.
The  remaining selection criteria MKPF-BLART and MKPF-BLDAT are not indexed, and imho this would also not make sense for this query.
BLART has only 3 different values n the MKPF table, and the selected value 'WE' has more than 1 million occurences.
BLDAT is selected with =<20110903, so this is not distinctive as well.
Can any one suggest some better way to write this query.
Regards,
Subhajit

Actually there are 2 select statements where JOIN have been introduced and especially the time out is occurring in the second JOIN.
Find all goods receipts for material
  PERFORM get_number_range_matdoc USING '03'
                               CHANGING lv_interval.
  SELECT mkpf~mblnr
         mkpf~mjahr
         mkpf~bldat
         mkpf~blart
         mseg~matnr
         mseg~werks
    INTO CORRESPONDING FIELDS OF TABLE i_matdoc_we
    FROM mkpf INNER JOIN mseg ON mkpfmblnr = msegmblnr
                             AND mkpfmjahr = msegmjahr
FOR ALL entries IN i_list
   WHERE mkpf~mblnr BETWEEN lv_interval-fromnumber
                        AND lv_interval-tonumber
     AND mkpf~blart = 'WE'
     AND mkpf~bldat LE gv_last_day_fisc_period
AND mseg~matnr = i_list-matnr
    AND mseg~werks IN s_werks.
  CLEAR lv_interval.
  PERFORM get_number_range_matdoc USING '02'
                               CHANGING lv_interval.
Find all goods issues for material
  SELECT mkpf~mblnr
         mkpf~mjahr
         mkpf~bldat
         mkpf~blart
         mseg~matnr
         mseg~werks
    INTO CORRESPONDING FIELDS OF TABLE i_matdoc_wa
    FROM mkpf INNER JOIN mseg ON mkpfmblnr = msegmblnr
                             AND mkpfmjahr = msegmjahr
FOR ALL entries IN i_list
   WHERE mkpf~mblnr BETWEEN lv_interval-fromnumber
                        AND lv_interval-tonumber
     AND ( mkpfblart = 'WA' OR mkpfblart = 'WI' )
     AND mkpf~bldat LE gv_last_day_fisc_period
AND mseg~matnr = i_list-matnr
     AND mseg~bwart NE '561'
     AND mseg~bwart NE '562'
     AND mseg~bwart NE '961'
AND mseg~bwart NE '962'
AND mseg~werks IN s_werks.
Mainly the second JOIN is creating the problem... In the backend ORACLE is being used as database.
Please suggest how I can improve the performance of these joins as its taking more than 45 mins..

Similar Messages

  • MKPF and MSEG table

    What is diff between MKPF and MSEG table ?

    Dear Balaji,
    In MKPF you will get to know the transaction code which was used for posting the material document.
    In MSEG,you will get to know the the item details from which it was posted along with the quantity and amount in LC.
    Regards
    Mangalraj.S

  • Relation between BKPF and EKBE table for reversing document?

    Is there any relation between BKPF and EKBE table for reversing document when STBLG is blank in BKPF.
    AND
    How to differentiate Old Accounting document / Reverse document / New document when in BKPF-STBLG is blank for all three document and BKPF-XBLNR are same for all.

    Hi Varun,
    Table Document no (BKPF-BELNR) is link between Material document no (EKBE-BELNR). If you are looking for validating Material reversal document then please use following logic for your requirement.
    Material Document (MBLNR) & Material Document Year (MJAHR). Pass material document (MBLNR) to MSEG-SMBLN to read MSEG-MBLNR with MSEG-MJAHR to MSEG-SJAHR, if record found delete both the documents i.e. MSEG-SMBLN & MSEG-MBLNR (donu2019t consider these documents in the logic) and display Material Document No. (MSEG-MBLNR)
    Regards,
    Santosh

  • Joins query between itab and database table..

    Hi all,
    Is it posible to use joins query between internle table and data base table...

    Hi Mehboob,
    No thats impossible to join the internal table and the database table.
    Alternatively what you need to do is you need to execute a Queryin Database Table and use the For All Entries in itab.
    Eg:  Select * from marc into table it_marc
             for all entries in it_matnr
               where matnr = it_matnr-matnr.
    Thanks,
    Chidanand

  • Relation between PLAF and MSEG

    Hi
    Can anyone provide me with a relation between PLAF and MSEG table
    Thanks
    VRV

    HI VRV,
    I don't know if you have already got the response to your query. But for your requirement, i believe you should be looking at PLAF & tables like AFKO, AFPO, AFRU.
    AFKO is order header, AFPO for the order details & AFRU for the confirmations.
    From the PLAF you can get planned order details, from the others you can get the order & qty which has been converted to production order, the qty which has been confirmed.
    Have a look at these tables & if you need any further inputs, message back & will try my best to be of some help.
    Regards,
    Vivek

  • Join between hz_cust_site_uses_all and pa_agreements_all table

    What is the joining condition between hz_cust_site_uses_all and pa_agreements_all table? How hz_cust_site_uses_all and pa_agreements_all table can be joined?

    Hi,
    What happens if you simply use a DISTINCT clause, something like:
    SELECT DISTINCT pa.customer_id ,hcs.cust_acct_site_id
               FROM hz_cust_acct_sites_all hca,
              hz_cust_site_uses_all hcs,pa_agreements_all pa
              WHERE hcs.cust_acct_site_id = hca.cust_acct_site_id
            AND hca.cust_account_id       = pa.customer_id
    Thanks &
    Best Regards,

  • Link b/w QALS and MSEG TABLE

    hi,
    i want to make a link up between QALS AND MSEG table as i want to those inspection lot which have the UD = REJECTED and stored in SC01 etc storage locations. Till now i am able to find that the Item which are rejected having material documents present in the MSEG table but not present in QALS.
    I had tried to make a link up with fields such as MATRN,CHARG,KDAUF, KDPOS etc.. but the right data is not displayed in it.
    Please provide me guidelines to solve this problem.

    this i Functional question asked at wrong place .
    but i will gice you the relation :
    MSEG: Document Segment: Material
    Fields:      MBLNR
         MJAHR                               
         ZEILE
    Relation :
    MATNR      EBELN     EBELP  MJAHR MBLNR                         
    QALS:  Inspection lot record
    Fields:      PRUEFLOS
    can use this table also
    QAVE:  Inspection processing
    Fields:      PRUEFLOS
                    KZART
         ZAEHLER
    rgds aryan
    Edited by: Aryan@sap on Jun 4, 2009 8:21 AM

  • Info about mkpf and mseg

    I need to modify a report that brings all the production of all our materias for a given period of time.
    The code joins both tables mkpf and mseg and ask for the date:
    mkpf-budat between s_budat-low and s_budat-high
    This query is taking A LOT of time and I need to optimize it. All of the fields needed are in the mseg, but the date is in mkpf. In mseg there is a field called production date (hdat) Is this field the same than the budat located in mkpf (I want to query only one table)?  If not, what do I have to do to optimize my query????
    TIA
    Query:
    select smblnr smjahr sbwart smatnr swerks smenge  
    appending  corresponding fields of table t_mseg  
    from  mseg as s inner join mkpf as k             
    on smblnr = kmblnr and                       
    smjahr = kmjahr                           
    where                                           
    ( sbwart eq lit_101 or sbwart eq lit_102 )
    and s~matnr in s_matnr                          
    and s~werks in s_werks_full                     
    and k~budat between s_budat-low and s_budat-high
    and s~bukrs = p_bukrs.

    Well MSEG has an index on MATNR and WERKS. Try changing the order of the where:
    select s~mblnr s~mjahr s~bwart s~matnr s~werks s~menge
    appending corresponding fields of table t_mseg
    from mseg as s inner join mkpf as k
    on s~mblnr = k~mblnr and
    s~mjahr = k~mjahr
    where s~matnr in s_matnr
    and s~werks in s_werks_full
    and ( s~bwart eq lit_101 or s~bwart eq lit_102 )
    and k~budat between s_budat-low and s_budat-high
    and s~bukrs = p_bukrs.
    Also - make sure s_matnr is not empty.
    Also make sure s_matnr is either 'I'ncluding either ranges or single values. Indexes don't work very well with 'E'xcluding, patterns or NE.
    Rob
    Message was edited by: Rob Burbank

  • Join condition between PO_REQUISITION_HEADERS_ALL and WF_NOTIFICATIONS

    Hi,
    Could anyone tell me what is the join condition between PO_REQUISITION_HEADERS_ALL and WF_NOTIFICATIONS?
    I joined these two tables by WF_NOTIFICATIONS.ITEM_KEY = PO_REQUISITION_HEADERS_ALL .WF_ITEM_KEY.But I cannot found some approved requisitions item key in WF_NOTIFICATIONS table.
    Please help.
    I paste my query below:
    SELECT PRH.ORG_ID ORG_ID,
    WF.ITEM_KEY,
    WF.FROM_ROLE,
    PRH.WF_ITEM_KEY,
    WF.RECIPIENT_ROLE APPROVERS_NAME,
    TRUNC(NVL(PRH.APPROVED_DATE, '')) DATE_APPROVED,
    WF.SUBJECT SUBJECT,
    PRH.DESCRIPTION REQ_DESC,
    PRH.SEGMENT1,
    (SUM(NVL(PRL.AMOUNT, 0)) +
    SUM(NVL(PRL.UNIT_PRICE, 0) * NVL(PRL.QUANTITY, 0))) REQ_AMT,
    GL.SEGMENT1 || '.' || GL.SEGMENT2 || '.' || GL.SEGMENT3 || '.' ||
    GL.SEGMENT4 || '.' || GL.SEGMENT5 || '.' || GL.SEGMENT6 || '.' ||
    GL.SEGMENT7 || '.' || GL.SEGMENT8 CHARGE_ACCT
    FROM APPS.WF_NOTIFICATIONS WF,
    APPS.PO_REQUISITION_HEADERS_ALL PRH,
    APPS.PO_REQUISITION_LINES_ALL PRL,
    APPS.PO_REQ_DISTRIBUTIONS_ALL PRD,
    APPS.GL_CODE_COMBINATIONS GL
    WHERE WF.FROM_ROLE IN ('GHAWKINS', 'GHALVERSON', 'NCERNOTTA', 'DCOLLOPY', 'RHAY')
    AND BEGIN_DATE > SYSDATE - 60
    AND WF.MESSAGE_TYPE = 'REQAPPRV'
    AND WF.ITEM_KEY = PRH.WF_ITEM_KEY --added
    AND PRH.AUTHORIZATION_STATUS = 'APPROVED'
    AND PRL.REQUISITION_HEADER_ID = PRH.REQUISITION_HEADER_ID
    AND PRD.REQUISITION_LINE_ID = PRL.REQUISITION_LINE_ID
    AND PRD.CODE_COMBINATION_ID = GL.CODE_COMBINATION_ID
    GROUP BY PRH.ORG_ID,
    WF.ITEM_KEY,
    WF.FROM_ROLE,
    PRH.WF_ITEM_KEY,
    WF.BEGIN_DATE,
    WF.SUBJECT,
    WF.RECIPIENT_ROLE,
    PRH.APPROVED_DATE,
    PRH.DESCRIPTION,
    PRH.SEGMENT1,
    PRL.REQUISITION_HEADER_ID,
    GL.SEGMENT1 || '.' || GL.SEGMENT2 || '.' || GL.SEGMENT3 || '.' ||
    GL.SEGMENT4 || '.' || GL.SEGMENT5 || '.' || GL.SEGMENT6 || '.' ||
    GL.SEGMENT7 || '.' || GL.SEGMENT8

    Pl see if these MOS Docs can help -
    603232.1 - How to Diagnose Purchasing Document Approval Routing
    579522.1 - Forward Document Form FAQ
    431767.1 - How To View Requisition From The Email Notifications For Which Workflow Data Is Purged
    HTH
    Srini

  • What is the Join condition between mtl_system_items_b and mtl_onhand_quantities_detail

    Hi,
    What is the Join condition between mtl_system_items_b and mtl_onhand_quantities_detail?
    Thanks & Regards,
    Hari Babu

    Please see the query in (Consolidate Onhand Quantity /Sum Quantity Zero in MTL_ONHAND_QUANTITIES_DETAIL (MOQD) / Concurrent Program Consolidate Inventory Onhand Quantities / Datafix for 0 Quantity Displayed For Finished Goods (Doc ID 353345.1)), is shows how to join those 2 tables.
    http://etrm.oracle.com
    Thanks,
    Hussein

  • Link between vbpa and vbak tables

    Hi,
    I would like to know the link between VBAK and VBPA tables.
    VBELN field in both these fields are the same?
    If I give the VBELN field got from the VBAK table into the VBPA table will I get the  customer number(KUNNR) of that particular SAles document?
    Thanks & Regards,
    Soumya.

    You can get Kunnr directly from the VBAK table, if you wanna do the Join still you can go forward and do it there is no harm but remeber to give the Partner Function(PARVW) as well as VBELN.
    Hope That Helps
    Anirban M.

  • Link between AUFK and BKPF table

    Hi all,
    Can anyone tell me the link between AUFK and BKPF table.
    Thanks in advance
    Regards
    Neha Kapoor

    hi neha ,
    1.first u have to get MBLNR from AUFM for that order
    2.Next u have to call FM
    <b>AC_DOCUMENT_RECORD</b>
    I_AWTYP                         MKPF--->Constant
    I_AWREF                         4900003215--->MBLNR
    I_AWORG                         2004--->Year
    I_AWSYS
    I_AWTYP_INCL
    I_AWTYP_EXCL
    I_BUKRS
    I_VALUTYP                       0
    X_DIALOG                           X
    then u will get the Accounting Documents.
    regards
    prabhu

  • Optimize application does not empty FAC2 and FACTWB tables

    Hello everyone,
    I am currently using OutlookSoft 4.2.338 and recently came across the following problem:
    Optimize application fails to empty FACTWB and FAC2 tables, even though it says "Successfully finished"
    -Whenever I run an optimize process directly (= not scheduled), it takes less than one second and the message "Successfully finished" pops up. However FAC2 and FACTWB are NOT empty
    - When I schedule an optimize proces, the log usually states "Fail"... (But not every time, it 's a bit random here)
    - The problem occurs with one specific application in one specific appset (that contains 3 applications, the other 2 can be optimized just fine)
    - The application contains a fairly large number of records (close to 20 millions) and, yes, some records have a "source" value at 1.
    However, the same application, on a different server, with a bigger number of records (and more "1" source values!) optimizes just fine.
    - The problem is not appset or server related, as other applications can be optimized without problem
    - The application has data imports scheduled every night, and the FAC2 table keeps growing
    - Data sent through an Input schedule stay in FACTWB.
    Did anyone come across this sort of issue before?
    Any suggestion as to how to be able to optimize the application again? (apart from moving the records manually from FAC2 to FACT...)
    Many thanks in advance
    David

    Hello,
    Unfortunately there is no such table. The only table where some mention of optimization is made is tblPackageLog, where the log of optimization tasks is recorded.
    Thanks to both of you anyway.
    David
    PS: Actually your answers gave me the clue I needed, many thanks! On version 4.2, the table tblDefaults stores the optimization status
    The query
    select * from tblDefaults
    where KEYID ='Optimize'
    and APP=  App name
    showed that the value was somehow set to 1, preventing any optimization. I manually set it to 0, and that did the trick!!!
    Many thanks again guys!
    Edited by: David Placci on Mar 2, 2012 1:50 PM
    Edited by: David Placci on Mar 2, 2012 2:44 PM

  • Linking between PP and SD tables

    Hai friends,
    I want one link between PP and SD tables. My requirement is i have planned order PLAF table. i want to link Sales table. Please guide me.
    Thanks and Regards
    visvanath

    Hi
    You can simply link the Sales order No and ITEM
    VBAP-VBELN and VBAP-POSNR with the PP order item table
    AFPO-KDAUF and AFPO-KDPOS and get the Pp related info
    or in Sales tables there is a field called AUFNR in VBAP
    use that for PP order number
    SD tables
    http://www.erpgenie.com/abap/tables_sd.htm
    PP tables
    http://www.erpgenie.com/abap/tables_pp.htm
    Regards
    Kiran Sure

  • Can we write a join on a view and a table

    Hi all,
    can we write a join on a view and a table. i got the requirement from my functional people about the following one
    Select CAUFV-AFUNR, CAUFV-AUART, AFVC-VORNR, CAUFV-FTRMI, CRHD-ARBPL
    into <ProOrd>, <OrdTyp>, <Opt>, <RelDat>, <WorCen>
    from CAUFV, AFVC, CRHD
    where CAUFV-WERKS = plant in selection screen
    and CAUFV-AFUNR = production order in selection screen
    and CAUFV-AUART = production order type in selection screen
    and CAUFV-FTRMI = range of release date in selection screen
    and CAUFV-AUFPL = AFVC-AUFPL
    and AFVC-ARBID = CRHD-OBJID
    and CRHD-OBJTY = ‘A’
    here CAUFV is a view and CRHD and AFVC are transperent tables.
    please tell me any feasible solution for this..
    Thanks  in Advance..

    Hi
    Refer these links:
    <u>http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec84446011d189700000e8322d00/content.htm</u>
    <u>http://www.sap-img.com/abap/what-is-the-different-types-and-usage-of-views.htm</u>
    <u>http://www.karakas-online.de/forum/viewtopic.php?t=730</u>
    Thanks
    Vasudha
    Message was edited by:
            Vasudha L

Maybe you are looking for

  • Performance problems on a Oracle 11G with Windows 2008 64bits.

    Hi everyone, I have noticed that our db is going low and low every week. My server has 16GB RAM and 10GB are dedicated to the Oracle database, this is a 11.2.0.1 with Windows 2008 R2 SP1 64bits. I like to know acording to the nexts values what you gu

  • Really short and basic question

    Hi there! I am interested in starting to do some Illustrator scripts (as far as my scriping experience goes, i did 3 scripts for maya, and that's it). WHAT i want to ask is, whether Illustrator has a window which lets you know what goes in the "backs

  • Calling Web Services form Custom Apps (11.5.7) Forms 6i

    Hi, My basic goal is to invoke a .net web service from a custom form. The web service is used to make a charge to a creditcard. I am currently using kind of convoluted method to achieve this. Below are the sequence of steps I do to achieve this 1) I

  • Is anyone else having this issue???

    im having issues with youtube videos loading really slowly on my iphone and ipod touch and my internet speed is pretty fast as you can see below, can someone help me fix this so youtube loads videos faster and is anyone else having this problem?

  • Newbie totally frustrated. Please help?

    I have a video i recorded with iMovie on my phone. It's so hard for me to make any edits and i want to transfer it to my iPad - I have synced both, but no luck - I can't see the videos from one on the other. Even more frustrating, I tried to give up