<?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: sql performance tuning in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266013#M1215943</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. The first select query is required as i want to fetch out all the service orders with MAT = AXX and with equipment no. starts with 1, so the itab must not be initial, do i still need to put the check: &lt;/P&gt;&lt;P&gt;'if not itab is initial.'  as suggested after the first select query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Mar 2009 14:55:58 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-03-16T14:55:58Z</dc:date>
    <item>
      <title>sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266009#M1215939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an SQL query with poor performance that it runs for at least 8 hrs +, I've tried to fine-tune it in many ways, but not much improvement is found:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="---------------------------------------------" /&gt;&lt;P&gt;ranges r_equnr for afih-equnr.&lt;/P&gt;&lt;P&gt;ranges r_ilart for afih-ilart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;r_equnr-sign = 'I'.&lt;/P&gt;&lt;P&gt;r_equnr-option = 'CP'.&lt;/P&gt;&lt;P&gt;r_equnr-low = '00000000001*'.&lt;/P&gt;&lt;P&gt;append r_equnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;r_ilart-sign = 'I'.&lt;/P&gt;&lt;P&gt;r_ilart-option = 'CP'.&lt;/P&gt;&lt;P&gt;r_ilart-low = 'A*'.&lt;/P&gt;&lt;P&gt;append r_ilart.   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select aufnr from afih into table itab &lt;/P&gt;&lt;P&gt;  where equnr in r_equnr and ilart in r_ilart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  select a&lt;SUB&gt;aufnr a&lt;/SUB&gt;mblnr a&lt;SUB&gt;mjahr a&lt;/SUB&gt;zeile b~budat&lt;/P&gt;&lt;P&gt;    into corresponding fields of table rtab &lt;/P&gt;&lt;P&gt;    from mseg as a inner join mkpf as b&lt;/P&gt;&lt;P&gt;    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;    for all entries in itab&lt;/P&gt;&lt;P&gt;    where a&lt;SUB&gt;aufnr = itab-aufnr and b&lt;/SUB&gt;cpudt in s_date&lt;/P&gt;&lt;P&gt;    and (  a&lt;SUB&gt;bwart = '261' or  a&lt;/SUB&gt;bwart = '262' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestion to greatly improve the performance?&lt;/P&gt;&lt;P&gt;Many Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2009 06:53:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266009#M1215939</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-16T06:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266010#M1215940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;1.First SELECT can have IPHAS( say = 2,4,6 check for the fixed values) in the WHERE condition.&lt;/P&gt;&lt;P&gt;2.Ensure it_tab[] IS NOT INITIAL&lt;/P&gt;&lt;P&gt;3.try to provide mkpf-budat also try to include matnr and werks from MSEG in the 2nd select ,WHERE cond.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2009 07:42:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266010#M1215940</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-16T07:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266011#M1215941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1)Try to add few more conditions in where condition while getting data from AFIH,data will be large in this.&lt;/P&gt;&lt;P&gt;2)In second select query you need to declare one more range for Movement type(BWART) and data in MSEG and MKPF usually will be huge and it will deffinately take some time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Rock.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2009 07:57:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266011#M1215941</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-16T07:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266012#M1215942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Macy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before the second select Query , there must be a check for entries in itab ..&lt;/P&gt;&lt;P&gt;with out that it may result for Time out dump .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select aufnr from afih into table itab &lt;/P&gt;&lt;P&gt;where equnr in r_equnr and ilart in r_ilart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT itab IS INITIAL .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a&lt;SUB&gt;aufnr a&lt;/SUB&gt;mblnr a&lt;SUB&gt;mjahr a&lt;/SUB&gt;zeile b~budat&lt;/P&gt;&lt;P&gt;into corresponding fields of table rtab &lt;/P&gt;&lt;P&gt;from mseg as a inner join mkpf as b&lt;/P&gt;&lt;P&gt;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;for all entries in itab&lt;/P&gt;&lt;P&gt;where a&lt;SUB&gt;aufnr = itab-aufnr and b&lt;/SUB&gt;cpudt in s_date&lt;/P&gt;&lt;P&gt;and ( a&lt;SUB&gt;bwart = '261' or a&lt;/SUB&gt;bwart = '262' ).&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;&lt;/P&gt;&lt;P&gt;Apart from that .,&lt;/P&gt;&lt;P&gt;  Why do you need that  first select query there u r just fetching all AUFNR againest the Select-options .&lt;/P&gt;&lt;P&gt;same thing directly u can write in the second one only .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just check wether u need that for any other purpose , if not better use select option directly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Sreenivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2009 09:06:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266012#M1215942</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-16T09:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266013#M1215943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. The first select query is required as i want to fetch out all the service orders with MAT = AXX and with equipment no. starts with 1, so the itab must not be initial, do i still need to put the check: &lt;/P&gt;&lt;P&gt;'if not itab is initial.'  as suggested after the first select query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2009 14:55:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266013#M1215943</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-16T14:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266014#M1215944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; create a secondary index on the first table (MSEG), based on field that you are using to select data plus the MANDT field (as first field).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Mar 2009 16:29:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266014#M1215944</guid>
      <dc:creator>andrea_galluccio2</dc:creator>
      <dc:date>2009-03-16T16:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266015#M1215945</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 to use IN instead of 'OR'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;and ( a&lt;SUB&gt;bwart = '261' or a&lt;/SUB&gt;bwart = '262' ).&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  and a~bwart IN ('261','262')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2009 00:52:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266015#M1215945</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-17T00:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266016#M1215946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andrea,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you show me how to create a 2nd index, any examples?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2009 01:54:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266016#M1215946</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-17T01:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266017#M1215947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;use below path for creation of secondary index for a table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Go to transaction SE11, open your database table. Choose the menu, Goto-&amp;gt;Indexes to create index. Give your index name and choose the fields of the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;Madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2009 14:06:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266017#M1215947</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-17T14:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266018#M1215948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt;  create a secondary index on the first table (MSEG), based on field that you are using&lt;/P&gt;&lt;P&gt;&amp;gt;  to select data plus the MANDT field (as first field).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just because one select is slow, is not a sufficient argument to create an index to a central table.&lt;/P&gt;&lt;P&gt;How many records aree in your MSEG table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2009 14:12:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266018#M1215948</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-17T14:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: sql performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266019#M1215949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
