<?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: sql statement too slow in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861521#M1592995</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 your loop .. endloop statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can write as :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort GT_GLACC by BUDAT descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Delete GT_GLACC where BUDAT &amp;gt; S_CPUDT-HIGH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort GT_GLACC2 by CPUDT .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT GT_GLAC2 where CPUDT &amp;lt; S_CPUDT-LOW..&lt;/P&gt;&lt;P&gt;  MOVE-CORRESPONDING GT_GLAC2 TO GT_GLACC.&lt;/P&gt;&lt;P&gt;  APPEND GT_GLACC.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Srini.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 May 2011 06:19:40 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-05-11T06:19:40Z</dc:date>
    <item>
      <title>sql statement too slow</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861520#M1592994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For some reason I have to change code from this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
               LOOP AT GT_SKA1.
			SELECT A~BELNR A~GJAHR A~BUZEI A~BUKRS A~HKONT A~SHKZG A~KOSTL B~HWAER A~DMBTR B~BKTXT A~BLDAT A~BUDAT B~CPUDT B~CPUTM B~USNAM
			FROM BSIS AS A INNER JOIN BKPF AS B ON A~BUKRS = B~BUKRS AND
												   A~GJAHR = B~GJAHR AND
												   A~BELNR = B~BELNR
			APPENDING CORRESPONDING FIELDS OF TABLE GT_GLACC
			WHERE A~HKONT = GT_SKA1-SAKNR AND
				  A~BUKRS IN S_WERKS AND
				  A~BLDAT IN S_BLDAT AND
				  A~BUDAT IN S_BUDAT AND
				  B~CPUDT IN S_CPUDT AND
				  B~USNAM IN S_USNAM AND
				  B~BLART NE 'WA'.
		ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
			SELECT A~BELNR A~GJAHR A~BUZEI A~BUKRS A~HKONT A~SHKZG A~KOSTL B~HWAER A~DMBTR B~BKTXT A~BLDAT A~BUDAT B~CPUDT B~CPUTM B~USNAM
			FROM BSIS AS A INNER JOIN BKPF AS B ON A~BUKRS = B~BUKRS AND
												   A~GJAHR = B~GJAHR AND
												   A~BELNR = B~BELNR
			APPENDING CORRESPONDING FIELDS OF TABLE GT_GLACC
			WHERE A~HKONT IN S_SAKNR AND
				  A~BUKRS IN S_WERKS AND
				  B~CPUDT IN S_CPUDT AND
				  B~USNAM IN S_USNAM AND
				  B~BLART NE 'WA'.
				  
			SELECT A~BELNR A~GJAHR A~BUZEI A~BUKRS A~HKONT A~SHKZG A~KOSTL B~HWAER A~DMBTR B~BKTXT A~BLDAT A~BUDAT B~CPUDT B~CPUTM B~USNAM
			FROM BSIS AS A INNER JOIN BKPF AS B ON A~BUKRS = B~BUKRS AND
												   A~GJAHR = B~GJAHR AND
												   A~BELNR = B~BELNR
			APPENDING CORRESPONDING FIELDS OF TABLE GT_GLAC2
			WHERE A~HKONT IN S_SAKNR AND
				  A~BUKRS IN S_WERKS AND
				  A~BUDAT IN S_CPUDT AND
				  B~USNAM IN S_USNAM AND
				  B~BLART NE 'WA'.
*delete entries which posting date greater than higher limit of selected period
		LOOP AT GT_GLACC.
			IF GT_GLACC-BUDAT &amp;gt; S_CPUDT-HIGH.
				DELETE GT_GLACC.
			ENDIF.
		ENDLOOP.
