<?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: Selects within loops in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253227#M487455</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please   go throught  the   SM30 There in the trips&amp;amp;trciks you can see the difference and  performance  of the all types of select query ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;place your program name  or  t.code   and   active   sql trace  , then  see it inthe  exact  ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do the same  in ST05   there  you can see the  SQL Statement  'SELECT'  how much time  it take   ...........&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards  points  if  it is usefull&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 21 May 2007 08:38:44 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-21T08:38:44Z</dc:date>
    <item>
      <title>Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253222#M487450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;I have been told that having selects within loops is a bad practice. Can anyone please tell me how having selects within loops may have a negative impact on performance?&lt;/P&gt;&lt;P&gt;I have a while loops in my program and within that while loop, I am running a select query on particular internal table. Is there any particular reason why I should be changing my code?&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Divyaman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 05:23:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253222#M487450</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T05:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253223#M487451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;when ever a SELECT statement has to be executed, it establishes a connection with the database server, &lt;/P&gt;&lt;P&gt;hence if you have select within a loop, it has to connect to database server so many times . instead if you write your select out of the loop there will be connection to data base server only once which will improve the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raghavendra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 05:46:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253223#M487451</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T05:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253224#M487452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Raghavendra for your response!&lt;/P&gt;&lt;P&gt;But, in my case, I am running the select query on an internal table. So, there should not be any performance degradation here because connection to the database is not required in each iteration of the loop. Correct me if I am wrong here!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Divyaman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 05:59:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253224#M487452</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T05:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253225#M487453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi divyaman,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that's not bad code to write which u have written,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;still u can avoid that select statement also by writing as follows,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if not &amp;lt;itab&amp;gt; is initial.&lt;/P&gt;&lt;P&gt;select * from &amp;lt;table&amp;gt; into &amp;lt;itab1&amp;gt; for all entries in &amp;lt;itab&amp;gt; where &amp;lt;field&amp;gt; eq &amp;lt;itab-field&amp;gt;.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this statement can still improve your performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;plz check once,,,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards..&lt;/P&gt;&lt;P&gt;seshu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 07:06:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253225#M487453</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T07:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253226#M487454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Divyaman,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;why do you want to write a select query on an internal table. instead read the required records for further processing, if not...use nested loops. &lt;/P&gt;&lt;P&gt;the performance depends on the internal table size. you can check the loop's performance using Get runtime command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 08:18:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253226#M487454</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T08:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253227#M487455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please   go throught  the   SM30 There in the trips&amp;amp;trciks you can see the difference and  performance  of the all types of select query ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;place your program name  or  t.code   and   active   sql trace  , then  see it inthe  exact  ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do the same  in ST05   there  you can see the  SQL Statement  'SELECT'  how much time  it take   ...........&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards  points  if  it is usefull&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 08:38:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253227#M487455</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T08:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253228#M487456</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 an e.g. say you have and itab with 100000 records and field matnr and u want material text i.e. maktx for that then there are two possibilities:&lt;/P&gt;&lt;P&gt;1. You are using loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at itab.

select single maktx into itab-maktx where....

modify itab transporting maktx.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here, u will find select statement is exectured once for each record.  this is is less performing codes as 1. each time is will take time to access db table and 2. search field from db table. so performance will be very less.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but, if u are using for all entries then codes will look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select matnr maktx into itab_matnr from makt FOR ALL ENTRIES IN itab where....
"Now update itab-maktx using itab_matnr-maktx&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will access data table only once and will be fetch all records so it will reduce overheades as in above e.g. like table access time etc.  so this second option is better may be this will reduce load on database but load will be shared by ABAP. bcoz itab enteris will be processed by using loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if there are very fiew records then u will not notice too much diffierence but for huge data second method is far better than first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jogdand M B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2007 08:55:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253228#M487456</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-21T08:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253229#M487457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks guys for your response! I've rewarded points to helpful answers.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2007 05:38:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253229#M487457</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-23T05:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Selects within loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253230#M487458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Instead of using select statments inside loops you can use it like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * from &amp;lt;table&amp;gt; INTO &amp;lt;iternal table&amp;gt; for all entries in &amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will imporove the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points for all useful answers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SaiRam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2007 09:28:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selects-within-loops/m-p/2253230#M487458</guid>
      <dc:creator>former_member196280</dc:creator>
      <dc:date>2007-05-23T09:28:24Z</dc:date>
    </item>
  </channel>
</rss>

