<?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 single within Loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450547#M549136</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;It all depends upon the no of comparision primary fields available.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write the code for both and try running and check the performance during the peak hours then remove the other one&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Comment the some tables check the performance andf remove the tables which are taking more  time. for them use FOR ALL ENTRIES &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then use binary and read table &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will surely increase the performance of the report&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Jun 2007 06:15:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-06-22T06:15:47Z</dc:date>
    <item>
      <title>Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450544#M549133</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 have to optimize an existing code, this program runs monthly with huge data. It is using an inner join with more than 2 database tables. Also, which is better: &lt;/P&gt;&lt;P&gt;1. Select into itab2 for all entries in itab1, then Loop at itab1 and Read itab2.&lt;/P&gt;&lt;P&gt;2. Loop at itab1, then select single from database table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  select afpo~matnr&lt;/P&gt;&lt;P&gt;         makt~maktx&lt;/P&gt;&lt;P&gt;         afpo~charg&lt;/P&gt;&lt;P&gt;         afpo~wempf&lt;/P&gt;&lt;P&gt;         afko~aufnr&lt;/P&gt;&lt;P&gt;         afpo~wemng&lt;/P&gt;&lt;P&gt;         afko~gamng&lt;/P&gt;&lt;P&gt;         afko~stlbez&lt;/P&gt;&lt;P&gt;         afko~stlst&lt;/P&gt;&lt;P&gt;         afko~stlnr&lt;/P&gt;&lt;P&gt;         afko~sdatv&lt;/P&gt;&lt;P&gt;         mara~ferth&lt;/P&gt;&lt;P&gt;         s022~arbpl&lt;/P&gt;&lt;P&gt;  appending corresponding fields of table it_porder&lt;/P&gt;&lt;P&gt;     from afpo inner join afko on afpo&lt;SUB&gt;aufnr = afko&lt;/SUB&gt;aufnr&lt;/P&gt;&lt;P&gt;               inner join aufk on afpo&lt;SUB&gt;aufnr = aufk&lt;/SUB&gt;aufnr&lt;/P&gt;&lt;P&gt;               inner join mara on afpo&lt;SUB&gt;matnr = mara&lt;/SUB&gt;matnr&lt;/P&gt;&lt;P&gt;               inner join makt on afpo&lt;SUB&gt;matnr = makt&lt;/SUB&gt;matnr&lt;/P&gt;&lt;P&gt;                              and makt~spras = sy-langu&lt;/P&gt;&lt;P&gt;               inner join s022 on afpo&lt;SUB&gt;aufnr = s022&lt;/SUB&gt;aufnr&lt;/P&gt;&lt;P&gt;                              and afpo&lt;SUB&gt;matnr = s022&lt;/SUB&gt;matnr&lt;/P&gt;&lt;P&gt;    where afpo~matnr in p_matnr&lt;/P&gt;&lt;P&gt;      and afko~aufnr in p_aufnr&lt;/P&gt;&lt;P&gt;      and afko~gstrp in p_date&lt;/P&gt;&lt;P&gt;      and mara~mtart in ('FERT', 'HALB')&lt;/P&gt;&lt;P&gt;      and aufk~auart in ('FO11', 'PO11')&lt;/P&gt;&lt;P&gt;      and afko~gltri ne '00000000'.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 01:05:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450544#M549133</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T01:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450545#M549134</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 first option is always better. But make sure your itab1 has entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Atish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 01:08:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450545#M549134</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T01:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450546#M549135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As per my analysis since i have done Trace for complete select query's&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use Inner joins max 3 tables ,if it is more than 3 tables then go for all entries &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use select single if you have primary key condition otherwise use Select upto 1 row&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it is not good idea use select single within loop intead of that use normal select query outside of the loop and within loop use Read table with binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use Clear,refresh,free command properly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you want to compare diffrent select query use get run time field command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;simple example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : a type i,&lt;/P&gt;&lt;P&gt;         b type i,&lt;/P&gt;&lt;P&gt;         c type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start-of-selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;get runtime field a.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;here select query&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;get runtime field b.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;here a is starting time ,b ending time &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c = b - a.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; c.&lt;/P&gt;&lt;P&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>Fri, 22 Jun 2007 01:48:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450546#M549135</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T01:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450547#M549136</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;It all depends upon the no of comparision primary fields available.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write the code for both and try running and check the performance during the peak hours then remove the other one&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Comment the some tables check the performance andf remove the tables which are taking more  time. for them use FOR ALL ENTRIES &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then use binary and read table &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will surely increase the performance of the report&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 06:15:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450547#M549136</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T06:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450548#M549137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the responses. &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have a question on inner join. In the select statement above, if a record does not exist on table S022 but all the conditions in the where clause are satisfied, will the record still be included?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 08:08:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450548#M549137</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T08:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450549#M549138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The answer to your last question about an entry not exisitng in one table but existing in other is no.  An inner join only returns records that match all join conditions.  An outer join can be used to return values that exist in on table but not on another along with those that do match.  But generally you are safer removing that tbale from your SELECT and peforming an additinal select using FOR ALL ENTRIES&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 11:01:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450549#M549138</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T11:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450550#M549139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The join on S022 isn't using any key fields. If it is a large table, that is probably the source of your problem. Try taking just that out to see if the remaining SELECT runs more quickly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 13:35:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450550#M549139</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T13:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450551#M549140</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;While using INNER JOINS, if any one condition fails for any of db table, it will not fetch the record. So, if there is no record existing in S022, it will not return any record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding you question on for all entries and select single in loop,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not use Select statement in loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES: When the records in the internal table are in millions, then the select query will take lot of time.&lt;/P&gt;&lt;P&gt;Inorder to optimize the query, push the records of internal table into a buffer table and sort the records by the field used for comparing. Now delete adjacent duplicates from the buffer table.&lt;/P&gt;&lt;P&gt;This will reduce the number of records and hence optimize the query using for all entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Navneet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Jun 2007 21:20:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450551#M549140</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-23T21:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Select single within Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450552#M549141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks everyone. &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jun 2007 01:31:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-within-loop/m-p/2450552#M549141</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-26T01:31:39Z</dc:date>
    </item>
  </channel>
</rss>

