<?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: SELECT OPTIMIZATION URGENT in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838043#M664611</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 Statements Select Queries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Avoid nested selects&lt;/P&gt;&lt;P&gt;2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements. &lt;/P&gt;&lt;P&gt;3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index. &lt;/P&gt;&lt;P&gt;4. For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. &lt;/P&gt;&lt;P&gt;5. Use Select Single if all primary key fields are supplied in the Where condition .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 1&lt;/P&gt;&lt;P&gt;SELECT * FROM EKKO INTO EKKO_WA.&lt;/P&gt;&lt;P&gt;SELECT * FROM EKAN INTO EKAN_WA&lt;/P&gt;&lt;P&gt;WHERE EBELN = EKKO_WA-EBELN.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below.&lt;/P&gt;&lt;P&gt;SELECT P&lt;SUB&gt;F1 P&lt;/SUB&gt;F2 F&lt;SUB&gt;F3 F&lt;/SUB&gt;F4 INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;FROM EKKO AS P INNER JOIN EKAN AS F&lt;/P&gt;&lt;P&gt;ON P&lt;SUB&gt;EBELN = F&lt;/SUB&gt;EBELN.&lt;/P&gt;&lt;P&gt;Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA.&lt;/P&gt;&lt;P&gt;CHECK: SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table&lt;/P&gt;&lt;P&gt;SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK&lt;/P&gt;&lt;P&gt;WHERE SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 3&lt;/P&gt;&lt;P&gt;To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 4&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;UP TO 1 ROWS&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code is more optimized as compared to the code mentioned below for testing existence of a record.&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'.&lt;/P&gt;&lt;P&gt;EXIT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 5&lt;/P&gt;&lt;P&gt;If all primary key fields are supplied in the Where condition you can even use Select Single. &lt;/P&gt;&lt;P&gt;Select Single requires one communication with the database system, whereas Select-Endselect needs two.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Oct 2007 08:11:04 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-10-03T08:11:04Z</dc:date>
    <item>
      <title>SELECT OPTIMIZATION URGENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838041#M664609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to select data from this table FMIOI...&lt;/P&gt;&lt;P&gt;but it take a lotta time. DO U KNOW HOW TO OPTIMIZE IT??? &lt;/P&gt;&lt;P&gt;THIS IS URGENT!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HERE'S THE EXAMPLE.&lt;/P&gt;&lt;P&gt;  select&lt;/P&gt;&lt;P&gt;    REFBT&lt;/P&gt;&lt;P&gt;    RFORG&lt;/P&gt;&lt;P&gt;    RFPOS&lt;/P&gt;&lt;P&gt;    RFKNT&lt;/P&gt;&lt;P&gt;    RFETE&lt;/P&gt;&lt;P&gt;    RFTYP&lt;/P&gt;&lt;P&gt;    RFSYS&lt;/P&gt;&lt;P&gt;    STUNR&lt;/P&gt;&lt;P&gt;    GJAHR PERIO FIKRS BUKRS FONDS&lt;/P&gt;&lt;P&gt;    FISTL FIPEX WRTTP RLDNR BTART FKBTR&lt;/P&gt;&lt;P&gt;    REFBN&lt;/P&gt;&lt;P&gt;          from FMIOI&lt;/P&gt;&lt;P&gt;          into table IT_FMIOI&lt;/P&gt;&lt;P&gt;          for all entries in ALV3_DATA&lt;/P&gt;&lt;P&gt;          where&lt;/P&gt;&lt;P&gt;              ( FONDS in S04 ) and&lt;/P&gt;&lt;P&gt;              ( FIPEX = ALV3_DATA-S15 ) and&lt;/P&gt;&lt;P&gt;              ( FISTL = ALV3_DATA-S13 ) and&lt;/P&gt;&lt;P&gt;              ( GJAHR = Input_Data-S06 ) and&lt;/P&gt;&lt;P&gt;              ( PERIO = Input_Data-S08 ) and&lt;/P&gt;&lt;P&gt;              ( FIKRS = Input_Data-S02 ) and&lt;/P&gt;&lt;P&gt;              ( BUKRS = Input_Data-S00 )&lt;/P&gt;&lt;P&gt;          .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2007 08:04:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838041#M664609</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-03T08:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT OPTIMIZATION URGENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838042#M664610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;REFBT&lt;/P&gt;&lt;P&gt;RFORG&lt;/P&gt;&lt;P&gt;RFPOS&lt;/P&gt;&lt;P&gt;RFKNT&lt;/P&gt;&lt;P&gt;RFETE&lt;/P&gt;&lt;P&gt;RFTYP&lt;/P&gt;&lt;P&gt;RFSYS&lt;/P&gt;&lt;P&gt;STUNR&lt;/P&gt;&lt;P&gt;GJAHR PERIO FIKRS BUKRS FONDS&lt;/P&gt;&lt;P&gt;FISTL FIPEX WRTTP RLDNR BTART FKBTR&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;REFBN into corresponding fields of table it_fmi01 from fmio1&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;for all entries in ALV3_DATA&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;( FONDS in S04 ) and&lt;/P&gt;&lt;P&gt;( FIPEX = ALV3_DATA-S15 ) and&lt;/P&gt;&lt;P&gt;( FISTL = ALV3_DATA-S13 ) and&lt;/P&gt;&lt;P&gt;( GJAHR = Input_Data-S06 ) and&lt;/P&gt;&lt;P&gt;( PERIO = Input_Data-S08 ) and&lt;/P&gt;&lt;P&gt;( FIKRS = Input_Data-S02 ) and&lt;/P&gt;&lt;P&gt;( BUKRS = Input_Data-S00 )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2007 08:08:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838042#M664610</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-03T08:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT OPTIMIZATION URGENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838043#M664611</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 Statements Select Queries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Avoid nested selects&lt;/P&gt;&lt;P&gt;2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements. &lt;/P&gt;&lt;P&gt;3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index. &lt;/P&gt;&lt;P&gt;4. For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. &lt;/P&gt;&lt;P&gt;5. Use Select Single if all primary key fields are supplied in the Where condition .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 1&lt;/P&gt;&lt;P&gt;SELECT * FROM EKKO INTO EKKO_WA.&lt;/P&gt;&lt;P&gt;SELECT * FROM EKAN INTO EKAN_WA&lt;/P&gt;&lt;P&gt;WHERE EBELN = EKKO_WA-EBELN.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below.&lt;/P&gt;&lt;P&gt;SELECT P&lt;SUB&gt;F1 P&lt;/SUB&gt;F2 F&lt;SUB&gt;F3 F&lt;/SUB&gt;F4 INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;FROM EKKO AS P INNER JOIN EKAN AS F&lt;/P&gt;&lt;P&gt;ON P&lt;SUB&gt;EBELN = F&lt;/SUB&gt;EBELN.&lt;/P&gt;&lt;P&gt;Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA.&lt;/P&gt;&lt;P&gt;CHECK: SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table&lt;/P&gt;&lt;P&gt;SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK&lt;/P&gt;&lt;P&gt;WHERE SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 3&lt;/P&gt;&lt;P&gt;To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 4&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;UP TO 1 ROWS&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code is more optimized as compared to the code mentioned below for testing existence of a record.&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'.&lt;/P&gt;&lt;P&gt;EXIT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 5&lt;/P&gt;&lt;P&gt;If all primary key fields are supplied in the Where condition you can even use Select Single. &lt;/P&gt;&lt;P&gt;Select Single requires one communication with the database system, whereas Select-Endselect needs two.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2007 08:11:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-optimization-urgent/m-p/2838043#M664611</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-03T08:11:04Z</dc:date>
    </item>
  </channel>
</rss>

