<?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 performance improvement. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873517#M1960074</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If I will remove all the select queries inside of the loop, then how would I implement it then? &lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2019 08:59:57 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2019-07-03T08:59:57Z</dc:date>
    <item>
      <title>Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873505#M1960062</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;As I am new to ABAP world, I needed some suggestion regarding an performance issue.&lt;/P&gt;
  &lt;P&gt;In my program there are multiple select single query hitting database where 100k of data are stored and taking 4-5 hours to fetch the result. I referred many blogs and googled and came to know that I can take all the data from database into internal table and fetch the data. But I am confused how to achieve it. Below is the code. Can anyone please guide me how to make the performance more faster and achieve the fetching in much lesser time. Here c_t_data is being populated with 100k's of records. and then many select single statements are being fired inside it.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt; LOOP AT c_t_data.&lt;BR /&gt; CLEAR: wa_za.&lt;BR /&gt; &lt;BR /&gt; SELECT SINGLE matnr&lt;BR /&gt; INTO mara-matnr FROM mara&lt;BR /&gt; WHERE matnr = c_t_data-matnr&lt;BR /&gt; AND lvorm = space.&lt;BR /&gt; CHECK sy-subrc = 0.&lt;BR /&gt; &lt;BR /&gt; SELECT SINGLE user4 waers&lt;BR /&gt; INTO (wa_za-yyuser4, wa_za-yywaers)&lt;BR /&gt; FROM aufk&lt;BR /&gt; WHERE aufnr = c_t_data-aufnr.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT SINGLE kursk prsdt&lt;BR /&gt; INTO (wa_za-yykursk, wa_za-yyprsdt)&lt;BR /&gt; FROM vbkd&lt;BR /&gt; WHERE vbeln = c_t_data-vbeln&lt;BR /&gt; AND posnr = '000000'.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT SINGLE kursk prsdt&lt;BR /&gt; INTO (wa_za-yykursk, wa_za-yyprsdt)&lt;BR /&gt; FROM vbkd&lt;BR /&gt; WHERE vbeln = c_t_data-vbeln&lt;BR /&gt; AND posnr = c_t_data-posnr.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT SINGLE vbegdat venddat&lt;BR /&gt; INTO (wa_za-yyvbegdat, wa_za-yyvenddat)&lt;BR /&gt; FROM veda&lt;BR /&gt; WHERE vbeln = c_t_data-vbeln&lt;BR /&gt; AND vposn = '000000'.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT SINGLE vbegdat venddat&lt;BR /&gt; INTO (wa_za-yyvbegdat, wa_za-yyvenddat)&lt;BR /&gt; FROM veda&lt;BR /&gt; WHERE vbeln = c_t_data-vbeln&lt;BR /&gt; AND vposn = c_t_data-posnr.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;SELECT tj30t~txt04 INTO wa_za-yycontsts&lt;BR /&gt; FROM jest&lt;BR /&gt; JOIN jsto&lt;BR /&gt; ON jsto~objnr = jest~objnr&lt;BR /&gt; JOIN tj30t&lt;BR /&gt; ON tj30t~stsma = jsto~stsma&lt;BR /&gt; WHERE jest~objnr = c_t_data-objnr&lt;BR /&gt; AND jest~inact = space&lt;BR /&gt; AND tj30t~stsma = jsto~stsma&lt;BR /&gt; AND tj30t~estat = jest~stat&lt;BR /&gt; AND tj30t~spras = 'EN'.&lt;BR /&gt; ENDSELECT.&lt;BR /&gt; &lt;BR /&gt; CLEAR wa_za-yyconroot.&lt;BR /&gt; MOVE c_t_data-vbeln(7) TO wa_za-yyconroot.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT SINGLE knumv INTO vbak-knumv&lt;BR /&gt; FROM vbak&lt;BR /&gt; WHERE vbeln = c_t_data-vbeln.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT SINGLE kbetr INTO wa_za-yykbetr&lt;BR /&gt; FROM konv&lt;BR /&gt; WHERE knumv = vbak-knumv and&lt;BR /&gt; KPOSN = '000000' and&lt;BR /&gt; KSCHL = 'ZDIS'.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; SELECT vbeln parvw kunnr pernr parnr&lt;BR /&gt; FROM vbpa INTO TABLE itab_vbpa&lt;BR /&gt; WHERE vbeln = c_t_data-vbeln.&lt;/P&gt;
  &lt;P&gt;Thanks in advance,&lt;/P&gt;
  &lt;P&gt;Kumar.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 12:56:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873505#M1960062</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-01T12:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873506#M1960063</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Why are &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT SINGLE kursk prsdt
