<?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: Improve Acces to SD data in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088209#M433827</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this..&lt;/P&gt;&lt;P&gt;table i_mard is of type MARD....&lt;/P&gt;&lt;P&gt;SELECT * FROM mard&lt;/P&gt;&lt;P&gt;  INTO TABLE i_mard&lt;/P&gt;&lt;P&gt;  WHERE matnr IN s_matnr&lt;/P&gt;&lt;P&gt;                       AND werks IN s_werks&lt;/P&gt;&lt;P&gt;                       AND lgort IN s_lgort.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    IF NOT li_mard[] IS INITIAL.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    SELECT *&lt;/P&gt;&lt;P&gt;    INTO TABLE wt_mkpf&lt;/P&gt;&lt;P&gt;    FROM MKPF&lt;/P&gt;&lt;P&gt;     FOR ALL ENTRIES IN li_mard&lt;/P&gt;&lt;P&gt;        WHERE   a~bukrs = p_bukrs&lt;/P&gt;&lt;P&gt;          AND a~matnr = li_mard-matnr&lt;/P&gt;&lt;P&gt;          AND a~werks = li_mard-werks&lt;/P&gt;&lt;P&gt;          AND a~lgort = li_mard-lgort&lt;/P&gt;&lt;P&gt;          AND b~budat &amp;gt;= s_dtper-low.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;     ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then try to get data from MSEG...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In any case don't use INTO CORRESPONDING.. it will take more DB time. Insteda u can use ABAP statements...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Apr 2007 09:23:32 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-04-05T09:23:32Z</dc:date>
    <item>
      <title>Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088208#M433826</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 problems trying to improve database access in SD requests.&lt;/P&gt;&lt;P&gt; I'm not the one who wrote the source code and now, I'm trying to modify it cause it's so bad that there is a 'Timeout' each time users try to launch it from production server.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The are a lot of requests. I began with the followings ones (hereunder is the original version) :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM mard WHERE matnr IN s_matnr
                       AND werks IN s_werks
*                      AND spart IN s_spart
                       AND lgort IN s_lgort.
*   Initialisation de la quantité
    CLEAR wmenge.
    wmenge = mard-insme + mard-einme + mard-speme + mard-retme.

    SELECT * FROM mseg WHERE bukrs = p_bukrs
                         AND matnr = mard-matnr
                         AND werks = mard-werks
                         AND lgort = mard-lgort.
Treatment
     SELECT * FROM mkpf WHERE mblnr = mseg-mblnr
                   AND mjahr = li_mseg-mjahr
                   AND budat &amp;gt;= s_dtper-low.
