<?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 query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490795#M839434</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 main performance issue is that u have looped the database table.... transfer the data that u want into the internal table and then use loop the internal table with another internal table.&lt;/P&gt;&lt;P&gt;Eg.&lt;/P&gt;&lt;P&gt;select * from vbak into itab1.&lt;/P&gt;&lt;P&gt;select * from vbap into itab2.&lt;/P&gt;&lt;P&gt;Loop at itab1.&lt;/P&gt;&lt;P&gt;read table itab2 with key f1 = itab1-f1.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Reward if Useful.&lt;/P&gt;&lt;P&gt;Arunprasad.P&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Mar 2008 05:52:14 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-10T05:52:14Z</dc:date>
    <item>
      <title>select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490792#M839431</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 wrote logic like this.But it getting performance problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody tell me how to avoid this.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT *   INTO  TABLE wknvv                   &lt;/P&gt;&lt;P&gt;    FROM knvv&lt;/P&gt;&lt;P&gt;    WHERE vkorg     IN sales_or&lt;/P&gt;&lt;P&gt;          AND vtweg IN dist_cha&lt;/P&gt;&lt;P&gt;          AND spart IN div&lt;/P&gt;&lt;P&gt;          AND vkbur IN sales_of .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT wknvv .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT vbeln auart zzmax_cpi INTO (wlist-vbeln,wlist-auart,max)&lt;/P&gt;&lt;P&gt;         FROM vbak&lt;/P&gt;&lt;P&gt;         WHERE&lt;/P&gt;&lt;P&gt;             vbtyp = 'G'&lt;/P&gt;&lt;P&gt;             AND kunnr = wknvv-kunnr&lt;/P&gt;&lt;P&gt;             AND auart IN contr_ty.&lt;/P&gt;&lt;P&gt;      max1 = max.&lt;/P&gt;&lt;P&gt;      IF sy-subrc = 0 AND max1 IS NOT INITIAL .&lt;/P&gt;&lt;P&gt;        SELECT * INTO wvbap FROM vbap&lt;/P&gt;&lt;P&gt;              WHERE vbeln = wlist-vbeln&lt;/P&gt;&lt;P&gt;               AND abgru = ''.&lt;/P&gt;&lt;P&gt;          IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;            SELECT SINGLE * FROM veda INTO wveda&lt;/P&gt;&lt;P&gt;              WHERE vbeln = wlist-vbeln&lt;/P&gt;&lt;P&gt;                AND vposn = wvbap-posnr&lt;/P&gt;&lt;P&gt;                AND vkuegru = ''&lt;/P&gt;&lt;P&gt;                AND venddat IN dates .&lt;/P&gt;&lt;P&gt;            IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;              MOVE-CORRESPONDING wvbap TO wlist .&lt;/P&gt;&lt;P&gt;              MOVE-CORRESPONDING wveda TO wlist .&lt;/P&gt;&lt;P&gt;              MOVE-CORRESPONDING wknvv TO wlist .&lt;/P&gt;&lt;P&gt;              APPEND wlist.&lt;/P&gt;&lt;P&gt;            ENDIF .&lt;/P&gt;&lt;P&gt;          ENDIF.&lt;/P&gt;&lt;P&gt;        ENDSELECT.&lt;/P&gt;&lt;P&gt;        CLEAR wlist.&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;    ENDSELECT .&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;rakesh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Mar 2008 20:22:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490792#M839431</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-08T20:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490793#M839432</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;Instead of using SELECT SINGLE and SELECT .. ENDSELECT for each record from table wknvv use SELECT FOR ALL ENTRIES. For example, this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT vbeln auart zzmax_cpi INTO (wlist-vbeln,wlist-auart,max)
