<?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: regarding SELECT statements in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858033#M670136</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;&lt;/P&gt;&lt;P&gt;The following SELECT statements which hit the d/b and get the records and makes differnce performance wise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT....END SELECT (&amp;lt;i&amp;gt;BAD&amp;lt;/i&amp;gt; in Performance ) :&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the select hits the d/b one record as per the loop.&lt;/P&gt;&lt;P&gt;Suppose if u select 10 records it hits the dB 10 times to fetch the records.&lt;/P&gt;&lt;P&gt;so SELECT ENDSELECT each time it hits the database table and cause perforamnce issue bec of heavy traffiec.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex :&lt;/P&gt;&lt;P&gt;SELECT matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO  it1 UP TO n ROWS.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT INTO CORRESPONDING FIELDS...(Not good in performance).&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As per good coding standards this one is also not suggestable but it not couses that much of above statement.so it is better to be avoided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How the assigning reocords here is that once fetching is done it needs to assign it to the fields which are in the internal table as corresponding to the dB table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This arises because the field order is not the same in the internal table and in the dB. So this can be avoided by taking care to declare the fields in the internal table in the order they appear in dB.&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF it1 OCCURS 0,&lt;/P&gt;&lt;P&gt;      bukrs type bukrs,&lt;/P&gt;&lt;P&gt;      matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;      mbrsh TYPE mbrsh,&lt;/P&gt;&lt;P&gt;      belnr   type belnr,&lt;/P&gt;&lt;P&gt;      END OF it1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO CORESPONDING FIELDS OF TABLE  it1 UP TO n ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;The most efficient Select query would be:&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select field1 field2 field3&lt;/P&gt;&lt;P&gt;from table&lt;/P&gt;&lt;P&gt;into table int_tab&lt;/P&gt;&lt;P&gt;where conditions..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lively example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF it1 OCCURS 0,&lt;/P&gt;&lt;P&gt;      matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;      mbrsh TYPE mbrsh,&lt;/P&gt;&lt;P&gt;      END OF it1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO TABLE  it1 .&lt;/P&gt;&lt;P&gt;WHERE matnr eq p_matnr.&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  SORT it1 BY matnr.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT SINGLE :&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want select the single records like header data you can use this statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF it1 ,&lt;/P&gt;&lt;P&gt;      matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;      mbrsh TYPE mbrsh,&lt;/P&gt;&lt;P&gt;      END OF it1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO  it1 .&lt;/P&gt;&lt;P&gt;WHERE matnr eq p_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT....APPENDING TABLE :&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This syn use when r need to be insert the internla table wchih it contains records already ,say tbl_bsak contins initially 10 records again u need to add some records into this same internal table with differnt validations.&lt;/P&gt;&lt;P&gt;  SELECT * FROM  bsak&lt;/P&gt;&lt;P&gt;            APPENDING TABLE tbl_bsak&lt;/P&gt;&lt;P&gt;            WHERE bukrs IN s_bukrs&lt;/P&gt;&lt;P&gt;              AND augdt IN s_date&lt;/P&gt;&lt;P&gt;              AND gjahr IN r_gjahr&lt;/P&gt;&lt;P&gt;              AND belnr IN s_belnr&lt;/P&gt;&lt;P&gt;              AND blart IN s_blart&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    SORT tbl_bsak BY bukrs gjahr belnr monat.&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;These are some of select stataments which you can use in reports.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am giving some of SELECT statement TIPS while fetching data form d/b&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Select Statements within Loop processing is not recommended. Preferred approach is to select data into an itab and then read the itab to access specific records&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not use Nested Selects, Selects within Loops. or SELECT...ENDSELECT&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not use Select * unless at least 70% of fields are needed&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Select only the fields you require.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not use INTO CORRESPONDING&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not do Order By on non key fields&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Force optimizer to use the index where possible&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;If primary index can not be used, look for alternate indexes or alternate index tables&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Avoid Use of LIKE in the Where clause on index fields. It will force a non index read.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Avoid Use of NOT conditions in the Where clause on index fields. It will force a non index read.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Select Single MUST have the primary key fully specified in the WHERE clause. Otherwise use Select.. Up to 1 Rows.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Avoid DISTINCT see performance standards for usage&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Consider filtering on the appserver rather than in a WHERE statement&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;SAP Recommendation on Joins - try not to exceed a 3 Table Join&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;When using "Select.. For all Entries". The following 4 rules MUST be followed:&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;o Check to make sure driver itab is not empty&lt;/P&gt;&lt;P&gt;o Always SORT the itab (driver table) by keys. Specify all keys used in the Where clause&lt;/P&gt;&lt;P&gt;o DELETE Adjacent Duplicates Comparing the keys that were sorted.&lt;/P&gt;&lt;P&gt;o All Primary Key Fields must be in the Select List&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Rewards with points if helpful.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Sep 2007 07:09:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-09-21T07:09:13Z</dc:date>
    <item>
      <title>regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858029#M670132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;i m following these SELECT statements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. SELECT &amp;lt;fieldname1&amp;gt;&lt;/P&gt;&lt;P&gt;                 &amp;lt;fieldname2&amp;gt;&lt;/P&gt;&lt;P&gt;                 &amp;lt;fieldname3&amp;gt;&lt;/P&gt;&lt;P&gt;                 FROM &amp;lt;DB tablename&amp;gt; INTO TABLE &amp;lt;internal table&amp;gt;.&lt;/P&gt;&lt;P&gt;2. SELECT * FROM &amp;lt;DB tablename&amp;gt; INTO CORRESPONDING FIELDS OF TABLE        &lt;/P&gt;&lt;P&gt;&amp;lt;internal table&amp;gt;.&lt;/P&gt;&lt;P&gt;3. SELECT SINGLE * FROM &amp;lt;DB tablename&amp;gt; INTO CORRESPONDING FIELDS OF &amp;lt;work area&amp;gt;.&lt;/P&gt;&lt;P&gt;*****************************&lt;/P&gt;&lt;P&gt;can any of u plz help me in this...&lt;/P&gt;&lt;P&gt;plz give a brief description on varoius SELECT statements we can use and their functionality and perfomance....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards &amp;amp; thanks&lt;/P&gt;&lt;P&gt;venu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2007 18:24:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858029#M670132</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-20T18:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858030#M670133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;lt;b&amp;gt;This is good performance&amp;lt;/b&amp;gt;1. &lt;/P&gt;&lt;P&gt;This will get the all records from database table&lt;/P&gt;&lt;P&gt;SELECT &amp;lt;fieldname1&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;fieldname2&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;fieldname3&amp;gt;&lt;/P&gt;&lt;P&gt;FROM &amp;lt;DB tablename&amp;gt; INTO TABLE &amp;lt;internal table&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;This is bad performance (Do not use into &lt;/P&gt;&lt;P&gt;corresponding)&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;This will get the all records from database table&lt;/P&gt;&lt;P&gt;2. SELECT * FROM &amp;lt;DB tablename&amp;gt; INTO CORRESPONDING FIELDS OF TABLE &lt;/P&gt;&lt;P&gt;&amp;lt;internal table&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to get single record from database table then use below query&lt;/P&gt;&lt;P&gt;3. SELECT SINGLE * FROM &amp;lt;DB tablename&amp;gt; INTO CORRESPONDING FIELDS OF &amp;lt;work area&amp;gt;.&lt;/P&gt;&lt;P&gt;*****************************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Do not use into corresponding,this will cause performance issue&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Seshu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2007 18:38:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858030#M670133</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-20T18:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858031#M670134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using INTO CORRESPONDING FIELDS OF will give a small performance hit, but not much. If you add a field into the middle of the internal table that you aren't SELECTing, INTO CORRESPONDING FIELDS OF will allow this without further program changes. I use it all the time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;a href="/people/rob.burbank/blog/2006/11/16/performance--what-will-kill-you-and-what-will-leave-you-with-only-a-flesh-wound"&amp;gt;Performance - what will kill you and what will leave you with only a flesh wound&amp;lt;/a&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Sep 2007 19:13:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858031#M670134</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-20T19:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858032#M670135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a good question. Firstly you need to be introduced to bad practices to understand the better one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT....&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;End Select.&lt;/P&gt;&lt;P&gt;Here the select happens one record as per the loop.&lt;/P&gt;&lt;P&gt;Hence to select 10 records it hits the dB 10 times to fetch the records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select into corresponding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is okay not abusive as the first. &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But can be avoided.&lt;/P&gt;&lt;P&gt;The catch here is that once fetching is done it needs to assign it to the fields which are in the internal table as corresponding to the dB table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This arises because the field order is not the same in the internal table and in the dB. So this can be avoided by taking care to declare the fields in the internal table in the order they appear in dB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The most effective Select query would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select field1 field2 field3&lt;/P&gt;&lt;P&gt;from table&lt;/P&gt;&lt;P&gt;into table int_tab&lt;/P&gt;&lt;P&gt;where conditions..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lively example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT vbeln posnr vgbel&lt;/P&gt;&lt;P&gt;FROM lips&lt;/P&gt;&lt;P&gt;INTO TABLE it_lips&lt;/P&gt;&lt;P&gt;WHERE vgbel = it_vbap-vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also remember that while selecting the header data for a particular record, use Single.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE vbeln&lt;/P&gt;&lt;P&gt;FROM vbak&lt;/P&gt;&lt;P&gt;INTO v_vbeln2&lt;/P&gt;&lt;P&gt;WHERE vbeln EQ s_vbeln-high.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this would solve all your queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful. &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&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;Tej..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2007 05:40:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858032#M670135</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-21T05:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858033#M670136</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;&lt;/P&gt;&lt;P&gt;The following SELECT statements which hit the d/b and get the records and makes differnce performance wise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT....END SELECT (&amp;lt;i&amp;gt;BAD&amp;lt;/i&amp;gt; in Performance ) :&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the select hits the d/b one record as per the loop.&lt;/P&gt;&lt;P&gt;Suppose if u select 10 records it hits the dB 10 times to fetch the records.&lt;/P&gt;&lt;P&gt;so SELECT ENDSELECT each time it hits the database table and cause perforamnce issue bec of heavy traffiec.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex :&lt;/P&gt;&lt;P&gt;SELECT matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO  it1 UP TO n ROWS.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT INTO CORRESPONDING FIELDS...(Not good in performance).&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As per good coding standards this one is also not suggestable but it not couses that much of above statement.so it is better to be avoided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How the assigning reocords here is that once fetching is done it needs to assign it to the fields which are in the internal table as corresponding to the dB table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This arises because the field order is not the same in the internal table and in the dB. So this can be avoided by taking care to declare the fields in the internal table in the order they appear in dB.&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF it1 OCCURS 0,&lt;/P&gt;&lt;P&gt;      bukrs type bukrs,&lt;/P&gt;&lt;P&gt;      matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;      mbrsh TYPE mbrsh,&lt;/P&gt;&lt;P&gt;      belnr   type belnr,&lt;/P&gt;&lt;P&gt;      END OF it1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO CORESPONDING FIELDS OF TABLE  it1 UP TO n ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;The most efficient Select query would be:&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select field1 field2 field3&lt;/P&gt;&lt;P&gt;from table&lt;/P&gt;&lt;P&gt;into table int_tab&lt;/P&gt;&lt;P&gt;where conditions..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lively example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF it1 OCCURS 0,&lt;/P&gt;&lt;P&gt;      matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;      mbrsh TYPE mbrsh,&lt;/P&gt;&lt;P&gt;      END OF it1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO TABLE  it1 .&lt;/P&gt;&lt;P&gt;WHERE matnr eq p_matnr.&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  SORT it1 BY matnr.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT SINGLE :&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want select the single records like header data you can use this statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF it1 ,&lt;/P&gt;&lt;P&gt;      matnr TYPE matnr,&lt;/P&gt;&lt;P&gt;      mbrsh TYPE mbrsh,&lt;/P&gt;&lt;P&gt;      END OF it1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE matnr mbrsh&lt;/P&gt;&lt;P&gt;FROM mara INTO  it1 .&lt;/P&gt;&lt;P&gt;WHERE matnr eq p_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT....APPENDING TABLE :&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This syn use when r need to be insert the internla table wchih it contains records already ,say tbl_bsak contins initially 10 records again u need to add some records into this same internal table with differnt validations.&lt;/P&gt;&lt;P&gt;  SELECT * FROM  bsak&lt;/P&gt;&lt;P&gt;            APPENDING TABLE tbl_bsak&lt;/P&gt;&lt;P&gt;            WHERE bukrs IN s_bukrs&lt;/P&gt;&lt;P&gt;              AND augdt IN s_date&lt;/P&gt;&lt;P&gt;              AND gjahr IN r_gjahr&lt;/P&gt;&lt;P&gt;              AND belnr IN s_belnr&lt;/P&gt;&lt;P&gt;              AND blart IN s_blart&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    SORT tbl_bsak BY bukrs gjahr belnr monat.&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;These are some of select stataments which you can use in reports.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am giving some of SELECT statement TIPS while fetching data form d/b&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Select Statements within Loop processing is not recommended. Preferred approach is to select data into an itab and then read the itab to access specific records&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not use Nested Selects, Selects within Loops. or SELECT...ENDSELECT&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not use Select * unless at least 70% of fields are needed&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Select only the fields you require.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not use INTO CORRESPONDING&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Do not do Order By on non key fields&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Force optimizer to use the index where possible&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;If primary index can not be used, look for alternate indexes or alternate index tables&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Avoid Use of LIKE in the Where clause on index fields. It will force a non index read.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Avoid Use of NOT conditions in the Where clause on index fields. It will force a non index read.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Select Single MUST have the primary key fully specified in the WHERE clause. Otherwise use Select.. Up to 1 Rows.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Avoid DISTINCT see performance standards for usage&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Consider filtering on the appserver rather than in a WHERE statement&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;SAP Recommendation on Joins - try not to exceed a 3 Table Join&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;When using "Select.. For all Entries". The following 4 rules MUST be followed:&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;o Check to make sure driver itab is not empty&lt;/P&gt;&lt;P&gt;o Always SORT the itab (driver table) by keys. Specify all keys used in the Where clause&lt;/P&gt;&lt;P&gt;o DELETE Adjacent Duplicates Comparing the keys that were sorted.&lt;/P&gt;&lt;P&gt;o All Primary Key Fields must be in the Select List&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Rewards with points if helpful.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2007 07:09:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858033#M670136</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-21T07:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858034#M670137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try to avoid 'into corresponding', very often it is possible that you use an internal table with the same structure as the database table, then into corresponding is not necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As said above into corresponding is an offset. However, if your structures are different, then into corresponding can be useful, especially if your structures can change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;into table is for many records&lt;/P&gt;&lt;P&gt;single for one&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your questions are so basic that I would recommend to have a look into a good ABAP book for more and broader information.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2007 08:00:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858034#M670137</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-21T08:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858035#M670138</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 giving total ways of writing a select query with regarding to the performance &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Ways of Performance Tuning&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;1.	Selection Criteria &lt;/P&gt;&lt;P&gt;2.	Select Statements&lt;/P&gt;&lt;P&gt;&amp;#149;	Select Queries&lt;/P&gt;&lt;P&gt;&amp;#149;	SQL Interface&lt;/P&gt;&lt;P&gt;&amp;#149;	Aggregate Functions&lt;/P&gt;&lt;P&gt;&amp;#149;	For all Entries&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Select Over more than one Internal table&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Selection Criteria&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;1.	Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement.  &lt;/P&gt;&lt;P&gt;2.	Select with selection list.&lt;/P&gt;&lt;P&gt;Note: It is suggestible to make at least on field mandatory                             in Selection-Screen as mandatory fields restrict the data selection and hence increasing the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Points # 1/2&amp;lt;/b&amp;gt;&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 &lt;/P&gt;&lt;P&gt;&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;&amp;lt;b&amp;gt;Select Statements   Select Queries&amp;lt;/b&amp;gt;&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;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Point # 1&amp;lt;/b&amp;gt;&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;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Point # 2&amp;lt;/b&amp;gt;&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;&amp;lt;b&amp;gt;Point # 3&amp;lt;/b&amp;gt;&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;&amp;lt;b&amp;gt;Point # 4&amp;lt;/b&amp;gt;&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;&amp;lt;b&amp;gt;Point # 5&amp;lt;/b&amp;gt;&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;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Select Statements           contd..  SQL Interface&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.	Use column updates instead of single-row updates &lt;/P&gt;&lt;P&gt;to update your database tables.&lt;/P&gt;&lt;P&gt;2.	For all frequently used Select statements, try to use an index.&lt;/P&gt;&lt;P&gt;3.	Using buffered tables improves the performance considerably.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Point # 1&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT INTO SFLIGHT_WA.&lt;/P&gt;&lt;P&gt;  SFLIGHT_WA-SEATSOCC =&lt;/P&gt;&lt;P&gt;    SFLIGHT_WA-SEATSOCC - 1.&lt;/P&gt;&lt;P&gt;  UPDATE SFLIGHT FROM SFLIGHT_WA.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above mentioned code can be more optimized by using the following code&lt;/P&gt;&lt;P&gt;UPDATE SFLIGHT&lt;/P&gt;&lt;P&gt;       SET SEATSOCC = SEATSOCC - 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Point # 2&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;  WHERE CARRID = 'LH'&lt;/P&gt;&lt;P&gt;    AND CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above mentioned code can be more optimized by using the following code&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;  WHERE MANDT IN ( SELECT MANDT FROM T000 )&lt;/P&gt;&lt;P&gt;    AND CARRID = 'LH'&lt;/P&gt;&lt;P&gt;    AND CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Point # 3&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;Bypassing the buffer increases the network considerably&lt;/P&gt;&lt;P&gt;SELECT SINGLE * FROM T100 INTO T100_WA&lt;/P&gt;&lt;P&gt;  BYPASSING BUFFER&lt;/P&gt;&lt;P&gt;  WHERE     SPRSL = 'D'&lt;/P&gt;&lt;P&gt;        AND ARBGB = '00'&lt;/P&gt;&lt;P&gt;        AND MSGNR = '999'.&lt;/P&gt;&lt;P&gt;The above mentioned code can be more optimized by using the following code&lt;/P&gt;&lt;P&gt;SELECT SINGLE * FROM T100  INTO T100_WA&lt;/P&gt;&lt;P&gt;  WHERE     SPRSL = 'D'&lt;/P&gt;&lt;P&gt;        AND ARBGB = '00'&lt;/P&gt;&lt;P&gt;        AND MSGNR = '999'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Select Statements       contd&amp;#133;           Aggregate Functions&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149;	If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. &lt;/P&gt;&lt;P&gt;Some of the Aggregate functions allowed in SAP are  MAX, MIN, AVG, SUM, COUNT, COUNT( * )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the following extract.&lt;/P&gt;&lt;P&gt;            Maxno = 0.&lt;/P&gt;&lt;P&gt;            Select * from zflight where airln = &amp;#145;LF&amp;#146; and cntry = &amp;#145;IN&amp;#146;.&lt;/P&gt;&lt;P&gt;             Check zflight-fligh &amp;gt; maxno.&lt;/P&gt;&lt;P&gt;             Maxno = zflight-fligh.&lt;/P&gt;&lt;P&gt;            Endselect.&lt;/P&gt;&lt;P&gt;The  above mentioned code can be much more optimized by using the following code.&lt;/P&gt;&lt;P&gt; Select max( fligh ) from zflight into maxno where airln = &amp;#145;LF&amp;#146; and cntry = &amp;#145;IN&amp;#146;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Select Statements    contd&amp;#133;For All Entries&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149;	The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause. &lt;/P&gt;&lt;P&gt;	The plus &lt;/P&gt;&lt;P&gt;&amp;#149;	Large amount of data &lt;/P&gt;&lt;P&gt;&amp;#149;	Mixing processing and reading of data &lt;/P&gt;&lt;P&gt;&amp;#149;	Fast internal reprocessing of data &lt;/P&gt;&lt;P&gt;&amp;#149;	Fast &lt;/P&gt;&lt;P&gt;	The Minus &lt;/P&gt;&lt;P&gt;&amp;#149;	Difficult to program/understand &lt;/P&gt;&lt;P&gt;&amp;#149;	Memory could be critical (use FREE or PACKAGE size) &lt;/P&gt;&lt;P&gt;	&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Points to be must considered FOR ALL ENTRIES&amp;lt;/b&amp;gt; &amp;#149;	Check that data is present in the driver table&lt;/P&gt;&lt;P&gt;&amp;#149;	Sorting the driver table &lt;/P&gt;&lt;P&gt;&amp;#149;	Removing duplicates from the driver table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the following piece of extract&lt;/P&gt;&lt;P&gt; Loop at int_cntry.&lt;/P&gt;&lt;P&gt;       Select single * from zfligh into int_fligh&lt;/P&gt;&lt;P&gt; where cntry = int_cntry-cntry.&lt;/P&gt;&lt;P&gt; Append int_fligh. &lt;/P&gt;&lt;P&gt; Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above mentioned can be more optimized by using the following code.&lt;/P&gt;&lt;P&gt;Sort int_cntry by cntry.&lt;/P&gt;&lt;P&gt;Delete adjacent duplicates from int_cntry.&lt;/P&gt;&lt;P&gt;If NOT int_cntry[] is INITIAL.&lt;/P&gt;&lt;P&gt;            Select * from zfligh appending table int_fligh&lt;/P&gt;&lt;P&gt;            For all entries in int_cntry &lt;/P&gt;&lt;P&gt;            Where cntry = int_cntry-cntry.&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;&amp;lt;b&amp;gt;Select Statements    contd&amp;#133;  Select Over more than one Internal table&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.	Its better to use a views instead of nested Select statements.&lt;/P&gt;&lt;P&gt;2.	To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.&lt;/P&gt;&lt;P&gt;3.	Instead of using nested Select loops it is often better to use subqueries. &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Point # 1&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM DD01L INTO DD01L_WA&lt;/P&gt;&lt;P&gt;  WHERE DOMNAME LIKE 'CHAR%'&lt;/P&gt;&lt;P&gt;        AND AS4LOCAL = 'A'.&lt;/P&gt;&lt;P&gt;  SELECT SINGLE * FROM DD01T INTO DD01T_WA&lt;/P&gt;&lt;P&gt;    WHERE   DOMNAME    = DD01L_WA-DOMNAME&lt;/P&gt;&lt;P&gt;        AND AS4LOCAL   = 'A'&lt;/P&gt;&lt;P&gt;        AND AS4VERS    = DD01L_WA-AS4VERS&lt;/P&gt;&lt;P&gt;        AND DDLANGUAGE = SY-LANGU.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above code can be more optimized by extracting all the data from view DD01V_WA &lt;/P&gt;&lt;P&gt;SELECT * FROM DD01V INTO  DD01V_WA&lt;/P&gt;&lt;P&gt;  WHERE DOMNAME LIKE 'CHAR%'&lt;/P&gt;&lt;P&gt;        AND DDLANGUAGE = SY-LANGU.&lt;/P&gt;&lt;P&gt;ENDSELECT&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Point # 2&amp;lt;/b&amp;gt;&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;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Point # 3&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SPFLI&lt;/P&gt;&lt;P&gt;  INTO TABLE T_SPFLI&lt;/P&gt;&lt;P&gt;  WHERE CITYFROM = 'FRANKFURT'&lt;/P&gt;&lt;P&gt;    AND CITYTO = 'NEW YORK'.&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT AS F&lt;/P&gt;&lt;P&gt;    INTO SFLIGHT_WA&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN T_SPFLI&lt;/P&gt;&lt;P&gt;    WHERE SEATSOCC &amp;lt; F~SEATSMAX&lt;/P&gt;&lt;P&gt;      AND CARRID = T_SPFLI-CARRID&lt;/P&gt;&lt;P&gt;      AND CONNID = T_SPFLI-CONNID&lt;/P&gt;&lt;P&gt;      AND FLDATE BETWEEN '19990101' AND '19990331'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above mentioned code can be even more optimized by using subqueries instead of for all entries.&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA&lt;/P&gt;&lt;P&gt;    WHERE SEATSOCC &amp;lt; F~SEATSMAX&lt;/P&gt;&lt;P&gt;      AND EXISTS ( SELECT * FROM SPFLI&lt;/P&gt;&lt;P&gt;                     WHERE CARRID = F~CARRID&lt;/P&gt;&lt;P&gt;                       AND CONNID = F~CONNID&lt;/P&gt;&lt;P&gt;                       AND CITYFROM = 'FRANKFURT'&lt;/P&gt;&lt;P&gt;                       AND CITYTO = 'NEW YORK' )&lt;/P&gt;&lt;P&gt;      AND FLDATE BETWEEN '19990101' AND '19990331'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Reward if usefull&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2007 10:08:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858035#M670138</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-21T10:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858036#M670139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shree,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just my two cents.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not true that for SELECT ... END SELECT each single record is fetched from the database. The database interface still do array fetches (this could mean some hundred to some thousand rows dependent on the row width - but could be also much less) but the rows are processed in the application server row by row. It is still slower than the second example, but it would be much worse if it would be implemented as you described it (as long as PACKAGE SIZE is not used).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This type of SELECT statement has still some advantages. If you have to run over the hole table and you have memory constraints because of the table size and your memory, it could be an option to save memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would also agree to Rob, that INTO CORRESPONDING helps a lot to write more stable programs (stable here meant stable against structure changes), which is always worth the small performance impact.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Ralph&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Sep 2007 09:03:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858036#M670139</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-23T09:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: regarding SELECT statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858037#M670140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;about the 'INTO CORRESPONDING', it is often overestimated what a fieldlist (specifying fields instead of select *) will help. Fieldlist require new structures and the 'INTO CORRESPONDING'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use fieldlist only if you can decease table width dramatically&lt;/P&gt;&lt;P&gt;For the small rest 'INTO CORRESPONDING' is o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last comment that also the 'SELECT ... ENDSELECT' uses an array interface is right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Overall, the major performance issue with SELECTS is the correct usage of indices! This is point 1, point 2 and point 3, all other are of much lower importance!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2007 08:14:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-select-statements/m-p/2858037#M670140</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-24T08:14:45Z</dc:date>
    </item>
  </channel>
</rss>