*delete entries which entry date greater than lower limit of selected period
		LOOP AT GT_GLAC2.
			IF GT_GLAC2-CPUDT &amp;lt; S_CPUDT-LOW.
				MOVE-CORRESPONDING GT_GLAC2 TO GT_GLACC.
				APPEND GT_GLACC.
			ENDIF.
		ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, the resulted code is very slow. The original one only runs around 10 minutes while the resulted one need to be run for 10 hours.&lt;/P&gt;&lt;P&gt;Actually, the sql statement did not change much and I only run two times for it in the new code design.&lt;/P&gt;&lt;P&gt;I want to ask why is it so slow and any solution for this.&lt;/P&gt;&lt;P&gt;Thanks, Experts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2011 06:09:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861520#M1592994</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-11T06:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: sql statement too slow</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861521#M1592995</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 your loop .. endloop statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can write as :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort GT_GLACC by BUDAT descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Delete GT_GLACC where BUDAT &amp;gt; S_CPUDT-HIGH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort GT_GLACC2 by CPUDT .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT GT_GLAC2 where CPUDT &amp;lt; S_CPUDT-LOW..&lt;/P&gt;&lt;P&gt;  MOVE-CORRESPONDING GT_GLAC2 TO GT_GLACC.&lt;/P&gt;&lt;P&gt;  APPEND GT_GLACC.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Srini.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2011 06:19:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861521#M1592995</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-11T06:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: sql statement too slow</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861522#M1592996</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;Because you are retriving data from database tables comparing with single record. check below code which statement is in red color.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT GT_SKA1.&lt;/P&gt;&lt;P&gt;SELECT A&lt;SUB&gt;BELNR A&lt;/SUB&gt;GJAHR A&lt;SUB&gt;BUZEI A&lt;/SUB&gt;BUKRS A&lt;SUB&gt;HKONT A&lt;/SUB&gt;SHKZG A&lt;SUB&gt;KOSTL B&lt;/SUB&gt;HWAER A&lt;SUB&gt;DMBTR B&lt;/SUB&gt;BKTXT A&lt;SUB&gt;BLDAT A&lt;/SUB&gt;BUDAT B&lt;SUB&gt;CPUDT B&lt;/SUB&gt;CPUTM B~USNAM&lt;/P&gt;&lt;P&gt;FROM BSIS AS A INNER JOIN BKPF AS B ON A&lt;SUB&gt;BUKRS = B&lt;/SUB&gt;BUKRS AND&lt;/P&gt;&lt;P&gt;									A&lt;SUB&gt;GJAHR = B&lt;/SUB&gt;GJAHR AND&lt;/P&gt;&lt;P&gt;									        A&lt;SUB&gt;BELNR = B&lt;/SUB&gt;BELNR&lt;/P&gt;&lt;P&gt;APPENDING CORRESPONDING FIELDS OF TABLE GT_GLACC&lt;/P&gt;&lt;P&gt;WHERE A~HKONT = GT_SKA1-SAKNR AND            " Because of this line the code performance is good&lt;/P&gt;&lt;P&gt;A~BUKRS IN S_WERKS AND&lt;/P&gt;&lt;P&gt;A~BLDAT IN S_BLDAT AND&lt;/P&gt;&lt;P&gt;A~BUDAT IN S_BUDAT AND&lt;/P&gt;&lt;P&gt;B~CPUDT IN S_CPUDT AND&lt;/P&gt;&lt;P&gt;B~USNAM IN S_USNAM AND&lt;/P&gt;&lt;P&gt;B~BLART NE 'WA'.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ram.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2011 06:21:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861522#M1592996</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-11T06:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: sql statement too slow</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861523#M1592997</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; If you are selecting a lot of data into table GT_GLACC, I would say the problem is with the DELETE command.&lt;/P&gt;&lt;P&gt;It is very time consuming to DELETE entries from a large table in ABAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To avoid using DELETE, try this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*delete entries which posting date greater than higher limit of selected period

*create a filtered table of the items we wish to keep 
		LOOP AT GT_GLACC.
			IF GT_GLACC-BUDAT &amp;lt;= S_CPUDT-HIGH.
		                         APPEND GT_GLACC to GT_GLACC_KEEP.
			ENDIF.
		ENDLOOP.
*overwrite the original table with the filtered table
                                          MOVE GT_GLACC_KEEP[] to GT_GLACC[].
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2011 06:27:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861523#M1592997</guid>
      <dc:creator>paul_bakker2</dc:creator>
      <dc:date>2011-05-11T06:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: sql statement too slow</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861524#M1592998</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;Try to avoid  'CORRESPONDING FIELDS OF' Statement in Select Statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2011 06:42:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861524#M1592998</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-11T06:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: sql statement too slow</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861525#M1592999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem solved.&lt;/P&gt;&lt;P&gt;Now I instead of looping the table gt_ska1 to run sql statement,&lt;/P&gt;&lt;P&gt;I loop through the table and insert all values into a select option.&lt;/P&gt;&lt;P&gt;Then rewriting the sql statement like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT A~BELNR A~GJAHR A~BUZEI A~BUKRS A~HKONT A~SHKZG A~KOSTL B~HWAER A~DMBTR B~BKTXT A~BLDAT A~BUDAT B~CPUDT B~CPUTM B~USNAM
FROM BSIS AS A INNER JOIN BKPF AS B ON A~BUKRS = B~BUKRS AND
									A~GJAHR = B~GJAHR AND
									A~BELNR = B~BELNR
APPENDING CORRESPONDING FIELDS OF TABLE GT_GLACC
WHERE A~HKONT IN S_SAKNR AND
				  A~BUKRS IN S_WERKS AND
				  B~CPUDT IN S_CPUDT AND
				  B~USNAM IN S_USNAM AND
				  B~BLART NE 'WA'.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2011 08:01:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-statement-too-slow/m-p/7861525#M1592999</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-11T08:01:31Z</dc:date>
    </item>
  </channel>
</rss>

