<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Code Performance use mseg table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507482#M1259547</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see what the problem is with the IF statement. Depending on the movement tyep, The amount is either added to or subtracted from the stored quantity.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Apr 2009 15:11:32 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-04-16T15:11:32Z</dc:date>
    <item>
      <title>Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507473#M1259538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;way of best performance of below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT itab.&lt;/P&gt;&lt;P&gt;    CLEAR wa_d_wt.&lt;/P&gt;&lt;P&gt;    SELECT  * FROM mseg WHERE matnr EQ itab-o_matnr AND charg EQ itab-o_charg  AND&lt;/P&gt;&lt;P&gt;    ( bwart = '601' OR bwart = '641' OR bwart = 602 OR bwart = '642' ).&lt;/P&gt;&lt;P&gt;      IF mseg-bwart = '601' OR mseg-bwart = '641'.&lt;/P&gt;&lt;P&gt;        wa_d_wt = wa_d_wt +  mseg-menge.&lt;/P&gt;&lt;P&gt;      ELSE.&lt;/P&gt;&lt;P&gt;        wa_d_wt = wa_d_wt -  mseg-menge.&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;    IF wa_d_wt IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;      itab-d_wt = wa_d_wt.&lt;/P&gt;&lt;P&gt;      MODIFY itab INDEX sy-tabix  TRANSPORTING d_wt.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 06:19:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507473#M1259538</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T06:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507474#M1259539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First get MBLNR from MKPF according to ur requirement , then pass those MBLNR to MSEG to get&lt;/P&gt;&lt;P&gt; ur data. Sample select query as follows---&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT MBLNR FROM MKPF INTO CORRESPONDING FIELDS OF IT_MKPF WHERE BUDAT BETWEEN DATE-LOW AND DATE-HIGH
                                                              AND MJAHR = MJAHR.
    SELECT * FROM MSEG INTO CORRESPONDING FIELDS OF IT_MSEG WHERE MBLNR = IT_MKPF-MBLNR
                                                            AND WERKS = S_WERKS AND MJAHR = MJAHR.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: mujib tirandaz on Apr 16, 2009 8:23 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 06:22:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507474#M1259539</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T06:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507475#M1259540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tomar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1st use for all entries in itab and fetch data from mseg filling i_mseg&lt;/P&gt;&lt;P&gt;Then loop itab and inside that read i_mseg with key and accordingly modify itab.&lt;/P&gt;&lt;P&gt;Let me know if you want more details about how to implement code.&lt;/P&gt;&lt;P&gt;Always remember to avoid select queries inside loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pranil Shinde.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 07:33:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507475#M1259540</guid>
      <dc:creator>Pranil1</dc:creator>
      <dc:date>2009-04-16T07:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507476#M1259541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tomar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot understand the IF clause in your below code. Irrespective of the mvoement type (BWART) you are adding the quantity (MENGE) hence you can &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF itab[] IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;SELECT matnr charg menge&lt;/P&gt;&lt;P&gt;FROM mseg&lt;/P&gt;&lt;P&gt;INTO TABLE it_mseg  &amp;lt;&amp;lt; has only fields mantnr, charg and menge&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN itab&lt;/P&gt;&lt;P&gt;WHERE matnr EQ itab-o_matnr &lt;/P&gt;&lt;P&gt;AND charg EQ itab-o_charg &lt;/P&gt;&lt;P&gt;AND bwart IN r_bwart &amp;lt;&amp;lt;where r_bwart is a RANGE of mseg-bwart and contains the bwarts u want&lt;/P&gt;&lt;P&gt;ORDER BY matnr charg.&lt;/P&gt;&lt;P&gt;LOOP AT it_mseg INTO w_mseg. &amp;lt;&amp;lt; use internal tables with header lines better for performance&lt;/P&gt;&lt;P&gt;  AT END OF charg.&lt;/P&gt;&lt;P&gt;  SUM.&lt;/P&gt;&lt;P&gt;  READ TABLE itab INTO wa WITH KEY o_matnr = w_mseg-matnr o_charg = w_mseg-charg.&lt;/P&gt;&lt;P&gt;  IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;     wa-d_wt = w_mseg-menge.&lt;/P&gt;&lt;P&gt;     MODIFY itab FROM wa INDEX sy-tabix TRANSPORTING d_wt. &amp;lt;&amp;lt; If you loop assignging field &lt;/P&gt;&lt;P&gt;&amp;lt;&amp;lt; symbol it will improve performance further &lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDAT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be syntax errors and a few corrections, but the above covers gist of that I think can be improved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Aditya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 07:44:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507476#M1259541</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T07:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507477#M1259542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please find the below optimized code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) First move the data from itab to itab_tmp.&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;2) sort itab_tmp by MATNR CHARG.&lt;/P&gt;&lt;P&gt;  then delete the duplicate entries from iatb_tmp comapring MATNR CHARG.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  For futher processing check the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;define internal table i_mseg with fields matnr charg menge.&lt;/P&gt;&lt;P&gt;data : v_menge type mseg-menge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF itab_tmp[] IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;SELECT matnr charg menge&lt;/P&gt;&lt;P&gt;             FROM mseg&lt;/P&gt;&lt;P&gt;             INTO TABLE it_mseg &lt;/P&gt;&lt;P&gt;             FOR ALL ENTRIES IN itab_tmp&lt;/P&gt;&lt;P&gt;             WHERE matnr EQ itab-o_matnr &lt;/P&gt;&lt;P&gt;                          AND charg EQ itab-o_charg &lt;/P&gt;&lt;P&gt;                          AND bwart IN ('601', '641','602','642').&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      sort itab by matnr chagr.&lt;/P&gt;&lt;P&gt;      sort i_mseg by matnr charg.&lt;/P&gt;&lt;P&gt;     LOOP AT itab into wa_itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      READ TABLE i_mseg INTO wa_mseg WITH KEY matnr = wa_itab-matnr charg = wa_itab-charg&lt;/P&gt;&lt;P&gt;                                                                      bianry search.&lt;/P&gt;&lt;P&gt;         IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;          IF mseg-bwart = '601' OR mseg-bwart = '641'.&lt;/P&gt;&lt;P&gt;                 V_menge = V_menge + w_mseg-menge.&lt;/P&gt;&lt;P&gt;          ELSE.&lt;/P&gt;&lt;P&gt;                 V_menge = V_menge + w_mseg-menge.&lt;/P&gt;&lt;P&gt;         ENDIF.&lt;/P&gt;&lt;P&gt;           wa_iatb-meng = v_menge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          MODIFY itab FROM wa_itab tranproting menge. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Sudha Rani Pathuri on Apr 16, 2009 4:24 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 10:54:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507477#M1259542</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T10:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507478#M1259543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks OK as is to me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 13:12:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507478#M1259543</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T13:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507479#M1259544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have faced same problem, but my problem has been solved by creating index on table MSEG in SE11 transaction&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so create an index on filelds which you are using in where condition in select statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Krishna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 13:47:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507479#M1259544</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T13:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507480#M1259545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; so create an index on filelds which you are using in where condition in select statement&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There already is an SAP delivered index on MATNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 14:00:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507480#M1259545</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T14:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507481#M1259546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is that ???&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