FROM vbak
WHERE
vbtyp = 'G'
AND kunnr = wknvv-kunnr
AND auart IN contr_ty.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;replace with this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
" this code should be after the first select
" but outside the loop
IF wknvv[] IS NOT INITIAL.
  SELECT vbeln auart zzmax_cpi 
    INTO TABLE lit_wlist "table lit_wlist defined earlier somewhere in the code
    FROM vbak
    FOR ALL ENTRIES IN wknvv
    WHERE vbtyp = 'G'
      AND kunnr = wknvv-kunnr
      AND auart IN contr_ty.
ENDIF.

" then in the loop use READ TABLE
READ TABLE lit_wlist 
  INTO lwa_wlist
  WITH KEY kunnr = wknvv-kunnr.

" or LOOP
LOOP AT lit_wlist 
  INTO lwa_wlist
  WHERE kunnr = wknvv-kunnr.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way you will read each record from the memory, not from the harddisk. Also apply this to other SELECTs.&lt;/P&gt;&lt;P&gt;You can define internal tables with keys so that reading and looping would be even faster.&lt;/P&gt;&lt;P&gt;Also, check if there is any index on VBAK that you could use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helped you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;Mat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Mar 2008 23:45:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490793#M839432</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-09T23:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490794#M839433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rakesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main thing which would have affected the performance of your coding is-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use of all fields in select statements instead of using specific fields.You should specify all the fields which have to retrieved from the table KNVV if you know them.For example you may use the codes as follows.This is only the example-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT  kunnr vkorg INTO TABLE wknvv &lt;/P&gt;&lt;P&gt;FROM knvv&lt;/P&gt;&lt;P&gt;WHERE vkorg IN sales_or&lt;/P&gt;&lt;P&gt;AND vtweg IN dist_cha&lt;/P&gt;&lt;P&gt;AND spart IN div&lt;/P&gt;&lt;P&gt;AND vkbur IN sales_of .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The generalised way is as follows-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*SELECT field1 field2 field3 .... INTO TABLE itab FROM dbtab &lt;/P&gt;&lt;P&gt;WHERE condition.*  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. The second thing which is affecting the performance most is the use of select statements within the LOOP.Thst reduces the performance very much.Because for each loop the data is fetched from the database table and it takes time.&lt;/P&gt;&lt;P&gt;So better to use select quieries with the addition FOR ALL ENTIRIES.For example-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*SELECT field1 field2 field3 .... INTO TABLE itab1 &lt;/P&gt;&lt;P&gt;                                             FROM dbtab1 &lt;/P&gt;&lt;P&gt;                                             WHERE condition.* &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*SELECT field11 field 12 field13.....INTO TABLE itab2 &lt;/P&gt;&lt;P&gt;                                    FROM dbtab2 &lt;/P&gt;&lt;P&gt;                                    FOR ALL ENTRIES IN itab1&lt;/P&gt;&lt;P&gt;                                    WHERE field of dbtab = itab1-field1.* &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The use of above codes will definately improve the performance and always try to avoid the SELECT quieries within the LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ok Take Care and  I expect solution given by me may remove your performance problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BYE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2008 05:37:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490794#M839433</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-10T05:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490795#M839434</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 main performance issue is that u have looped the database table.... transfer the data that u want into the internal table and then use loop the internal table with another internal table.&lt;/P&gt;&lt;P&gt;Eg.&lt;/P&gt;&lt;P&gt;select * from vbak into itab1.&lt;/P&gt;&lt;P&gt;select * from vbap into itab2.&lt;/P&gt;&lt;P&gt;Loop at itab1.&lt;/P&gt;&lt;P&gt;read table itab2 with key f1 = itab1-f1.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Reward if Useful.&lt;/P&gt;&lt;P&gt;Arunprasad.P&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2008 05:52:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490795#M839434</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-10T05:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490796#M839435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The other answers are generally helpful, but don't solve your main problem. You are doing two SELECTS without using an index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first against KNVV uses all primary key fileds except KUNNR which is the first key field, so the index won't be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second against VBAK doesn't try to use an index and is within a loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, run it in th ebackground.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2008 14:04:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/3490796#M839435</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-10T14:04:00Z</dc:date>
    </item>
  </channel>
</rss>

