<?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: Need Help in Select Statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663847#M1288074</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As correctly suggested above, always check if the table is not initial. Otherwise it will cause the full table scan and the program will run forever.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally, I would recommend using the same order in the SELECT statement as in the primary key of the table, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT belnr bldat xblnr
FROM bkpf 
INTO TABLE zbkpf
FOR ALL ENTRIES IN document_tab 
WHERE bukrs = 'TPF'
AND belnr = document_tab-belnr
AND gjahr = document_tab-gjahr&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although normally the optimizer should take care of this, sometimes coding in the exact order helps (also it makes the code a bit easier to maintain). There is no need for a secondary key since all the fields from a primary key are known.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2009 16:26:06 GMT</pubDate>
    <dc:creator>Jelena_Perfiljeva</dc:creator>
    <dc:date>2009-05-28T16:26:06Z</dc:date>
    <item>
      <title>Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663840#M1288067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear gurus.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is my select statement fetching data from table BKPF and comparing it from my internal table.&lt;/P&gt;&lt;P&gt;Problem is that BKPF table contain more then 50,000 entries. which take my program to hang&lt;/P&gt;&lt;P&gt;is there any solution to help my problem.&lt;/P&gt;&lt;P&gt;My Program is a Print program which take two inputs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Document No.&lt;/P&gt;&lt;P&gt;2) Facial year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT belnr bldat xblnr
     FROM bkpf
    INTO TABLE zbkpf
    FOR ALL ENTRIES IN document_tab
    WHERE belnr EQ document_tab-belnr
            AND bukrs EQ 'TPF'
          and  awtyp = 'BKPF'
          AND gjahr = document_tab-gjahr.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please Help&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Saad.Nisar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 05:30:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663840#M1288067</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T05:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663841#M1288068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Nisar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Try to use inner join instead of for all entries.&lt;/P&gt;&lt;P&gt;2. in below stmt follow key fields order i.e &lt;/P&gt;&lt;P&gt;SELECT belnr bldat xblnr&lt;/P&gt;&lt;P&gt;     FROM bkpf&lt;/P&gt;&lt;P&gt;    INTO TABLE zbkpf&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN document_tab&lt;/P&gt;&lt;P&gt;    WHERE belnr EQ document_tab-belnr&lt;/P&gt;&lt;P&gt;AND gjahr = document_tab-gjahr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;            AND bukrs EQ 'TPF'&lt;/P&gt;&lt;P&gt;          and  awtyp = 'BKPF'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rgds,&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 05:36:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663841#M1288068</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T05:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663842#M1288069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you sure this statement is causing an error? Well for all entries will cause performance issues. But then 50000 records to be queried. Not much I feel. Check your trace to see which statement is causing performance issues. It could be the nested loops or some bad program construct. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also check if the table used in for all entries is not initial. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
if not table[] is initial.
  select ...
  from bkpf
  for all entries in table
  where ....
endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Abdullah Ismail&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: ZAFCO ABAP on May 28, 2009 10:23 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 06:19:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663842#M1288069</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T06:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663843#M1288070</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;For All Entries is not always better than Join. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, I think 'For All Entries' should do for this query because the query is dealing with just one database table. As a suggestion, try sorting the internal table, remove all the duplicate entries, sort the database table and also check if the internal table is not initial before it processes the query. This will avoid execution of the query if the internal table is empty (For All Entries queries all records of the database table if the internal table is empty). On sorting, the performance could possibly tune itself decelty because the query need not scan the entire table for finding an entry.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Nitwick on May 28, 2009 9:09 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 07:06:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663843#M1288070</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T07:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663844#M1288071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;first put if document_tab not initial command,&lt;/P&gt;&lt;P&gt;then put some more where condition in the select table&lt;/P&gt;&lt;P&gt;just check secondary index in bkpf table&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 07:14:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663844#M1288071</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T07:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663845#M1288072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Saad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If sy-subrc = 0.&lt;/P&gt;&lt;P&gt;Sort document_tab by xblnr gjahr.&lt;/P&gt;&lt;P&gt;If not document_tab[] is initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT belnr bldat xblnr&lt;/P&gt;&lt;P&gt;     FROM bkpf&lt;/P&gt;&lt;P&gt;    INTO TABLE zbkpf&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN document_tab&lt;/P&gt;&lt;P&gt;    WHERE belnr EQ document_tab-belnr&lt;/P&gt;&lt;P&gt;            AND bukrs EQ 'TPF'&lt;/P&gt;&lt;P&gt;          and  awtyp = 'BKPF'&lt;/P&gt;&lt;P&gt;          AND gjahr = document_tab-gjahr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 11:23:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663845#M1288072</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T11:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663846#M1288073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Saad Nisar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can write the code in this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT document_tab[] IS INITIAL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     SORT document_tab BY BELNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     SELECT belnr bldat xblnr&lt;/P&gt;&lt;P&gt;         FROM bkpf &lt;/P&gt;&lt;P&gt;     INTO TABLE zbkpf&lt;/P&gt;&lt;P&gt;     FOR ALL ENTRIES IN document_tab &lt;/P&gt;&lt;P&gt;    WHERE belnr = document_tab-belnr&lt;/P&gt;&lt;P&gt;    AND bukrs = 'TPF'&lt;/P&gt;&lt;P&gt;   AND  gjahr = document_tab-gjahr&lt;/P&gt;&lt;P&gt;   AND  awtyp = 'BKPF'.&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;Hope this may some what increase the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or Try to check if there is any secondary index present.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prashant&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 15:52:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663846#M1288073</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T15:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663847#M1288074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As correctly suggested above, always check if the table is not initial. Otherwise it will cause the full table scan and the program will run forever.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally, I would recommend using the same order in the SELECT statement as in the primary key of the table, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT belnr bldat xblnr
FROM bkpf 
INTO TABLE zbkpf
FOR ALL ENTRIES IN document_tab 
WHERE bukrs = 'TPF'
AND belnr = document_tab-belnr
AND gjahr = document_tab-gjahr&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although normally the optimizer should take care of this, sometimes coding in the exact order helps (also it makes the code a bit easier to maintain). There is no need for a secondary key since all the fields from a primary key are known.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2009 16:26:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663847#M1288074</guid>
      <dc:creator>Jelena_Perfiljeva</dc:creator>
      <dc:date>2009-05-28T16:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663848#M1288075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; Although normally the optimizer should take care of this, sometimes coding in the exact order helps&lt;/P&gt;&lt;P&gt;is this really the case, in simple selects I have never seen that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; (also it makes the code a bit easier to maintain).&lt;/P&gt;&lt;P&gt;yes, this is true, also for cursor cache, it is recommended to have the same order as in the table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if there are more conditions than the primary key, then all conditions should be used, the additional&lt;/P&gt;&lt;P&gt;one are restrictions, i.e. not all lines come into the result !!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally check whether the FOR ALL ENTRIES has duplicates, if yes, do sort and delete adjacent duplicates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the then if there 50.000 records, expected, then it can need 50.000.000 micrsosec, i.e. 50seconds&lt;/P&gt;&lt;P&gt;as a rough estimate. How many records are in BKPF and who fast is your hardware. Even good performance takes some time &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&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, 28 May 2009 18:51:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663848#M1288075</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-28T18:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663849#M1288076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;One thing I would like to bring into your notice is that, when ever you are using for all entries, do select all the key fields, weather you are using those or not using those fields.&lt;/P&gt;&lt;P&gt;Else unexpected result will come.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Krishna..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2009 04:20:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663849#M1288076</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-29T04:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663850#M1288077</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 wondering why the biggest issue in this select is not mentioned. Whenever you use FOR ALL ENTRIES try all you can to use only one field of the table in the WHERE clause. As soon as you use more than one table field in the WHERE clause the table buffers are bypassed. So check if in your context one of the field might be the same for all entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Roman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Jun 2009 22:56:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663850#M1288077</guid>
      <dc:creator>romanweise</dc:creator>
      <dc:date>2009-06-06T22:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help in Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663851#M1288078</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;To increase the performance first do a sort function and add binary search with the key fields.&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;subhashini&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Jun 2009 05:14:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-in-select-statement/m-p/5663851#M1288078</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-07T05:14:25Z</dc:date>
    </item>
  </channel>
</rss>