IF mseg-bwart = '601' OR mseg-bwart = '641'.
   wa_d_wt = wa_d_wt + mseg-menge.
ELSE. 
   wa_d_wt = wa_d_wt - mseg-menge.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is the same as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   wa_d_wt = wa_d_wt - mseg-menge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the conditions are useless !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe there is a typo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise, if there is no typo, then you could do the summation with an aggregatfunction.&lt;/P&gt;&lt;P&gt;Whether the aggregate is better than a FOR ALL ENTRIES can not be said in general.&lt;/P&gt;&lt;P&gt;Anyway, first of all your IF-clause must be explained.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 15:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507481#M1259546</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T15:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507482#M1259547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see what the problem is with the IF statement. Depending on the movement tyep, The amount is either added to or subtracted from the stored quantity.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 15:11:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507482#M1259547</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T15:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Code Performance use mseg table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507483#M1259548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for people not knowing the meaning of bwart it makes sense to mark the difference between the plus and nearly invisible minus.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering whether there is really a problem with that coding, it looks o.k. Maybe there is small improvement possible by using FAE, but neither of the above recommendation works really.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the structure of itab, are the moire fields besides itab-o_matnr and itab-o_charg ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not then you can use select for all entries, and create a new table &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matnr  charg  bwart and menge&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort it &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop over that table and do the summation and subtraction and append into a new table at every&lt;/P&gt;&lt;P&gt;change of matnr charg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then a nested loop can be avoided, and then it could be faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2009 15:45:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-performance-use-mseg-table/m-p/5507483#M1259548</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-16T15:45:37Z</dc:date>
    </item>
  </channel>
</rss>