ENDSELECT.
ENDSELECT.
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I began with these modifications, it seems to be better but not enought at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM mard
  INTO CORRESPONDING FIELDS OF TABLE li_mard
  WHERE matnr IN s_matnr
                       AND werks IN s_werks
                       AND lgort IN s_lgort.

    IF NOT li_mard[] IS INITIAL.

    SELECT *
    INTO CORRESPONDING FIELDS OF TABLE wt_mseg
    FROM mseg AS a
    INNER JOIN mkpf AS b
        ON  a~mandt = b~mandt
           AND a~mblnr = b~mblnr
          AND a~mjahr = b~mjahr
    FOR ALL ENTRIES IN li_mard
        WHERE   a~bukrs = p_bukrs
          AND a~matnr = li_mard-matnr
          AND a~werks = li_mard-werks
          AND a~lgort = li_mard-lgort
          AND b~budat &amp;gt;= s_dtper-low.

     ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why dioo you thing about these modifications ? Can I do better ?&lt;/P&gt;&lt;P&gt;Do you any tips I can apply to solve this problem ?&lt;/P&gt;&lt;P&gt;An other thing to tell is that there are lot of other requests that take a long time and the analysis give my the following informations :&lt;/P&gt;&lt;P&gt;  - the most time is taken with table MSEG&lt;/P&gt;&lt;P&gt;  - More than 80% of the wasting time is lost in FETCH instructions.&lt;/P&gt;&lt;P&gt;  - there is a lot of small request with several "Select" .. "Endselect"  like :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
           select ....
               select 
                 select
                  ......
                 endselect
              endselect
           endselect&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for help cause it's a real brainstroming.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Morgan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 09:12:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088208#M433826</guid>
      <dc:creator>former_member246786</dc:creator>
      <dc:date>2007-04-05T09:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088209#M433827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this..&lt;/P&gt;&lt;P&gt;table i_mard is of type MARD....&lt;/P&gt;&lt;P&gt;SELECT * FROM mard&lt;/P&gt;&lt;P&gt;  INTO TABLE i_mard&lt;/P&gt;&lt;P&gt;  WHERE matnr IN s_matnr&lt;/P&gt;&lt;P&gt;                       AND werks IN s_werks&lt;/P&gt;&lt;P&gt;                       AND lgort IN s_lgort.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    IF NOT li_mard[] IS INITIAL.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    SELECT *&lt;/P&gt;&lt;P&gt;    INTO TABLE wt_mkpf&lt;/P&gt;&lt;P&gt;    FROM MKPF&lt;/P&gt;&lt;P&gt;     FOR ALL ENTRIES IN li_mard&lt;/P&gt;&lt;P&gt;        WHERE   a~bukrs = p_bukrs&lt;/P&gt;&lt;P&gt;          AND a~matnr = li_mard-matnr&lt;/P&gt;&lt;P&gt;          AND a~werks = li_mard-werks&lt;/P&gt;&lt;P&gt;          AND a~lgort = li_mard-lgort&lt;/P&gt;&lt;P&gt;          AND b~budat &amp;gt;= s_dtper-low.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;     ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then try to get data from MSEG...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In any case don't use INTO CORRESPONDING.. it will take more DB time. Insteda u can use ABAP statements...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 09:23:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088209#M433827</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-05T09:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088210#M433828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;create secondary index on MSEG table with fields of where clause.&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;Prabhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 09:31:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088210#M433828</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-05T09:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088211#M433829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is not possible to to what you are saying cause fields matnr, werks, lgort does not exist in mkpf.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 09:59:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088211#M433829</guid>
      <dc:creator>former_member246786</dc:creator>
      <dc:date>2007-04-05T09:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088212#M433830</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;SELECT matnr werks lgort "select only the required fields&lt;/P&gt;&lt;P&gt;     FROM mard &lt;/P&gt;&lt;P&gt;     INTO table i_mard&lt;/P&gt;&lt;P&gt;     WHERE matnr IN s_matnr&lt;/P&gt;&lt;P&gt;          AND werks IN s_werks&lt;/P&gt;&lt;P&gt;          AND lgort IN s_lgort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    SELECT MBLNR MJAHR&lt;/P&gt;&lt;P&gt;        FROM mseg &lt;/P&gt;&lt;P&gt;        INTO table i_msge&lt;/P&gt;&lt;P&gt;        FOR ALL ENTRIES IN I_MARD&lt;/P&gt;&lt;P&gt;        WHERE bukrs = p_bukrs&lt;/P&gt;&lt;P&gt;            AND matnr = i_mard-matnr&lt;/P&gt;&lt;P&gt;            AND werks = i_mard-werks&lt;/P&gt;&lt;P&gt;            AND lgort = i_mard-lgort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    SORT I_MSEG BY MBLNR MJAHR.&lt;/P&gt;&lt;P&gt;    DELETE ADJACENT DUPLICATES COMPARING MBLNR MJAHR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     SELECT *                 "select only req fields&lt;/P&gt;&lt;P&gt;         FROM mkpf &lt;/P&gt;&lt;P&gt;         INTO i_mkpf&lt;/P&gt;&lt;P&gt;         FOR ALL ENTRIES IN i_mseg&lt;/P&gt;&lt;P&gt;         WHERE mblnr = i_mseg-mblnr&lt;/P&gt;&lt;P&gt;               AND mjahr = i_mseg-mjahr&lt;/P&gt;&lt;P&gt;                   AND budat &amp;gt;= s_dtper-low.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**reward if helpful&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 10:21:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088212#M433830</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-05T10:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088213#M433831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thnks but the most part of the required fields for the report is the ones from MSEG,  the purpose isn't to display fields from mkpf (or only a small part of it).&lt;/P&gt;&lt;P&gt;So, I can not select only the fields from MSEG that join MSEG with MKPF.&lt;/P&gt;&lt;P&gt;According to me, it's the original request that is confusing because it make the selection from MKPF in second part but it must be first, just after mard.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 11:20:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088213#M433831</guid>
      <dc:creator>former_member246786</dc:creator>
      <dc:date>2007-04-05T11:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088214#M433832</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;You have to check your requirement.&lt;/P&gt;&lt;P&gt;As you say it should be MARD --&amp;gt; MKPF --&amp;gt; MSEG.&lt;/P&gt;&lt;P&gt;give in more details as ur requirement is not clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2007 11:31:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088214#M433832</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-05T11:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088215#M433833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;If your requirement is to get the data from MFPK and MSEG, it would always be better to get the data first from MKPF. Then get the details from MSEG, based on the document number in MKPF. Then you may process the data fetched from MSEG based on the details of 'MATNR', 'WERKS', 'LGORT', fecthed from the table 'MARD'. This would decrease the time used for selecting the data from Database. Also i guess the separate processing of the data rather than the direct statements on database might take less time.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;pavan k&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2007 15:26:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088215#M433833</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-07T15:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Improve Acces to SD data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088216#M433834</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;Try this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. do not use * anywhere in sqls&lt;/P&gt;&lt;P&gt;2. do not use corrosponding field clause&lt;/P&gt;&lt;P&gt;3. Important: User inner joins to join db tables as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select &amp;lt;fld names&amp;gt; into table g_itab&lt;/P&gt;&lt;P&gt;from mkpf as a inner join mseg as b on a&lt;SUB&gt;mblnr = b&lt;/SUB&gt;mblnr and a&lt;SUB&gt;mjahr = b&lt;/SUB&gt;mjahr&lt;/P&gt;&lt;P&gt;inner join mard as c where b&lt;SUB&gt;matnr = c&lt;/SUB&gt;matnr &lt;/P&gt;&lt;P&gt;where &amp;lt;all your where conditions&amp;gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;This is only way to improve this query. To improve it you should use more and more where criteria on KEY fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not use select and endselect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this will help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jogdand M B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2007 05:53:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improve-acces-to-sd-data/m-p/2088216#M433834</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-09T05:53:58Z</dc:date>
    </item>
  </channel>
</rss>