select aufnr from afih into table itab 
where equnr in r_equnr and ilart in r_ilart.

select a~aufnr a~mblnr a~mjahr a~zeile b~budat
into corresponding fields of table rtab 
from mseg as a inner join mkpf as b
on a~mblnr = b~mblnr and a~mjahr = b~mjahr
for all entries in itab
where a~aufnr = itab-aufnr and b~cpudt in s_date
and ( a~bwart = '261' or a~bwart = '262' ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The whole thing is very weird.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check with the SE11 and table entries, how many records you have in each of these tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why do you need the ranges?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
r_equnr-sign = 'I'.
r_equnr-option = 'CP'.
r_equnr-low = '00000000001*'.
append r_equnr.

r_ilart-sign = 'I'.
r_ilart-option = 'CP'.
r_ilart-low = 'A*'.
append r_ilart. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there are not more conditions then write a simple WHERE condition with LIKE !!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
select aufnr 
         from afih 
         into table itab 
         where equnr LIKE '00000000001*'
         and     ilart   LIKE 'A*'..
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then I would go for the complete join&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
select a~aufnr a~mblnr a~mjahr a~zeile b~budat
          into corresponding fields of table rtab 
          from             mkpf as b
          INNER JOIN mseg as a
          on a~mblnr = b~mblnr 
          and a~mjahr = b~mjahr 
          INNER JOIN  afih as c
          on a~aufnr = c~aufnr
          where b~cpudt in s_date
            and  a~bwart  in ( '261', '262' )
            and  c~equnr LIKE '00000000001*'
            and  c~ilart   LIKE 'A*'.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is probably one index missing&lt;/P&gt;&lt;P&gt;either on MKPF  on cpudt&lt;/P&gt;&lt;P&gt;or      on MSEG on aufnr&lt;/P&gt;&lt;P&gt;but first try without index. And tell us the size of the tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2009 14:41:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-performance-tuning/m-p/5266019#M1215949</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-17T14:41:35Z</dc:date>
    </item>
  </channel>
</rss>

