<?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: Tuning Select Statement . field sequence and where clause in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671776#M296860</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Amol,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have another hint:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The statement FOR ALL ENTRIES will package the select statements for every five entries in the internal table. So in comparison to the following code sequence...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT itab.
   SELECT * FROM table WHERE key = itab-key.
   ...
ENDLOOP&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the number of select statements is reduced to 20% with&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM table INTO TABLE ...
     FOR ALL ENTRIES IN itab
     WHERE key = itab-key&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I'm expecting a &amp;lt;i&amp;gt;huge&amp;lt;/i&amp;gt;  amount of data a go a step further and create my own packages by building a range table with around 100-500 entries and execute a select there...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab.
   IF counter &amp;lt; 500.
      APPEND itab-key TO range-tab.   " just code example
   ENDIF.
   IF count &amp;gt;= 500.
      SELECT * FROM table APPENDING TABLE ...
         WHERE key IN range_tab
   ENDIF.
   " adjust and calculate counter
ENDLOOP.
* Don't forget last select statement after loop&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;Florin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Nov 2006 09:04:07 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-11-14T09:04:07Z</dc:date>
    <item>
      <title>Tuning Select Statement . field sequence and where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671771#M296855</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;Are there any general guidelines how to write select &amp;lt; field sequence &amp;gt;where clause &amp;lt; field sequence ? Is that shuld be in order of the field sequence in tables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And how to use this when we have a view or a inner - join . Is that separate from normal select statement that is using FOR ALL ENTRIES.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know any general guidelines available on this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amol&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2006 08:07:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671771#M296855</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-14T08:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Tuning Select Statement . field sequence and where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671772#M296856</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;The only guideline is that your sequence in select should be same sequence you have in your internal table if you are not using "into corresponding fields of table".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Atul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2006 08:17:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671772#M296856</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-14T08:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Tuning Select Statement . field sequence and where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671773#M296857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Amol&lt;/P&gt;&lt;P&gt;When you are doing performance Tuning ,but these things in ur mind.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When writing select stmtn.&lt;/P&gt;&lt;P&gt;select field1&lt;/P&gt;&lt;P&gt;          field2 ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fields should be in order the way it is in DB  table.&lt;/P&gt;&lt;P&gt;In Where clause also try to use the Primary index fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using for all entries check sy-subrc = 0 after first select.&lt;/P&gt;&lt;P&gt;Try to avoid join if you are using more than 2 tables on select stmnt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you are reading select inside the loop..endloop.&lt;/P&gt;&lt;P&gt;Replace that select with Read stmnt and keep that select outside the loop and use for ell anetries..&lt;/P&gt;&lt;P&gt;Read stmnt shud follow binary search and before reading make sure u will have sort.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2006 08:23:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671773#M296857</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-14T08:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Tuning Select Statement . field sequence and where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671774#M296858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; While selecting any records from database tables following points should be bared in mind.&lt;/P&gt;&lt;P&gt;  1. Selection fields should be in same order as in the database table and of course in the internal table also,&lt;/P&gt;&lt;P&gt;  2. Try to specify where clause fields as much as possible.&lt;/P&gt;&lt;P&gt;  3. Try avoid using into corresponding fields. This will improve performance while handling huge data. Instead declare a local table with fields u want to select and then move it to ur internal table with more fields.&lt;/P&gt;&lt;P&gt; While using for all entries.&lt;/P&gt;&lt;P&gt;  1. It is very important to make sure the table that u are using with for all entires addition is not empty. Because empty table here would lead to selection of whole database table.&lt;/P&gt;&lt;P&gt; 2. Make sure the table dont contain any duplicates. Even though SAP will skip duplicate entries, unnecessarily you are loading SAP to check and skip the duplicaes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Hope these are usefull.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2006 08:31:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671774#M296858</guid>
      <dc:creator>former_member283648</dc:creator>
      <dc:date>2006-11-14T08:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Tuning Select Statement . field sequence and where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671775#M296859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at below weblog &lt;/P&gt;&lt;P&gt;/people/hema.rao/blog/2006/09/25/performance-tuning--an-overlooked-activity&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also have a look at below tips &lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/abap" target="test_blank"&gt;https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/abap&lt;/A&gt;&lt;EM&gt;Performance&lt;/EM&gt;and+Tuning&amp;amp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE. &lt;/P&gt;&lt;P&gt;Use WHERE clause in your SELECT statement to restrict the volume of data retrieved. &lt;/P&gt;&lt;P&gt;Design your Query to Use as much index fields as possible from left to right in your WHERE statement &lt;/P&gt;&lt;P&gt;Either enable buffering in your database table or create Indexes to speed up the query. &lt;/P&gt;&lt;P&gt;Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot. &lt;/P&gt;&lt;P&gt;Avoid using nested SELECT statement, SELECT within LOOPs. &lt;/P&gt;&lt;P&gt;Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE. &lt;/P&gt;&lt;P&gt;Avoid using SELECT * and Select only the required fields from the table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm" target="test_blank"&gt;http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Vibha &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Please mark all the helpful answers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2006 08:36:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671775#M296859</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-14T08:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Tuning Select Statement . field sequence and where clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671776#M296860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Amol,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have another hint:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The statement FOR ALL ENTRIES will package the select statements for every five entries in the internal table. So in comparison to the following code sequence...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT itab.
   SELECT * FROM table WHERE key = itab-key.
   ...
ENDLOOP&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the number of select statements is reduced to 20% with&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM table INTO TABLE ...
     FOR ALL ENTRIES IN itab
     WHERE key = itab-key&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I'm expecting a &amp;lt;i&amp;gt;huge&amp;lt;/i&amp;gt;  amount of data a go a step further and create my own packages by building a range table with around 100-500 entries and execute a select there...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab.
   IF counter &amp;lt; 500.
      APPEND itab-key TO range-tab.   " just code example
   ENDIF.
   IF count &amp;gt;= 500.
      SELECT * FROM table APPENDING TABLE ...
         WHERE key IN range_tab
   ENDIF.
   " adjust and calculate counter
ENDLOOP.
* Don't forget last select statement after loop&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;Florin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Nov 2006 09:04:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tuning-select-statement-field-sequence-and-where-clause/m-p/1671776#M296860</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-14T09:04:07Z</dc:date>
    </item>
  </channel>
</rss>

