MSEG, BSEG, MKPF

How would u go about improving the performance of a Program, which selects data from MSEG & MKPF or BSEG ?

Hi Subha,
Go through this info.
Disadvantages:
Basically index are provided to improver performance. i.e with index select on db tables retrieves data much faster.
If you are writting select statement on the table where in where clause you have non-primary keys then it takes longer to retriev data from DB table.
If you have select in dbtable on non-primary key you can create Secondary index with keys as per your where clause which result in faster DB table access.
But remember not to create too many secondary indexes on same table which could result in slow / degrage performance..
you can check out the link below for more inforamation on indexes
http://www.idig.za.net/mysqlindexes/2006/11/09/
Secondary Indexes
Advantages :
Secondary indexes are used to enhancement performance when retrieving data. For example, say you have a table AFKO where the key to the table is AUFNR. You can select data from this table using AUFNR, the performance will be great because you are using the key. Say you need to hit this table with GLTRP(finish date), it is not part of the key, so the performance would be poor. If you created a secondard index using this field GLTRP, the performance would be improved. Make sense?
https://forums.sdn.sap.com/click.jspa?searchID=1052972&messageID=1633228
http://help.sap.com/saphelp_470/helpdata/en/cf/21eb20446011d189700000e8322d00/frameset.htm
sap.ittoolbox.com/documents/popular-q-and-a/specifying-the-index-to-be-used-2462
sap.ittoolbox.com/documents/popular-q-and-a/specifying-the-index-to-be-used-2462
http://www.sap-img.com/abap/quick-note-on-design-of-secondary-database-indexes-and-logical-databases.htm
**********rewords some points.
Rgds,
P.Naganjana Reddy

