<?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: Problem with Select Statements in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008284#M1165922</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudhir&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please go through the SQL Trace results. Also, it'll be great if you avoid using Select..EndSelect and the group by statements. Moreoever, please get these Select Statements out of the loop. Incase you need them inside then you can put your data in an internal table instead of the variables and READ those itabs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Harsh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Jan 2009 04:17:07 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-01-14T04:17:07Z</dc:date>
    <item>
      <title>Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008276#M1165914</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;I have a performance problem for my report because of the following statements.&lt;/P&gt;&lt;P&gt;How can i modify the select statements for improving the performance of the report.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : shkzg1h  LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg1s  LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg2h  LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg2s  LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg1hu LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg1su LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg2hu LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         shkzg2su LIKE bsad-shkzg,&lt;/P&gt;&lt;P&gt;         kopbal1s  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal2s  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal1h  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal2h  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal1su  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal2su  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal1hu  LIKE bsad-dmbtr,&lt;/P&gt;&lt;P&gt;         kopbal2hu  LIKE bsad-dmbtr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*These statements are in LOOP.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg1s , kopbal1s)&lt;/P&gt;&lt;P&gt;      FROM bsid&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'S'&lt;/P&gt;&lt;P&gt;       AND umskz EQ ''&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg1su , kopbal1su)&lt;/P&gt;&lt;P&gt;      FROM bsid&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'S'&lt;/P&gt;&lt;P&gt;       AND umskz IN zspgl&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg1h , kopbal1h)&lt;/P&gt;&lt;P&gt;      FROM bsid&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'H'&lt;/P&gt;&lt;P&gt;       AND umskz EQ ''&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg1hu , kopbal1hu)&lt;/P&gt;&lt;P&gt;      FROM bsid&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'H'&lt;/P&gt;&lt;P&gt;       AND umskz IN zspgl&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg2s , kopbal2s)&lt;/P&gt;&lt;P&gt;      FROM bsad&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'S'&lt;/P&gt;&lt;P&gt;       AND umskz EQ ''&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg2su , kopbal2su)&lt;/P&gt;&lt;P&gt;      FROM bsad&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'S'&lt;/P&gt;&lt;P&gt;       AND umskz IN zspgl&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg2h , kopbal2h)&lt;/P&gt;&lt;P&gt;      FROM bsad&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'H'&lt;/P&gt;&lt;P&gt;       AND umskz EQ ''&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT shkzg SUM( dmbtr )&lt;/P&gt;&lt;P&gt;      INTO (shkzg2hu , kopbal2hu)&lt;/P&gt;&lt;P&gt;      FROM bsad&lt;/P&gt;&lt;P&gt;     WHERE bukrs = ibukrs&lt;/P&gt;&lt;P&gt;       AND kunnr = ktab-kunnr&lt;/P&gt;&lt;P&gt;       AND budat &amp;lt; idate-low&lt;/P&gt;&lt;P&gt;       AND shkzg = 'H'&lt;/P&gt;&lt;P&gt;       AND umskz IN zspgl&lt;/P&gt;&lt;P&gt;     GROUP BY shkzg.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 09:27:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008276#M1165914</guid>
      <dc:creator>sudhir_uppalapati</dc:creator>
      <dc:date>2008-12-30T09:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008277#M1165915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try to avoid endselect&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 09:29:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008277#M1165915</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-30T09:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008278#M1165916</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;Can you provide me the sample statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 09:34:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008278#M1165916</guid>
      <dc:creator>sudhir_uppalapati</dc:creator>
      <dc:date>2008-12-30T09:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008279#M1165917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudhir,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Using SELECT SINGLE is the better way for performance. Firstly READ statement for single value rather than LOOP&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Data:
  w_index type i value 1,
  w_lines type i.
