<?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 Better Way To Write Select Code in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350763#M1398840</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI, Just wondering if someone can help. I'm trying to get all sales orders that have the kit header on them that is on a production order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a list of all my production orders, then i'm using&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT aa~matnr aa~kwmeng bb~auart aa~netwr
         aa~abgru bb~erdat
    FROM vbap AS aa INNER JOIN vbak AS bb ON aa~vbeln  = bb~vbeln

    INTO wa_sales_orders
    FOR ALL ENTRIES IN it_prod_orders2
    WHERE aa~matnr = it_prod_orders2-plnbez AND
          bb~auart EQ 'ZOR'                 AND
          aa~abgru EQ ' '.

    APPEND wa_sales_orders TO it_sales_orders.

  ENDSELECT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to get all the sales orders. But this is taking ages, could anyone suggest a better way to write this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Nov 2009 08:51:15 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-11-23T08:51:15Z</dc:date>
    <item>
      <title>Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350763#M1398840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI, Just wondering if someone can help. I'm trying to get all sales orders that have the kit header on them that is on a production order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a list of all my production orders, then i'm using&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT aa~matnr aa~kwmeng bb~auart aa~netwr
         aa~abgru bb~erdat
    FROM vbap AS aa INNER JOIN vbak AS bb ON aa~vbeln  = bb~vbeln

    INTO wa_sales_orders
    FOR ALL ENTRIES IN it_prod_orders2
    WHERE aa~matnr = it_prod_orders2-plnbez AND
          bb~auart EQ 'ZOR'                 AND
          aa~abgru EQ ' '.

    APPEND wa_sales_orders TO it_sales_orders.

  ENDSELECT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to get all the sales orders. But this is taking ages, could anyone suggest a better way to write this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 08:51:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350763#M1398840</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T08:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350764#M1398841</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;You could try this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

if not it_prod_orders2[] is initial.

SELECT aa~matnr aa~kwmeng bb~auart aa~netwr
         aa~abgru bb~erdat
    FROM vbap AS aa INNER JOIN vbak AS bb ON aa~vbeln  = bb~vbeln
 
    INTO table  it_sales_orders
    FOR ALL ENTRIES IN it_prod_orders2
    WHERE aa~matnr = it_prod_orders2-plnbez AND
          bb~auart EQ 'ZOR'                 AND
          aa~abgru EQ ' '.

endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also check if you have used as many primary key fields possible in the where condition&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 08:54:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350764#M1398841</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T08:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350765#M1398842</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;&lt;/P&gt;&lt;P&gt;it_data[]  =  it_prod_orders2[]. (move the data from it_prod_orders2 to it_data.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT it_data BY plnbez.&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM it_data COMPARING plnbez.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT it_data[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT aa~erdat&lt;/P&gt;&lt;P&gt;         aa~auart&lt;/P&gt;&lt;P&gt;         bb~matnr&lt;/P&gt;&lt;P&gt;         bb~abgru&lt;/P&gt;&lt;P&gt;         bb~netwr&lt;/P&gt;&lt;P&gt;         bb~kwmeng&lt;/P&gt;&lt;P&gt;         FROM vbak AS aa INNER JOIN vbap AS bb ON aa&lt;SUB&gt;vbeln  = bb&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;         INTO TABLE it_sales_orders&lt;/P&gt;&lt;P&gt;         FOR ALL ENTRIES IN it_prod_orders2&lt;/P&gt;&lt;P&gt;         WHERE aa~auart EQ 'ZOR'&lt;/P&gt;&lt;P&gt;           AND bb~matnr = it_data-plnbez&lt;/P&gt;&lt;P&gt;           AND bb~abgru EQ ' '.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;instead of select endselect, you can use INTO TABLE IT_SALES_ORDERS for better performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope the above modified query will solve your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Phani.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 08:55:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350765#M1398842</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T08:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350766#M1398843</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;Avoid using select.....endselect loop. If the output from the where condition contins hundred thousand records than this select will run that many times. This would increase the overhead on the database and hence slow the query down. As mentioned in the previous post by Vikranth, insert all the records at a single shot into an internal table rather than placing it into a workarea and appending it into an internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sachin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 08:58:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350766#M1398843</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T08:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350767#M1398844</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;As sachin said avoid using SELECT...ENDSELECT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use syntax into table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Make sure that the access is based on Primary Key / Secondary  Indexes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 09:12:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350767#M1398844</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T09:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350768#M1398845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Replace SELECT/ENDSELECT with SELECT in table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check for initial before using for all entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also , try to use selection sceen values in where condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it help you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 10:03:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350768#M1398845</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T10:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350769#M1398846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for all suggestion.&lt;/P&gt;&lt;P&gt;I've tried using the code in the first reply, but it is still running extremly slow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any other suggestion would be welcome.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 15:46:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350769#M1398846</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T15:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350770#M1398847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You would probably have gotten better ideas if you had posted in the correct forum: &lt;SPAN __jive_macro_name="forum" id="234"&gt;&lt;/SPAN&gt;. But before doing that, you would have to do some analysis on your part. Running transaction ST05 for starters, would show you what (if any) index was being used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, your select runs slowly because you are not using an index. You will be able to speed it up considerably if you JOIN table VAPMA into the SELECT. This is a secondary index table on material.&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, 23 Nov 2009 16:19:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350770#M1398847</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T16:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350771#M1398848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to performance tune the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Match the order of fields same as in database tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Do runtime analysis and trace analysis using SE30 and ST05.Check which index is used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Try to increase fields in where condition, use selection screen fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it help you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Nov 2009 16:20:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350771#M1398848</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T16:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350772#M1398849</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; 1. Match the order of fields same as in database tables.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Harsh Bhalla - this will not help in performance - please search the forum. There are many discussions on this.&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, 23 Nov 2009 16:25:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350772#M1398849</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-23T16:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350773#M1398850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry for my ignorance, I'm new to this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I join table VAPMA, do I select any fields from this or just put it in the join statement. Also do I join it on VBELN &amp;amp; POSNR?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2009 08:49:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350773#M1398850</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-24T08:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Better Way To Write Select Code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350774#M1398851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi  MLockett,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just have a look on below blog especially conmments for your purpose...&lt;/P&gt;&lt;P&gt;it's interesting one..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[Blog|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417500)ID1011873750DB00632167431349190219End?blog=/pub/wlg/8058]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;VAPMA&lt;/STRONG&gt; is having these many fields as primary keys... of course you can join using VBELN POSNR... Better you select data from this table first and then proceed further data selection... There are other fields as well which you can put in where clause if it suits your requirement...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MATNR&lt;/P&gt;&lt;P&gt;VKORG&lt;/P&gt;&lt;P&gt;TRVOG&lt;/P&gt;&lt;P&gt;AUDAT&lt;/P&gt;&lt;P&gt;VTWEG&lt;/P&gt;&lt;P&gt;SPART&lt;/P&gt;&lt;P&gt;AUART&lt;/P&gt;&lt;P&gt;KUNNR&lt;/P&gt;&lt;P&gt;VKBUR&lt;/P&gt;&lt;P&gt;VKGRP&lt;/P&gt;&lt;P&gt;BSTNK&lt;/P&gt;&lt;P&gt;ERNAM&lt;/P&gt;&lt;P&gt;VBELN&lt;/P&gt;&lt;P&gt;POSNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also have a look on &lt;STRONG&gt;VBAP_VAPMA&lt;/STRONG&gt; View which joins VBAP and VAPMA and have a look on &lt;STRONG&gt;VAKPA&lt;/STRONG&gt;  Table as well&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Hope it will solve your problem..&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards&lt;/P&gt;&lt;P&gt;ilesh 24x7&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ilesh Nandaniya&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2009 09:28:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-way-to-write-select-code/m-p/6350774#M1398851</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-24T09:28:51Z</dc:date>
    </item>
  </channel>
</rss>