Similar Messages

  • Select Query info req for ZMKPFMSEG: View of MSEG and MKPF table

    Hi
    I am fetching 7-8 records frm ZMKPFMSEG: View of MSEG and MKPF table,which based on matnr,werks & budut,which is taking a large time,there is no index in the table,so can nay one tell me how to fetch the data,to make code more effictient.
    SELECT  budat
              matnr
              menge
              bwart
              meins
              bwtar
              waers
              dmbtr
              shkzg
              matkl
              FROM  zmkpfmseg
              INTO  CORRESPONDING FIELDS OF TABLE it_mseg
              WHERE budat GE r_ytd-low
                AND matnr IN so_matnr
                AND werks = p_werks
                AND lgort IN so_lgort
                AND matkl IN so_matkl.
    plz tell me what changes have to be done in where condtion to make it run fast.
    regds

    Hi,
    Try the alternate Methods,
    ACCESS VIA SUBQUERY.
    SELECT * FROM MKPF AS M INTO CORRESPONDING FIELDS OF SWAP
                                        WHERE  BUDAT IN BUDAT AND
                                               MBLNR IN MBLNR AND
                                               VGART = 'WA' AND
                                               EXISTS ( SELECT * FROM MSEG
                                                        WHERE MBLNR = M~MBLNR
                                                        AND   MJAHR = M~MJAHR
                                                       AND   WERKS = P_WERKS
    AND matnr IN so_matnr
    AND lgort IN so_lgort
    AND matkl IN so_matkl.
        APPEND SWAP.CLEAR SWAP.
      ENDSELECT.
      LOOP AT SWAP.
        SELECT  * FROM MSEG
                                 WHERE MBLNR = SWAP-MBLNR AND
                                        MJAHR = SWAP-MJAHR AND
          IF SY-SUBRC EQ 0.
            MOVE-CORRESPONDING SWAP TO ITAB.
            MOVE-CORRESPONDING MSEG TO ITAB.
            APPEND ITAB.CLEAR ITAB.
            CLEAR MSEG.
          ENDIF.
        ENDSELECT.
        CLEAR : SWAP,ITAB.
      ENDLOOP.
    Try this,
    SELECT budat
    matnr
    menge
    bwart
    meins
    bwtar
    waers
    dmbtr
    shkzg
    matkl
    FROM zmkpfmseg
    INTO CORRESPONDING FIELDS OF TABLE it_mseg
    WHERE budat GE r_ytd-low
    AND matnr IN so_matnr
    AND lgort IN so_lgort
    AND matkl IN so_matkl.
    delete it_mseg where WERKS NE p_WERKS .
    Reward Points if helpful.
    Regards,
    Balakumar.G

  • Are there any alternatives for mseg and mkpf

    I had to display from table S032...following fields.
    S032-LETZTABG --> Date: last (i.e. most recent) goods issue
    S032-LETZTVER --> Date: last (i.e. most recent) consumption
    However the data was not properly filled in s032 table.  So I went for mseg and mkpf table to get budat based on moment types.
        SELECT   MSEG~MATNR
                 MSEG~WERKS
                 MSEG~LGORT
                 MSEG~BWART
                 MKPF~BUDAT
                 INTO TABLE IT_MSEG
                 FROM MKPF AS MKPF  INNER JOIN MSEG AS MSEG
                 ON
                     MKPFMBLNR  =  MSEGMBLNR  AND
                     MKPFMJAHR  =  MSEGMJAHR
                 FOR ALL ENTRIES  IN  T_OUT_TMP
                WHERE MSEG~MATNR  EQ  T_OUT_TMP-MATNR
                  AND MSEG~WERKS  EQ  T_OUT_TMP-WERKS.
    Are there any other alternative table for mseg and mkpf...
    Because my above coding  ( which includes above  SELECT of mseg and mkpf )got performance issue...
    Could you please suggest me anyu other alternative for mseg and mkpf ...

    Try to include the BUDAT in the selection of the MKPF.. if you don't have any restriction in MKPF than just pass an empty range.
    RANGES: S_BUDAT FOR MKPF-BUDAT.
    SELECT
    MKPF~BUDAT   "<<<
    MSEG~MATNR
    MSEG~WERKS
    MSEG~LGORT
    MSEG~BWART
    INTO TABLE IT_MSEG
    FROM MKPF AS MKPF INNER JOIN MSEG AS MSEG
    ON
    MKPF~MBLNR = MSEG~MBLNR AND
    MKPF~MJAHR = MSEG~MJAHR
    FOR ALL ENTRIES IN T_OUT_TMP
    WHERE
    MKPF~BUDAT IN S_BUDAT   " <<<
    MSEG~MATNR EQ T_OUT_TMP-MATNR
    AND MSEG~WERKS EQ T_OUT_TMP-WERKS.
    Regards,
    Naimesh Patel

  • JOIN for BSEG, BSIS, BSAS, MSEG, BKPF and MKPF

    I am developing a report related to G/L . i am using the Tables BSEG BSIS BSAS MSEG BKPF MKPF ............please give me the Joinings of these tables.......how exactly we can join and get the prefect Data....
    Thank U waiting for ur replies....
    Title edited by: Alvaro Tejada Galindo on Jun 3, 2008 3:41 PM

    I have given the tables, internal tables and the select queries which can give you the join conditions of your requirement.
    tables: bsis,
            bsas,
            bkpf,
            bseg,
            ekbe,
            mkpf,
            mseg.
    select-options: s_hkont  for bseg-hkont,
                    s_bldat  for bkpf-budat,
                    s_budat  for bkpf-bldat obligatory,
                    s_lifnr  for bseg-lifnr,
                    s_lfbnr  for ekbe-lfbnr no intervals no-extension.
    data: begin of i_bsis_bsas occurs 0,
            bukrs like bsis-bukrs,
            hkont like bsis-hkont,
            gjahr like bsis-gjahr,
            belnr like bsis-belnr,
            budat like bsis-budat,
            bldat like bsis-bldat,
            xblnr like bsis-xblnr,
            wrbtr like bsis-wrbtr,
            buzei like bsis-buzei,
          end   of i_bsis_bsas,
          begin of i_bkpf     occurs 0,
            bukrs like bsis-bukrs,
            belnr like bsis-belnr,
            gjahr like bsis-gjahr,
            xblnr like bkpf-xblnr,
            stblg like bkpf-stblg,
            awtyp like bkpf-awtyp,
            tcode like bkpf-tcode,
          end   of i_bkpf,
          begin of i_bseg     occurs 0,
            bukrs like bsis-bukrs,
            belnr like bsis-belnr,
            gjahr like bsis-gjahr,
            buzei like bseg-buzei,
            buzid like bseg-buzid,
            koart like bseg-koart,
            zuonr like bseg-zuonr,
            hkont like bseg-hkont,
            lifnr like bseg-lifnr,
            sgtxt like bseg-sgtxt,
            ebeln like bseg-ebeln,
            ebelp like bseg-ebelp,
            wrbtr like bseg-wrbtr,
          end   of i_bseg,
          begin of i_ekbe    occurs 0,
            ebeln like ekbe-ebeln,
            ebelp like ekbe-ebelp,
            gjahr like ekbe-gjahr,
            belnr like ekbe-belnr,
            buzei like ekbe-buzei,
            lfgja like ekbe-lfgja,
            lfbnr like ekbe-lfbnr,
            lfpos like ekbe-lfpos,
            matnr like ekbe-matnr,
          end   of i_ekbe,
          begin of i_mkpf_mseg occurs 0,
            mblnr like mkpf-mblnr,
            mjahr like mkpf-mjahr,
            bktxt like mkpf-bktxt,
            xblnr like mkpf-xblnr,
            frbnr like mkpf-frbnr,
            zeile like mseg-zeile,
            matnr like mseg-matnr,
            erfmg like mseg-erfmg,
          end   of i_mkpf_mseg.
    *data: wa_ekbe like i_ekbe.
    select  bukrs
              hkont
              gjahr
              belnr
              budat
              bldat
              xblnr
              wrbtr
              buzei appending corresponding fields of table i_bsis_bsas
                    from  bsis
                    where bukrs eq p_bukrs
                      and hkont in s_hkont
                      and gjahr eq p_gjahr
                      and budat in s_budat
                      and shkzg eq 'S'.
      select  bukrs
              hkont
              gjahr
              belnr
              budat
              bldat
              xblnr
              wrbtr appending corresponding fields of table i_bsis_bsas
                    from  bsas
                    where bukrs eq p_bukrs
                      and hkont in s_hkont
                      and gjahr eq p_gjahr
                      and budat in s_budat
                      and shkzg eq 'S'.
    endform.                    " f_get_bsis_bsas_data
    *&      Form  f_get_bkpf_bseg_data
          Subroutine to get BKPF and BSEG data
    form f_get_bkpf_bseg_data.
      check not i_bsis_bsas[] is initial.
      select  bukrs
              belnr
              gjahr
              xblnr
              stblg
              awtyp
              tcode into table i_bkpf
                    from bkpf
                     for all entries in i_bsis_bsas
                   where bukrs eq i_bsis_bsas-bukrs
                     and belnr eq i_bsis_bsas-belnr
                     and gjahr eq i_bsis_bsas-gjahr.
                    and awtyp = 'BKPFF'
                    and tcode = 'J1IE'.
      check not i_bkpf[] is initial.
      select  bukrs
              belnr
              gjahr
              buzei
              buzid
              koart
              zuonr
              hkont
              lifnr
              sgtxt
              ebeln
              ebelp
              wrbtr  into corresponding fields of table i_bseg
                     from bseg
                      for all entries in i_bsis_bsas
                    where bukrs eq i_bsis_bsas-bukrs
                      and belnr eq i_bsis_bsas-belnr
                      and gjahr eq i_bsis_bsas-gjahr.
                     and buzei eq i_bsis_bsas-buzei
                     and hkont eq i_bsis_bsas-hkont.
      delete i_bseg where not hkont in s_hkont.
    endform.                    " f_get_bkpf_bseg_data
    *&      Form  f_get_ekbe_data
          Subroutine to get EKBE data
    form f_get_ekbe_data.
      data: $i_bseg like i_bseg occurs 0 with header line.
      $i_bseg[]  =  i_bseg[].
      delete $i_bseg where ebeln is initial.
      check not $i_bseg[] is initial.
      select ebeln
             ebelp
             gjahr
             belnr
             buzei
             lfgja
             lfbnr
             lfpos
             matnr into table i_ekbe
                   from ekbe
                    for all entries in $i_bseg
                  where ebeln eq $i_bseg-ebeln
                    and ebelp eq $i_bseg-ebelp
                    and gjahr eq $i_bseg-gjahr
                    and bwart = '101'.
                   and belnr eq $i_bseg-belnr.
    check not i_ekbe[] is initial.
      select a~mblnr
             a~mjahr
             a~bktxt
             a~xblnr
             a~frbnr
             b~zeile
             b~matnr
             b~werks
             b~erfmg  into table i_mkpf_mseg
                      from mkpf as a inner join
                           mseg as b on amblnr eq bmblnr
                                    and amjahr eq bmjahr
                       for all entries in i_ekbe
                       where a~mblnr eq i_ekbe-lfbnr
                      and a~mjahr eq i_ekbe-gjahr
                      and b~zeile eq i_ekbe-lfpos
                        and b~werks eq p_werks.
    <REMOVED BY MODERATOR>
    Edited by: Srikanth Kadiyala on Jun 3, 2008 7:24 AM
    Edited by: Alvaro Tejada Galindo on Jun 3, 2008 3:40 PM

  • Create a Logical Database Based on Mseg and Bseg

    Hi,
      how can i create a Logical database using bkpf,bseg,mkpf,mseg. i need to know , which table is a root node ?
    could any one help me?
       Thanks

    Hi Amit,
           While I am Creating the Logical Database by selection MKPF as root node, i have one problem.
       my selection-screen is,
        Plant  Bseg-werks,
        G/Laccount Bseg-Hkont,
        Fin year bseg-gjahr,
        Grn Date Bkpf-Budat,
        Vendor No Bseg-lifnr,
        Po        Bseg-ebeln,
        MatNr     Bseg-matnr.
      My LDB structure is
             MKPF
    Mseg
    BKPF
    Bseg.
      My Doubt is, how can I access the glaccount details from bseg and How can i fetch the data from Mseg and Mkpf
    (Grn details) .
      If you give the Source code it is very useful to me.
      Thanks,
      Neptune.M

  • Performance issue while selecting material documents MKPF & MSEG

    Hello,
    I'm facing performance issues in production while selecting Material documents for Sales order and item based on the Sales order Stock.
    Here is the query :
    I'm first selecting data from ebew table which is the Sales order Stock table then this query.
        IF ibew[] IS NOT INITIAL AND ignore_material_documents IS INITIAL.
    *     Select the Material documents created for the the sales orders.
          SELECT mkpf~mblnr mkpf~budat
                 mseg~matnr mseg~mat_kdauf mseg~mat_kdpos mseg~shkzg
                 mseg~dmbtr mseg~menge
           INTO  CORRESPONDING FIELDS OF TABLE i_mseg
           FROM  mkpf INNER JOIN mseg
           ON    mkpf~mandt = mseg~mandt
           AND   mkpf~mblnr = mseg~mblnr
           AND   mkpf~mjahr = mseg~mjahr
           FOR   ALL entries IN ibew
           WHERE mseg~matnr      = ibew-matnr
           AND   mseg~werks         = ibew-bwkey
           AND   mseg~mat_kdauf   = ibew-vbeln
           AND   mseg~mat_kdpos  = ibew-posnr.
          SORT i_mseg BY mat_kdauf ASCENDING
                         mat_kdpos ASCENDING
                         budat     DESCENDING.
        ENDIF.
    I need to select the material documents because the end users want to see the stock as on certain date for the sales orders and only material document lines can give this information. Also EBEW table gives Stock only for current date.
    For Example :
    If the report was run for Stock date 30th Sept 2008, but  on the 5th Oct 2008, then I need to consider the goods movements after 30th Sept and add if stock was issued or subtract if stock was added.
    I know there is an Index MSEG~M in database system on mseg, however I don't know the Storage location LGORT and Movement types BWART that should be considered, so I tried to use all the Storage locations and Movement types available in the system, but this caused the query to run even slower than before.
    I could create an index for the fields mentioned in where clause , but it would be an overhead anyways.
    Your help will be appreciated. Thanks in advance
    regards,
    Advait

    Hi Thomas,
    Thanks for your reply. the performance of the query has significantly improved than before after switching the join from mseg join mkpf.
    Actually, I even tried without join and looped using field symbols ,this is working slightly faster than the switched join.
    Here are the result ,  tried with 371 records as our sandbox doesn't have too many entries unfortunately ,
    Results before switching the join  146036 microseconds
    Results after swithing the join        38029 microseconds
    Results w/o join                           28068 microseconds for selection and 5725 microseconds for looping
    Thanks again.
    regards,
    Advait

  • VIEW b/w MKPF, MSEG and VBAK

    Hello Friends,
    I have done some coading, thought to take ur opinion, if its right or not....
    actually, I have following senario:
    I have to select all document of TODAYS date ( MKPF-BLDAT) which are from some specific MSEG-LIFNR and the KUUNR is always e.g "123456" ( VBAK-KUNNR )
    SO I made a VIEW with join condition...
    MKPF-MANDT = MSEG-MANDT
    MKPF-MANDT = VBAK-MANDT
    MKPF-MBLNR = MSEG-MBLNR
    MKPF-MJAHR = MSEG-MJAHR
    MSEG-KDAUF = VBAK-VBELN
    and make the select statement as:
      SELECT * FROM /BAGCOI/MSVIEW
        into CORRESPONDING FIELDS OF TABLE lt_msview
        WHERE
           BLDAT in p_sdate AND
           LIFNR eq c_lifnr AND
           KUNNR eq c_kunnr.
    Do u guys think, it will work for me ?
    Regards,
    PLS ask, if my post is not clear enough
    Message was edited by:
            Shah H

    Hi Rob,
    Could you pls explain about index ?
    Secondlly, I need to have all goods movement of todays date ?, then it would be the filed BLDAT or ?
    Regards,
    Message was edited by:
            Shah H

  • Link up b/w MKPF,MSEG and RBKP,RSEG

    Hi,
    I am working on a report in which i have to make up a link b/w above mentioned tanles. till now i am able to make  link between MSEG and MKPF but the problem is that when i go for the RBKP and Rseg it gives a bit problem as RBKP is a Header Table and RSEG is a item table ,the flow of logic conatins data from field MSEG-LFBNR which is EQ to RSEG-LFBNR and from there i pick up the BELNR and proceed to the PBKP .Is it a right process for reteriving the data?
    Please provide me guidelines to solve this problem.

    Plz SEARCH in SCN before posting.
    Re: EKBE - the connection between Invoice Recipt to Good Recipt

  • Bad performance of MKPF / MSEG selects

    Hi,
    I am working on report for performance issue.
    select-options : matnr FOR  mara-matnr,
                             mtart FOR  mara-mtart,
                             werks FOR  mseg-werks NO INTERVALS,
                              lgort FOR  mseg-lgort NO INTERVALS,
                             budat FOR  mkpf-budat ,"OBLIGATORY,
                             reci  FOR  mseg-bwart ,"OBLIGATORY NO INTERVALS,
                             iss   FOR  mseg-bwart ."
    select queries are followings but inside loop.
    loop at itab.
    at new matnr.
    SELECT SUM( MENGE ) INTO qty1 from mkpf inner join mseg on
    MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
    WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
    AND BUDAT < BUDAT-LOW and SHKZG = 'S'
    AND  BWART IN ('561','105','101','309','701').
    SELECT SUM( MENGE ) INTO qty2 from mkpf inner join mseg on
    MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
    WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
    AND BUDAT < BUDAT-LOW and SHKZG = 'H'
    AND  BWART IN ('562','201','261','502','543','333','551' ) .
    SELECT SUM( MENGE ) INTO r_qty1 from mkpf inner join mseg on
    MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
    WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
    AND BUDAT IN BUDAT AND SHKZG = 'S' AND
    bwart in reci.
    SELECT SUM( MENGE ) INTO R_qty2 from mkpf inner join mseg on
    MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
    WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
    AND BUDAT IN BUDAT and SHKZG = 'H'
    and bwart in reci.
    SELECT SUM( menge ) INTO q1_qty1 from mkpf inner join mseg on
    MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
    WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
    AND BUDAT IN BUDAT AND SHKZG = 'S' AND
    bwart in iss.
    SELECT SUM( menge ) INTO q1_qty2 from mkpf inner join mseg on
    MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
    WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
    AND BUDAT IN BUDAT AND SHKZG = 'S' AND
    bwart in iss.
    after that  calculations..
    endat.
    endloop.
    Its performance is very poor. It takes lot much time to get output.
    I want to replace the code with for all entries..
    Then 2 slect statements based on mkpf table
    1 ) for budat in budat
    2) for budat > budat-low.
    the based on this 8- 10 select statement from mseg table.
    how to get into final table all data ....

    Thanks sir. I worked like that.
    SELECT mblnr          mjahr          vgart          blart          blaum          budat FROM mkpf INTO TABLE tt_mkpf
                                              WHERE budat IN s_budat.
      IF sy-subrc = 0.
        SORT tt_mkpf BY mblnr mjahr budat.
      ENDIF.
      IF NOT tt_mkpf[] IS INITIAL.
        select  matnr    mblnr   mjahr   zeile  bwart   werks lgort   shkzg   dmbtr   menge
                FROM mseg INTO corresponding fields of TABLE tt_mseg_temp FOR ALL ENTRIES IN tt_mkpf
                WHERE mblnr   =  tt_mkpf-mblnr
                              AND   mjahr   =  tt_mkpf-mjahr
                                                                          AND  ( shkzg  =  'S'
                                                                          or     shkzg  =  'H' )
                                                                          and    matnr  in  s_matnr
                                                                          and    lgort  in  s_lgort
                                                                          and    werks  in  s_werks
                                                                          and (  bwart  in  s_reci  or
                                                                                 bwart  in  s_iss ).
    and for second case  SELECT mblnr          mjahr          vgart          blart          blaum          budat FROM mkpf INTO TABLE tt_mkpf
                                              WHERE budat <  s_budat.
    after fetching data from mseg based on above statement .
    how to take the data to final table based on two  mkpf amd mseg table data so that i can  use  loop tt at into wa . I need just small assistane on this.

  • Querry for MKPF and MSEG

    Hi,
    In mY report,
    I have BUDAT as select-options and
             WERKS as select-options.
    Based on MBLNR, MJAHR from MKPF into table it_mkpf where Budat in s_BUDAT.
    after that I am fetching MSEG data using for all entries in it_mkpf where werks in s_werks.
    for low date range it is working fine.
    For higher date range ,I am getting around 2 Lacs of records in MKPF , but while fetching MSEG ,Its getting dump with message endless Loop.
    How can increase my performance.
    Is there any Function Module to fetch data.
    Can anybody suggest me.
    Thanks
    kumar n

    Hi Kumar,
    I have the same situation,
    where I will have 1.5 lakhs minimum records from MKPF every month,,,
    now my total database is nearly 35 million records till date from 1998.
    and getting records from MKPF is not difficult its very easy even 35 million records,,,
    But after getting from MSEG by MKPF is Hell,,,,
    but I see Joins are far better , best in these cases,,,
    So after that i have written a Code snippet in "Code-gallery" in SAP -Wiki, with title Joins are Better in some cases
    Author: Dileep Kumar
    Submitted: 11.02.2009
    Description  : Join Statement is the best in some cases as shown below than For All Entries. So Dont Forget about Joins Simply. Keep trying with joins
    sometimes, where you can get a better performance.
    Dont forget about joins simply like that due to performances. Now in this case(A Business Requirement) Joins is the best than FOR ALL ENTRIES.
    TYPES: BEGIN OF TY_MKPF ,
            MBLNR TYPE MKPF-MBLNR,          "Material document
            MJAHR TYPE MKPF-MJAHR,
            BUDAT TYPE MKPF-BUDAT,          "Posting Date in the document
          END OF TY_MKPF.
    TYPES: BEGIN OF TY_MSEG1 ,
            MJAHR TYPE MKPF-MJAHR,
            BUDAT TYPE MKPF-BUDAT,          "Posting Date in the document
            MBLNR TYPE MSEG-MBLNR,          "Material document
            MATNR TYPE MSEG-MATNR,          "Material Number
            ZEILE TYPE MSEG-ZEILE,          "Item in material document
            BWART TYPE MSEG-BWART,          "Movement Type
            CHARG TYPE MSEG-CHARG,          "Batch Number
            EBELN TYPE MSEG-EBELN,          "PO #
            SHKZG TYPE MSEG-SHKZG,          "Debit/Credit Indicator
            MENGE TYPE MSEG-MENGE,          "Quantity
            MEINS TYPE MSEG-MEINS,          "UOM
            DMBTR TYPE MSEG-DMBTR,          "Amount in local currency
            WAERS TYPE MSEG-WAERS,          "Currency Key
          END OF TY_MSEG1.
    TYPES: BEGIN OF TY_MSEG ,
            MBLNR TYPE MSEG-MBLNR,          "Material document
            MATNR TYPE MSEG-MATNR,          "Material Number
            ZEILE TYPE MSEG-ZEILE,          "Item in material document
            BWART TYPE MSEG-BWART,          "Movement Type
            CHARG TYPE MSEG-CHARG,          "Batch Number
            EBELN TYPE MSEG-EBELN,          "PO #
            SHKZG TYPE MSEG-SHKZG,          "Debit/Credit Indicator
            MENGE TYPE MSEG-MENGE,          "Quantity
            MEINS TYPE MSEG-MEINS,          "UOM
            DMBTR TYPE MSEG-DMBTR,          "Amount in local currency
            WAERS TYPE MSEG-WAERS,          "Currency Key
          END OF TY_MSEG.
    DATA : IT_MSEG TYPE TABLE OF TY_MSEG, WA_MSEG LIKE LINE OF IT_MSEG.
    DATA : IT_MKPF TYPE TABLE OF TY_MKPF, WA_MKPF LIKE LINE OF IT_MKPF.
    DATA : IT_MSEG1 TYPE TABLE OF TY_MSEG1, WA_MSEG1 LIKE LINE OF IT_MSEG1.
    SELECT-OPTIONS :
       S_BUDAT FOR MKPF-BUDAT," OBLIGATORY,       " Posting Date.
       S_MATNR FOR MSEG-MATNR," OBLIGATORY.       " Material No.
       S_WERKS FOR MSEG-WERKS." OBLIGATORY,       " Plant
    Start-of-Selection.
    *<<<<<<<<<<<<<<<<<<<<
        SELECT MBLNR MJAHR BUDAT
          INTO TABLE IT_MKPF
          FROM MKPF
          WHERE BUDAT IN S_BUDAT.
      IF IT_MKPF IS NOT INITIAL.
        SELECT MBLNR MATNR ZEILE BWART CHARG EBELN SHKZG MENGE MEINS DMBTR WAERS
          FROM MSEG
          INTO TABLE IT_MSEG
          FOR ALL ENTRIES IN IT_MKPF
          WHERE MBLNR = IT_MKPF-MBLNR AND
                MJAHR = IT_MKPF-MJAHR AND
                MATNR IN S_MATNR AND
                WERKS IN S_WERKS .
      ENDIF.
    *compared to the above For all entries, below Join can perform well &
    *Good for 2nd & third runs are much faster as they store data in Buffer memory..
    *<<<<<<<<<<<<<<<<<
      SELECT  AMJAHR  ABUDAT BMBLNR BMATNR BZEILE BBWART B~CHARG
              BEBELN BSHKZG BMENGE BMEINS BDMBTR BWAERS
              INTO TABLE IT_MSEG1
              FROM MKPF AS A INNER JOIN MSEG AS B ON AMBLNR = BMBLNR AND
                                                     AMJAHR = BMJAHR
              WHERE A~BUDAT IN S_BUDAT AND
                    B~MATNR IN S_MATNR AND
                    B~WERKS IN S_WERKS .
    *<<<<<<<<<<<<<<<<<<
    Thanks & regards,
    Dileep .C

  • Urgent: Regarding Inner join relation b/w MSEG, MKPF, MARA and MAKT

    I have written o code like below for inner join. However, The program has take much more time to give out put. Could any one please correct the below inner join statement. Its very urgent.
    Thanks for your help.
    SELECT  mseg~mblnr
              mseg~matnr
              mseg~werks
              mseg~charg
              mseg~lifnr
              mseg~bualt
              mseg~erfmg
              mseg~ebeln
              mseg~ebelp
              mkpf~budat   
              mara~zzshelf_life                              
              makt~maktx
              FROM mseg
              INNER JOIN mkpf
                ON mkpfmblnr EQ msegmblnr
              INNER JOIN mara
                ON msegmatnr EQ maramatnr
              INNER JOIN makt
                ON maramatnr EQ maktmatnr
              INTO TABLE gt_mat_doc
              WHERE  mseg~matnr IN s_matnr
                AND  mseg~werks IN s_werks
                AND  mseg~lifnr IN s_lifnr
                AND  mseg~bwart EQ p_bwart
                AND  ( msegebeln NE ' ' AND msegebeln IN s_ebeln )
                AND  mkpf~budat IN s_budat
                AND  mara~mtart IN s_mtart
                AND  makt~spras EQ sy-langu.

    Hi,
    Do like this
    Types: begin of ty_mesg_mkpf,
             mblnr type mseg-mblnr,
             matnr type mseg-matnr,
             werks type mseg-werks,
             charg type mseg-charg,
             lifnr type mseg-lifnr,
             bualt type mseg-bualt,
             erfmg type mseg-erfmg,
             ebeln type mseg-ebeln,
             ebelp type mseg-ebelp,
             budat type mkpf-budat,
           end of ty_mseg_mkpf,
           Begin og ty_mara_makt,
            matnr type mara-matnr,
            zzshelf_life type mara-zzshelf_life,
            maktx type makt-maktx,
           end of ty_mara_makt.
    Data: it_mseg_mkpf type table of ty_mseg_mkpf,
          wa_mseg_mkpf type ty_mseg_mkpf,
          it_mara_makt type table of ty_mara_makt,
          wa_mara_makt type ty_mara_makt.
    SELECT m1~mblnr
    m1~matnr
    m1~werks
    m1~charg
    m1~lifnr
    m1~bualt
    m1~erfmg
    m1~ebeln
    m1~ebelp
    m2~budat
    FROM mseg
    INTO TABLE it_mseg_mkpf
    INNER JOIN mkpf
    ON m1mblnr EQ m2mblnr
    WHERE m1~matnr IN s_matnr
    AND m1~werks IN s_werks
    AND m1~lifnr IN s_lifnr
    AND m1~bwart EQ p_bwart
    AND ( m1ebeln NE ' ' AND m1ebeln IN s_ebeln )
    AND m2~budat IN s_budat
    if sy-subrc = 0.
    Select m3~matnr
    m3~zzshelf_life
    m4~maktx from mara as m3
    INNER JOIN makt as m4
    ON m3matnr EQ m4matnr
    INTO TABLE it_mara_makt
    where m3~mtart IN s_mtart
    AND m4~spras EQ sy-langu.
    endif.
    loop at it_mseg_mkpf into wa_mseg_mkpf.
    Move necessary field values from wa_mseg_mkpf to wa_mat_doc.
    Read table it_mara_makt into wa_mara_makt with key matnr = wa_mseg_mkpf-matnr.
    if sy-subrc = 0.
      move remaining field values to wa_mat_doc.
      append wa_mat_doc to gt_mat_doc.
      clear wa_mat_doc.
    endif.
    endloop.
    Regards,
    Satish

  • Table mseg, mkpf  cpu 90% problem

    when we run the report about some big table such as "mseg" or "mkpf",  the os resouce cpu is occupied 90%  .   
    our os is AIX 5,3 ,  memory 4G ,  one power 5 cpu,  
    I do no know is there some problem about my sap system?  thanks
    what can I do to these special tables daily?      Could you give me some advices??

    Maybe the report is to big, maybe you need to check if the indexes are right... You can do a trace via ST01 and find out if theres any particular sql statement that is taking too long and check the indexes.
    Regards
    Juan

  • Performance issue with MSEG table in Production

    Hi,
    I have written a report with 4 select queries.
    First i am selecting data from VBRK table in i_vbrk. Then for all entries in i_vbrk, i am fetching records from VBRP into i_vbrp table. Then for all entries in i_vbrp, records are fetched from MKPF into i_mkpf. Then, finally for all entries in i_mkpf, records are fetched from MSEG into i_mseg table.
    Performance of this report is good in Quality system, but it is very poor in Production systems. It is taking more than 20 mins to get executed. MSEG table query is taking most of the time.
    I have done indexing and packet sizing on MSEG table, but still performace issue persists. So, cqan you please let me know if there is any way by which performace of the program can be improved???
    Please help.
    Thanks,
    Archana

    Hi Archana,
    I was having the same issue for MKPF and MSEG , I am using INNER JOIN Condition .
    SELECT
    mkpf~mblnr
    mkpf~mjahr
    mkpf~budat
    mkpf~usnam
    mkpf~bktxt
    mseg~zeile
    mseg~bwart
    mseg~prctr
    mseg~matnr
    mseg~werks
    mseg~lgort
    mseg~menge
    mseg~meins
    mseg~ebeln
    mseg~sgtxt
    mseg~shkzg
    mseg~dmbtr
    mseg~waers
    mseg~sobkz
    mkpf~xblnr
    mkpf~frbnr
    mseg~lifnr
    INTO TABLE xmseg
    FROM mkpf
    INNER JOIN mseg
    ON mkpfmandt EQ msegmandt AND
    mkpfmblnr EQ msegmblnr AND
      mkpfmjahr EQ msegmjahr
    WHERE mkpf~vgart IN se_vgart
    AND   mkpf~budat IN se_budat
    AND   mkpf~usnam IN se_usnam
    AND   mkpf~bktxt IN se_bktxt
    AND   mseg~bwart IN se_bwart
    AND   mseg~matnr IN se_matnr
    AND   mseg~werks IN se_werks
    AND   mseg~lgort IN se_lgort
    AND   mseg~sobkz IN se_sobkz
    AND   mseg~lifnr IN se_lifnr
    %_HINTS ORACLE '&SUBSTITUTE VALUES&'.
    But still I have a issue in performance , Can anybody  give some suggestions , please .
    Regards,
    Shiv

  • Connect VBRP-VGBEL with MKPF-XBLNR

    Hello,
    I need to create a query with sales invoice number, material code, sales price, quantity, amt in local currency.
    The problem right now is the list displays all material document including that the outbound delivery was cancelled. Thus, if the user did outbound delivery followed by cancelling outbound and redoing outbound delivery, 3 duplicated information with different material document number is displayed.
    So, the solution I am thinking about is to link the delivery document number in VBRP and MKPF. However, the system doesn't allow me to do that.
    Currently I am using VBRK, VBRP, MSEG, and MKPF for the tables.
    Any suggestions welcomed.
    Thank you,

    Hello Takako,
    look into the following table
    LEDSPD_FLOW Document Flow for Subsequent Outbound-Delivery Split
    Or
    You can go in table vbfa which store the flow of the documents created ie.
    go with the invoice no you have and look for the preceeding delivery documents ie of Status (J), now in you case you may get 3 documents
    one outbound delivery created
    one for cancelled and
    one for recreation.
    Once you get these document nos you need to find out the reference document of the cancelled delivery document,it will store the delivery document no against which this is cancelled.
    You may check lips and likp if you want
    Thanks.
    Regards.
    Sunmit.

  • Relation between MSEG table and movement types in 2lis_03_bf

    Hi all,
    May i know the relation between MSEG table and 2lis_03 _bf xtractor stock type/stockcategory where we see the informarion in r/3 side for this, you answers gets rewarded.
    regards,
    Dan.

    Hi,
    Most of the data for IM comes from the tables MSEG andd MKPF. You can go to MSEG contents and see the data there. You will find all the movement types, stock types and stock categories there. You can also use the transactions MB5B, MB51 etc.. to see the related info in R/3. As I said most of the data comes from these tables but not all the data. It uses some internal programming to get the data.
    Hope it helps...

Maybe you are looking for