<?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: Performance problem in select statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143962#M1367438</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Samuel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your suggestion is actually very good however the problem is Contract document can not be linked to EKET table.&lt;/P&gt;&lt;P&gt;The only key that program can used is BANFN which is currently not included in the index of table EKPO.&lt;/P&gt;&lt;P&gt;I'm planning to create a new index for this table that used BANFN as the key so that my program can run significantly faster.&lt;/P&gt;&lt;P&gt;I'm assessing whether there is critical side affect when I create this index since this report is actually quite important report that will display link from PR until Invoice. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Abraham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Sep 2009 09:10:38 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-09-16T09:10:38Z</dc:date>
    <item>
      <title>Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143957#M1367433</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 am looking at one of the report in my organization due to performance issue.&lt;/P&gt;&lt;P&gt;The report have 2 select statement that look similar, using for all entries of Purch. Req (EBAN), to get PO data (EKKO).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) First select statement, execution time can be ignored, took less than 0.1 percent of total running time of the program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT a&lt;SUB&gt;banfn a&lt;/SUB&gt;bnfpo  a&lt;SUB&gt;ebeln  a&lt;/SUB&gt;ebelp b&lt;SUB&gt;konnr b&lt;/SUB&gt;bedat b~bstyp&lt;/P&gt;&lt;P&gt;           FROM       eket AS a&lt;/P&gt;&lt;P&gt;           INNER JOIN ekko AS b&lt;/P&gt;&lt;P&gt;           ON       a&lt;SUB&gt;ebeln = b&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;           INTO CORRESPONDING FIELDS OF TABLE it_a_intr_data&lt;/P&gt;&lt;P&gt;           FOR ALL ENTRIES IN it_eban_data&lt;/P&gt;&lt;P&gt;           WHERE  banfn    = it_eban_data-banfn&lt;/P&gt;&lt;P&gt;           AND    b~loekz  = ''&lt;/P&gt;&lt;P&gt;           AND    b~bstyp  = 'A'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Second select statement, execution time took 81.5% of total running time of the program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT b&lt;SUB&gt;banfn b&lt;/SUB&gt;bnfpo  a&lt;SUB&gt;ebeln  b&lt;/SUB&gt;ebelp a&lt;SUB&gt;bedat a&lt;/SUB&gt;bstyp c&lt;SUB&gt;belnr c&lt;/SUB&gt;vgabe&lt;/P&gt;&lt;P&gt;               FROM ( (        ekko AS a&lt;/P&gt;&lt;P&gt;               INNER JOIN      ekpo AS b  ON  a&lt;SUB&gt;ebeln = b&lt;/SUB&gt;ebeln )&lt;/P&gt;&lt;P&gt;               LEFT OUTER JOIN ekbe AS c  ON  b&lt;SUB&gt;ebeln = c&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;                           AND b&lt;SUB&gt;ebelp = c&lt;/SUB&gt;ebelp )&lt;/P&gt;&lt;P&gt;               INTO CORRESPONDING FIELDS OF TABLE it_k_intr_data&lt;/P&gt;&lt;P&gt;               FOR ALL ENTRIES IN it_eban_data&lt;/P&gt;&lt;P&gt;               WHERE  banfn = it_eban_data-banfn&lt;/P&gt;&lt;P&gt;               AND    b~loekz  = ''&lt;/P&gt;&lt;P&gt;               AND  ( a~bstyp  = 'K'&lt;/P&gt;&lt;P&gt;               OR     a~bstyp  = 'F' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems like the report used similar selection criteria with the first one, however with totally different result in term of performance. Anyone can highlight what's wrong in the second select statement? Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Abraham Bukit on Sep 16, 2009 1:32 PM&lt;/P&gt;&lt;P&gt;Fix spelling error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 05:31:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143957#M1367433</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T05:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143958#M1367434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i don't think both statements are similar the second select has a left outer join to EKBE which is a history table so it will contain more records than other two and as per what i have seen the left outer join will be expensive  than all entries.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 07:26:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143958#M1367434</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T07:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143959#M1367435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abraham,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In fact, your first query run fast since you use an index on table EKET (index EKET~E : &lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;&lt;STRONG&gt;MANDT / BANFN&lt;/STRONG&gt;&lt;/SPAN&gt; / BNFPO since MANDT is implicitely used).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But for the second query, you don't have any table which has field &lt;STRONG&gt;BANFN&lt;/STRONG&gt; indexed (other fields are not so restricitive)!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Moreover you have a join on 3 tables instead of 2, EKPO is a big table and you have a LEFT OUTER JOIN which is generally more consuming than INNER JOIN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On another hand, as you have to query including table EKKO, I suggest you to suppress it from the second one and modify your FOR ALL ENTRIES to carry on it_a_intr_data rather than it_eban_data. Like this you can enter on EBELN which would be an indexed field :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT b~banfn b~bnfpo b~ebeln b~ebelp a~bedat a~bstyp c~belnr c~vgabe
  FROM ekpo AS b
  LEFT OUTER JOIN ekbe AS c 
    ON b~ebeln = c~ebeln AND
       b~ebelp = c~ebelp
  INTO CORRESPONDING FIELDS OF TABLE it_k_intr_data
  FOR ALL ENTRIES IN it_a_intr_data
    WHERE ebeln   = it_a_intr_data-ebeln AND
          b~loekz = '' AND
        ( a~bstyp = 'K' OR
          a~bstyp = 'F' ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like this you should get the same data and your query should be faster!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Samuel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 08:23:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143959#M1367435</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T08:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143960#M1367436</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; Hi Abraham,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; In fact, your first query run fast since you use an index on table EKET (index EKET~E : &lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;&lt;STRONG&gt;MANDT / BANFN&lt;/STRONG&gt;&lt;/SPAN&gt; / BNFPO since MANDT is implicitely used).&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; But for the second query, you don't have any table which has field &lt;STRONG&gt;BANFN&lt;/STRONG&gt; indexed (other fields are not so restricitive)!&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Moreover you have a join on 3 tables instead of 2, EKPO is a big table and you have a LEFT OUTER JOIN which is generally more consuming than INNER JOIN.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; On another hand, as you have to query including table EKKO, I suggest you to suppress it from the second one and modify your FOR ALL ENTRIES to carry on it_a_intr_data rather than it_eban_data. Like this you can enter on EBELN which would be an indexed field :&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;/CODE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;CODE&gt;SELECT b~banfn b~bnfpo b~ebeln b~ebelp a~bedat a~bstyp c~belnr c~vgabe
&amp;gt;   FROM ekpo AS b
&amp;gt;   LEFT OUTER JOIN ekbe AS c 
&amp;gt;     ON b~ebeln = c~ebeln AND
&amp;gt;        b~ebelp = c~ebelp
&amp;gt;   INTO CORRESPONDING FIELDS OF TABLE it_k_intr_data
&amp;gt;   FOR ALL ENTRIES IN it_a_intr_data
&amp;gt;     WHERE ebeln   = it_a_intr_data-ebeln AND
&amp;gt;           b~loekz = '' AND
&amp;gt;         ( a~bstyp = 'K' OR
&amp;gt;           a~bstyp = 'F' ).&lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Like this you should get the same data and your query should be faster!&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Best regards,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Samuel&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for pointing that out, I guess I'm a bit tired when reading the code.&lt;/P&gt;&lt;P&gt;I also prefer your suggestion, where technically it is correct.&lt;/P&gt;&lt;P&gt;However, I'm still not sure whether the result will be the same or not.&lt;/P&gt;&lt;P&gt;In current select statement, program use PR number as a key to retrieve all PO related to this PR.&lt;/P&gt;&lt;P&gt;You suggest to use PO number in the PR records to get PO number.&lt;/P&gt;&lt;P&gt;Anyone can confirm whether both has the same result or not? Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 08:30:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143960#M1367436</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T08:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143961#M1367437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Abraham,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, you are right, BSTYP is not the same in both cases ('A' for 1st query and 'K'/'F' in the 2nd one).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And perhaps, if your 1st query is faster, it is perhaps also because you have far less PRs than POs in your system...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in order to you use indexes, you could split your join like this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* Select all Scheduling Agreement Schedule Lines (EKET)
SELECT banfn bnfpo ebeln ebelp
  FROM eket
  INTO CORRESPONDING FIELDS OF TABLE it_eket
  FOR ALL ENTRIES IN it_eban_data
    WHERE banfn = it_eban_data-banfn.

* Select all purchasing documents
SELECT ebeln konnr bedat bstyp
  FROM ekko
  INTO CORRESPONDING FIELDS OF TABLE it_ekko
  FOR ALL ENTRIES IN it_eket
    WHERE ebeln = it_eket-ebeln AND 
      loekz = '' AND 
      bstyp in ('A', 'F', 'K').

* Split into 2 parts : Purchase Request (BSTYP='A') and Purchase Order / Contracts (BSTYP = 'F' / 'K')
LOOP AT it_ekko ASSIGNING &amp;lt;fs_ekko&amp;gt;.
  IF &amp;lt;fs_ekko&amp;gt;-bstyp = 'A'.
    APPEND &amp;lt;fs_ekko&amp;gt; TO it_ekko_a.
 ELSE.
    APPEND &amp;lt;fs_ekko&amp;gt; TO it_ekko_f_k.
  ENDIF.
ENDLOOP.

* Select items corresponding only to POs
SELECT b~banfn b~bnfpo b~ebeln b~ebelp a~bedat a~bstyp c~belnr c~vgabe
  FROM ekpo AS b
  LEFT OUTER JOIN ekbe AS c 
    ON b~ebeln = c~ebeln AND
       b~ebelp = c~ebelp
  INTO CORRESPONDING FIELDS OF TABLE it_k_intr_data
  FOR ALL ENTRIES IN it_ekko_f_k
    WHERE ebeln   = it_ekko_f_k-ebeln AND
          b~loekz = '' AND
        ( a~bstyp = 'K' OR
          a~bstyp = 'F' ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it will be correct this time!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Samuel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 08:52:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143961#M1367437</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T08:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143962#M1367438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Samuel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your suggestion is actually very good however the problem is Contract document can not be linked to EKET table.&lt;/P&gt;&lt;P&gt;The only key that program can used is BANFN which is currently not included in the index of table EKPO.&lt;/P&gt;&lt;P&gt;I'm planning to create a new index for this table that used BANFN as the key so that my program can run significantly faster.&lt;/P&gt;&lt;P&gt;I'm assessing whether there is critical side affect when I create this index since this report is actually quite important report that will display link from PR until Invoice. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Abraham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 09:10:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143962#M1367438</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T09:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143963#M1367439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;DEL&gt;Maybe you can include a join on EKET in the second query as well, even if only for the sake of using index EKET~E. Check whether each EKPO has at lease one EKET entry (I believe this is the case).&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. sorry, doesn't work for contract items, as you said already.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 11:07:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143963#M1367439</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2009-09-16T11:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143964#M1367440</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;Just before select statement. Check for all entries internal table  is empty or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it might be empty.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nandha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 11:15:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143964#M1367440</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T11:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143965#M1367441</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; Hi,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Just before select statement. Check for all entries internal table  is empty or not.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; I think it might be empty.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Regards,&lt;/P&gt;&lt;P&gt;&amp;gt; Nandha&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not empty. The performance problem happen because select to EKPO using BANFN as the only key as pointed out by Samuel. EKPO does not have any index that make use of BANFN, hence it will loop entire records inside the table. I'm thinking of creating secondary index using BANFN and BNFPO as the non unique key but I'm still in the process of assessing the risk. I need to recheck this decision since it is not delivered as SAP standard even though the requirement is quite make sense, linking PR to RFQ, Contract and PO in a report. Thanks for the response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Abraham Bukit on Sep 16, 2009 11:26 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 15:26:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143965#M1367441</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T15:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143966#M1367442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are already using EKET in your first SELECT. Can you work that into the second one as well? That way you would be able to use its secondary index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 15:36:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143966#M1367442</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T15:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143967#M1367443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it aint broke don't fix it. If the first select takes just 0.1 percent of the total time, it is probably fine. I have concentrated on the second case that takes 81.5% of the total running time. The problem with that select statement is that you are reading table EKPO with BANFN, but there is no index on that particular field. You are effectively doing a full table scan on EKPO and hence the performance issue. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please implement the following code instead of the second select statement and let me know if your program runs faster. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_k_intr_data,
         banfn TYPE ekpo-banfn,
         bnfpo TYPE ekpo-bnfpo,
         ebeln TYPE ekko-ebeln,
         ebelp TYPE ekpo-ebelp,
         bedat TYPE ekko-bedat,
         bstyp TYPE ekko-bstyp,
         belnr TYPE ekbe-belnr,
         vgabe TYPE ekbe-vgabe,
       END OF ty_k_intr_data,

       BEGIN OF ty_ekko_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         banfn TYPE ekpo-banfn,
         bnfpo TYPE ekpo-bnfpo,
         bedat TYPE ekko-bedat,
         bstyp TYPE ekko-bstyp,
       END OF ty_ekko_ekpo,

       BEGIN OF ty_ekbe,
         ebeln TYPE ekbe-ebeln,
         ebelp TYPE ekbe-ebelp,
         zekkn TYPE ekbe-zekkn,
         vgabe TYPE ekbe-vgabe,
         gjahr TYPE ekbe-gjahr,
         belnr TYPE ekbe-belnr,
         buzei TYPE ekbe-buzei,
       END OF ty_ekbe.


DATA: w_k_intr_data    TYPE                 ty_k_intr_data,
      w_ekko_ekpo      TYPE                 ty_ekko_ekpo  ,
      w_ekbe           TYPE                 ty_ekbe       ,

      it_k_intr_data   TYPE        TABLE OF ty_k_intr_data,
      it_ekko_ekpo     TYPE        TABLE OF ty_ekko_ekpo  ,
      it_eban_data_tmp LIKE        TABLE OF it_eban_data  ,
      it_ekbe          TYPE SORTED TABLE OF ty_ekbe
        WITH NON-UNIQUE KEY ebeln ebelp.


IF NOT it_eban_data[] IS INITIAL.

  it_eban_data_tmp[] = it_eban_data[].

  SORT it_eban_data_tmp BY banfn.

  DELETE ADJACENT DUPLICATES FROM it_eban_data_tmp COMPARING banfn.

  SELECT b~ebeln
         b~ebelp
         b~banfn
         b~bnfpo
         c~bedat
         c~bstyp
    FROM       eban AS a
    INNER JOIN ekpo AS b
    ON  a~ebeln EQ b~ebeln
    AND a~ebelp EQ b~ebelp
    INNER JOIN ekko AS c
    ON b~ebeln EQ c~ebeln
    INTO TABLE it_ekko_ekpo
    FOR ALL ENTRIES IN it_eban_data_tmp
    WHERE a~banfn = it_eban_data_tmp-banfn
    AND   b~loekz = space
    AND ( c~bstyp = 'K'
    OR    c~bstyp = 'F' ).

  IF sy-subrc EQ 0.

    SELECT ebeln
           ebelp
           zekkn
           vgabe
           gjahr
           belnr
           buzei
           belnr
           vgabe
      FROM ekbe
      INTO TABLE it_ekbe
      FOR ALL ENTRIES IN it_ekko_ekpo
      WHERE ebeln EQ it_ekko_ekpo-ebeln
      AND   ebelp EQ it_ekko_ekpo-ebelp.


  ENDIF.

ENDIF.

LOOP AT it_ekko_ekpo INTO w_ekko_ekpo.

  w_k_intr_data-banfn = w_ekko_ekpo-banfn.

  w_k_intr_data-bnfpo = w_ekko_ekpo-bnfpo.

  w_k_intr_data-ebeln = w_ekko_ekpo-ebeln.

  w_k_intr_data-ebelp = w_ekko_ekpo-ebelp.

  w_k_intr_data-bedat = w_ekko_ekpo-bedat.

  w_k_intr_data-bstyp = w_ekko_ekpo-bstyp.


  READ TABLE it_ekbe WITH KEY ebeln = w_ekko_ekpo-ebeln
                              ebelp = w_ekko_ekpo-ebelp
                              TRANSPORTING NO FIELDS.

  IF sy-subrc EQ 0.

    LOOP AT it_ekbe INTO w_ekbe
      WHERE ebeln EQ w_ekko_ekpo-ebeln
      AND   ebelp EQ w_ekko_ekpo-ebelp.

      w_k_intr_data-belnr = w_ekbe-belnr.

      w_k_intr_data-vgabe = w_ekbe-vgabe.

      APPEND w_k_intr_data TO it_k_intr_data.

      CLEAR  w_k_intr_data.

    ENDLOOP.

  ELSE.

    APPEND w_k_intr_data TO it_k_intr_data.

  ENDIF.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Mark Christian on Sep 16, 2009 6:22 PM&lt;/P&gt;&lt;P&gt;The code functionality is not working again I see. I wonder how SAP can keep getting the same thing wrong so often? Please note that when ever SAP corrects this error again my post will appear legible.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 22:21:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143967#M1367443</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T22:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143968#M1367444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why does the code paste functionality fail so often (it has happened before and was fixed later)? I spent 20 minutes creating a solution and the message board software doesn't co-operate. Just take a look at my post. Believe you me it has the entire code in it but I doubt the asker will be able to read it at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you get somebody to take a look at this please?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's actually a "design feature". There is a 2.500 character limit to posts. I believe this is referred to in one of the stickies at the top opf the forum. So try to post only small snippets of code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Sep 17, 2009 9:04 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Sep 2009 22:49:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143968#M1367444</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-16T22:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143969#M1367445</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; Hi Rob,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Why does the code paste functionality fail so often (it has happened before and was fixed later)? I spent 20 minutes creating a solution and the message board software doesn't co-operate. Just take a look at my post. Believe you me it has the entire code in it but I doubt the asker will be able to read it at all.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Could you get somebody to take a look at this please?&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Thanks.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Regards,&lt;/P&gt;&lt;P&gt;&amp;gt; Mark&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't worry, I can read your code since it is forwarded to my e-mail.&lt;/P&gt;&lt;P&gt;I will check and come back with the result soon. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Abraham Bukit on Sep 17, 2009 9:14 AM&lt;/P&gt;&lt;P&gt;I just found out that 'email' is forbidden word&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2009 01:14:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143969#M1367445</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-17T01:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143970#M1367446</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; You are already using EKET in your first SELECT. Can you work that into the second one as well? That way you would be able to use its secondary index.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Rob&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's my initial plan Rob, until I found out that Contract does not have data in EKET table. Thanks for the suggestion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes and after I read the other posts I realized that as well. Sorry.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Sep 17, 2009 9:02 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2009 01:16:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143970#M1367446</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-17T01:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143971#M1367447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on your suggestion, if I'm using this select statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT b~ebeln&lt;/P&gt;&lt;P&gt;         b~ebelp&lt;/P&gt;&lt;P&gt;         b~banfn&lt;/P&gt;&lt;P&gt;         b~bnfpo&lt;/P&gt;&lt;P&gt;         c~bedat&lt;/P&gt;&lt;P&gt;         c~bstyp&lt;/P&gt;&lt;P&gt;    FROM       eban AS a&lt;/P&gt;&lt;P&gt;    INNER JOIN ekpo AS b&lt;/P&gt;&lt;P&gt;    ON  a&lt;SUB&gt;ebeln EQ b&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;    AND a&lt;SUB&gt;ebelp EQ b&lt;/SUB&gt;ebelp&lt;/P&gt;&lt;P&gt;    INNER JOIN ekko AS c&lt;/P&gt;&lt;P&gt;    ON b&lt;SUB&gt;ebeln EQ c&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;    INTO TABLE it_ekko_ekpo&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN it_eban_data_tmp&lt;/P&gt;&lt;P&gt;    WHERE a~banfn = it_eban_data_tmp-banfn&lt;/P&gt;&lt;P&gt;    AND   b~loekz = space&lt;/P&gt;&lt;P&gt;    AND ( c~bstyp = 'K'&lt;/P&gt;&lt;P&gt;    OR    c~bstyp = 'F' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will not get data for contract (bstyp = 'K') because it is not linked by EBAN-EBELN.&lt;/P&gt;&lt;P&gt;EBAN-EBELN field only contain PO number (bstyp = 'F').&lt;/P&gt;&lt;P&gt;Hence, I will still need to select to EKPO table using BANFN as the key for contract data and eventually will have same problem because it will scan the entire EKPO table. Thanks for the suggestion.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2009 01:28:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143971#M1367447</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-17T01:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Performance problem in select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143972#M1367448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the end, I create the index to speed things up. No further issue until today. Thanks everyone.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2010 05:50:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-problem-in-select-statement/m-p/6143972#M1367448</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-02T05:50:47Z</dc:date>
    </item>
  </channel>
</rss>