Describe table ktab lines w_lines.
While w_index LE w_lines.
Read table ktab index w_index.
SELECT single shkzg SUM( dmbtr )
INTO (shkzg1s , kopbal1s)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr  " hope here you are passing a single value
AND budat &amp;lt; idate-low
AND shkzg = 'S'
AND umskz EQ ''
GROUP BY shkzg.
w_index = w_index + 1.
Endwhile.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With luck,&lt;/P&gt;&lt;P&gt;Pritam.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Pritam Ghosh on Dec 30, 2008 10:48 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 09:40:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008279#M1165917</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-30T09:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008280#M1165918</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;You should avoid the &lt;STRONG&gt;END select&lt;/STRONG&gt; and &lt;STRONG&gt;Group by&lt;/STRONG&gt; to improve your coding performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;Jay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 10:05:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008280#M1165918</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-30T10:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008281#M1165919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;               To improve the performance,plz use SELECT single statement and if possible dependence on ur requirement its better reterive the data out side the loop  statement and read it using read statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anil.D&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 12:07:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008281#M1165919</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-30T12:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008282#M1165920</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;Check if you can replace the Select - End select of your programming logic and try some alternate way of achieving the same with a single fetch from the tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this way the data base access will be greatly reduced and hence the perfomce can be increased.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Radhika.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 12:10:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008282#M1165920</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-30T12:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008283#M1165921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please stop writing answers if you understrand nothing about database SELECTS!&lt;/P&gt;&lt;P&gt;All above recommendations are pure nonsense!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As always with such questions, you must do an analysis before you ask! The coding itself is perfectly o.k., a SELECT with an aggregate and a GROUP BY can not be changed into a SELECT SINGLE or whatever.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But your SELECTS mustr be supported by indexes!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please run SQL Trace, and tell us the results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see 8 statements, what is the duration and the number of records coming back for each statement?&lt;/P&gt;&lt;P&gt;Maybe only one statement is slow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See&lt;/P&gt;&lt;P&gt;SQL trace:&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_blogpost" href="https://community.sap.com/" __jive_macro_name="blogpost" modifiedtitle="true" __default_attr="44587"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Dec 2008 12:35:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008283#M1165921</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-30T12:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008284#M1165922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudhir&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please go through the SQL Trace results. Also, it'll be great if you avoid using Select..EndSelect and the group by statements. Moreoever, please get these Select Statements out of the loop. Incase you need them inside then you can put your data in an internal table instead of the variables and READ those itabs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Harsh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2009 04:17:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008284#M1165922</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-14T04:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008285#M1165923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Please stop writing answers if you understrand nothing about database SELECTS!&lt;/P&gt;&lt;P&gt;&amp;gt; All above recommendations are pure nonsense!&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; As always with such questions, you must do an analysis before you ask! The coding itself is perfectly o.k., a SELECT with an aggregate and a GROUP BY can not be changed into a SELECT SINGLE or whatever.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; But your SELECTS mustr be supported by indexes!&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Please run SQL Trace, and tell us the results:&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; I see 8 statements, what is the duration and the number of records coming back for each statement?&lt;/P&gt;&lt;P&gt;&amp;gt; Maybe only one statement is slow.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; See&lt;/P&gt;&lt;P&gt;&amp;gt; SQL trace:&lt;/P&gt;&lt;P&gt;&amp;gt; /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Siegfried&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nice point there Siegfried. Instead of giving constructive suggestion, people here give a very bad suggestion on using SELECT SINGLE combined with SUM and GROUP BY. &lt;/P&gt;&lt;P&gt;I hope the person already look at your reply before he try using select single and wondering why he has error. &lt;/P&gt;&lt;P&gt;Anyway, the most important thing is how many loop expected for those select statements?&lt;/P&gt;&lt;P&gt;If you have like thousands of loop, you can expect a poor performance.&lt;/P&gt;&lt;P&gt;So, you should also look at how many times the select statement is called and not only performance for each select statement when you're doing SQL trace.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Abraham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2009 08:45:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008285#M1165923</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-14T08:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008286#M1165924</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;in u r all select statements are writing inside the loop,and u r using the select .... endselect.therese all statements problem with performance,dont use the select statement with in the loop .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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>Thu, 15 Jan 2009 09:34:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008286#M1165924</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-15T09:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008287#M1165925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudhir,&lt;/P&gt;&lt;P&gt;Instead of using these statements inside the loop,&lt;/P&gt;&lt;P&gt;you can use ranges as we can't use for all entries for aggregate functions other than count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For refference look into the below example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;RANGES: r_cust FOR wa_ktab-kunnr.

LOOP AT ktab INTO wa_ktab "Assuming you are looping at ktab

  r_cust-sign = 'I'.
  r_cust-option = 'EQ'.
  r_cust-low = wa_ktab-kunnr.

  APPEND r_cust.
ENDLOOP.

"Instead of using delect stmts inside the loop use as follows
SELECT shkzg SUM( dmbtr )
INTO  TABLE &amp;lt;itab&amp;gt;  "Table contains fields shkzg1s , kopbal1s
FROM bsid
WHERE bukrs = ibukrs
AND kunnr IN r_cust "Use your ranges
AND budat &amp;lt; idate-low
AND shkzg = 'S'
AND umskz EQ ''
GROUP BY shkzg.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&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 helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Manoj Kumar P&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Manoj Kumar on Jan 16, 2009 6:56 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Jan 2009 05:45:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008287#M1165925</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-16T05:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Select Statements</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008288#M1165926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudhir,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First thing you should always avoid select statements inside a loop. This effects the performance a lot.&lt;/P&gt;&lt;P&gt;Second thing is you are always hitting the BSID, BSAD tables again and again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead you can do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you read complete BSID and BSAD tables into internal tables outside the loop. And use a read statement inside the loop where ever required this improves the performance a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And one more thing is it is better to use UP TO 1 ROWS statement and ENDSELECT statement rather than using without up to 1 rows statement.&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>Tue, 20 Jan 2009 10:05:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-select-statements/m-p/5008288#M1165926</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-20T10:05:37Z</dc:date>
    </item>
  </channel>
</rss>