INTO (wa_za-yykursk, wa_za-yyprsdt)
FROM vbkd
WHERE vbeln = c_t_data-vbeln
AND posnr = '000000'.

SELECT SINGLE kursk prsdt
INTO (wa_za-yykursk, wa_za-yyprsdt)
FROM vbkd
WHERE vbeln = c_t_data-vbeln
AND posnr = c_t_data-posnr.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And &lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT SINGLE vbegdat venddat
INTO (wa_za-yyvbegdat, wa_za-yyvenddat)
FROM veda
WHERE vbeln = c_t_data-vbeln
AND vposn = '000000'.

SELECT SINGLE vbegdat venddat
INTO (wa_za-yyvbegdat, wa_za-yyvenddat)
FROM veda
WHERE vbeln = c_t_data-vbeln
AND vposn = c_t_data-posnr.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Repeated?&lt;/P&gt;&lt;P&gt;You should consolidate some separate single selects into a join. &lt;/P&gt;&lt;P&gt;Other than that you're using header lines which are obsolete, so I would suggest to find an experienced ABAP-er in your company to assist you in this task.&lt;/P&gt;&lt;P&gt;Kind regards, Rob Dielemans&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:06:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873506#M1960063</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-01T13:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873507#M1960064</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Please use the code button when posting code.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can replace:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT tj30t~txt04 INTO wa_za-yycontsts
FROM jest
JOIN jsto
ON jsto~objnr = jest~objnr
JOIN tj30t
ON tj30t~stsma = jsto~stsma
WHERE jest~objnr = c_t_data-objnr
AND jest~inact = space
AND tj30t~stsma = jsto~stsma
AND tj30t~estat = jest~stat
AND tj30t~spras = 'EN'.
ENDSELECT.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT single tj30t~txt04 INTO wa_za-yycontsts
FROM jest
JOIN jstoON jsto~objnr = jest~objnr
JOIN tj30tON tj30t~stsma = jsto~stsma
WHERE jest~objnr = c_t_data-objnr
AND jest~inact = space
AND tj30t~stsma = jsto~stsma
AND tj30t~estat = jest~stat
AND tj30t~spras = 'EN'.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It won't help performance, but it makes more sense. You can also merge the VBAK and KONV selects into one select with an inner join. Maybe some of the others. You should look at FOR ALL ENTRIES.&lt;/P&gt;&lt;P&gt;Where is c_t_data populated? &lt;/P&gt;&lt;P&gt;How much data is in the database tables being referenced? &lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:11:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873507#M1960064</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2019-07-01T13:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873508#M1960065</link>
      <description>&lt;P&gt;For the repetitious SELECTs (looking for the same record over and over again), you might consider building hashed ITABs for those tables and searching the ITABs first, then looking at database and saving the entries into the ITAB.  For your example, this should be useful for the MARA-MATNR at least..  &lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:18:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873508#M1960065</guid>
      <dc:creator>loyd_enochs3</dc:creator>
      <dc:date>2019-07-01T13:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873509#M1960066</link>
      <description>&lt;P&gt;posnr/vposn = '0000000' is fetching for all items. Where as posnr/vposn = c_t_data-posnr is fetching for req order/item.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:39:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873509#M1960066</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-01T13:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873510#M1960067</link>
      <description>&lt;P&gt;Rahul,&lt;/P&gt;&lt;P&gt;But why would you do both?  When you select for POSNR or VPOSN = zeroes, store the results in an ITAB, then look up individual items from the ITAB and not the database.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:43:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873510#M1960067</guid>
      <dc:creator>loyd_enochs3</dc:creator>
      <dc:date>2019-07-01T13:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873511#M1960068</link>
      <description>&lt;P&gt;Loyd,&lt;/P&gt;&lt;P&gt;You are correct. But I think it is being done posnr/vposn = '000000' first to get at least one data into work area (wa_za is a work area) and then posnr/vposn = c_t_data-posnr to get required data. If c_t_data-posnr is not found then at least wa_za-yykursk/yyprsdt and wa_za-yyvbegdat/yyvenddat will have a value. Please correct me if I am wrong. &lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 14:01:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873511#M1960068</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-01T14:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873512#M1960069</link>
      <description>&lt;P&gt;Rahul, &lt;/P&gt;&lt;P&gt;I guess that works, but it still seems redundant to go to the database twice.  If the result of the '000000' SELECT is stored within the program, then you will have either the specific line item or the "default" result to be used if no specific item exists.  &lt;/P&gt;&lt;P&gt;But whoever did the functional requirements either didn't grasp that or couldn't explain it properly in the specs.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 14:29:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873512#M1960069</guid>
      <dc:creator>loyd_enochs3</dc:creator>
      <dc:date>2019-07-01T14:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873513#M1960070</link>
      <description>&lt;P&gt;1. your select with item number = 00000 and specific item number from internal table doesnt make sense. put it in 1 select with or condition or just select with document number.&lt;/P&gt;&lt;P&gt;2. loop and select is really poor performance. seem like c_t_data is a standard parameter from an enhancement you may try to sort it then use FOR ALL ENTRIES. if not, try to use join.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 01:24:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873513#M1960070</guid>
      <dc:creator>DoanManhQuynh</dc:creator>
      <dc:date>2019-07-02T01:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873514#M1960071</link>
      <description>&lt;P&gt;Hi Rahul,&lt;BR /&gt;I can see that you are using multiple select queries within a loop. As per &lt;A href="https://gocoding.org/abap-programming-guidelines/" target="_blank"&gt;SAP Standard&lt;/A&gt; you must try to decrease the use of Select queries in nested methods. &lt;/P&gt;&lt;P&gt;You can improve ABAP codes by using:&lt;/P&gt;&lt;P&gt;1. &lt;A href="https://www.sapnuts.com/courses/core-abap/select-statements/select-joins.html"&gt;Select with Joins&lt;/A&gt;&lt;/P&gt;&lt;P&gt;2. &lt;A href="https://help.sap.com/viewer/f2e545608079437ab165c105649b89db/7.5.6/en-US/7c078765ec6d4e6b88b71bdaf8a2bd9f.html"&gt;Use ABAP CDS&lt;/A&gt;&lt;/P&gt;&lt;P&gt;3. Using an &lt;A href="https://gocoding.org/internal-table/"&gt;Internal Table&lt;/A&gt; wherever possible&lt;/P&gt;&lt;P&gt;All the above examples have implemented these concepts.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 06:50:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873514#M1960071</guid>
      <dc:creator>rudramani</dc:creator>
      <dc:date>2019-07-02T06:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873515#M1960072</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;1. First check if there are duplicates in the table c_t_data. if yes, do a copy and delete adj dups and use that for subsequent selects.&lt;/P&gt;&lt;P&gt;2. Remove all selects from loop.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:03:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873515#M1960072</guid>
      <dc:creator>dev_parbutteea</dc:creator>
      <dc:date>2019-07-02T13:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873516#M1960073</link>
      <description>&lt;P&gt;Hi Rahul Kumar, Try to understand how transactions &lt;STRONG&gt;ATRA&lt;/STRONG&gt;, &lt;STRONG&gt;ST12 &lt;/STRONG&gt;and &lt;STRONG&gt;ST05&lt;/STRONG&gt; work to improve that as well as internal tables like &lt;STRONG&gt;Hashed&lt;/STRONG&gt;, &lt;STRONG&gt;Sorted&lt;/STRONG&gt; and &lt;STRONG&gt;Standard&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Regards, Roberto&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 14:17:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873516#M1960073</guid>
      <dc:creator>roberto_forti</dc:creator>
      <dc:date>2019-07-02T14:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873517#M1960074</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If I will remove all the select queries inside of the loop, then how would I implement it then? &lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 08:59:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873517#M1960074</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-03T08:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873518#M1960075</link>
      <description>&lt;P&gt;&lt;A href="https://answers.sap.com/users/455769/rmahabir2.html"&gt;Rahul Kumar&lt;/A&gt; I guess &lt;A href="https://answers.sap.com/users/557341/dev.parbutteea.html"&gt;Dev Parbutteea&lt;/A&gt; proposal was to use SELECT ... FOR ALL ENTRIES IN itab_copy_no_duplicates ... before the loop.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 11:54:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873518#M1960075</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-07-03T11:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select query performance improvement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873519#M1960076</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thanks for all your valuable feedbacks. I achieved the task.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 08:55:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-performance-improvement/m-p/11873519#M1960076</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-09T08:55:02Z</dc:date>
    </item>
  </channel>
</rss>

