<?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: ABAP Select statement performance (with nested NOT IN selects) in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141109#M451052</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am sending u some of the performance isuues that are to be kept in mind while coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.Donot use Select *...... instead use Select &amp;lt;required list&amp;gt;......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.Donot fetch data from CLUSTER tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3.Donot use Nested Select statements as. U have used nested select which reduces performance to a greater extent.&lt;/P&gt;&lt;P&gt;  Instead  use  views/join .&lt;/P&gt;&lt;P&gt; Also keep in mind that not use join condition for more for more than three tables unless otherwise required.&lt;/P&gt;&lt;P&gt;So split select statements into three or four and use Select ......for all entries....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 4.Extract  the data from the database  atonce consolidated upfront into table.&lt;/P&gt;&lt;P&gt;  i.e. use INTO TABLE &amp;lt;ITAB&amp;gt; clause instead of using &lt;/P&gt;&lt;P&gt;Select----&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;End Select.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5.Never use order by clause in Select ..... statement. instead use SORT&amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6.When  ever u need to calculate max,min,avg,sum,count use AGGREGATE FUNCTIONS and GROUP BY clause insted of calculating by userself..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;7.Donot use the same table once for Validation and another time for data extraction.select data  only once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;8.When the intention is for validation use Select single ....../Select.......up to one rows ......statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9.If possible always use array operations to update the database tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;10.Order of the fields in the where clause select statement  must be in the same order in the index of table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;11.Never release the object unless throughly checked by st05/se30/slin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;12.Avoid using identical select statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 21 Apr 2007 13:55:16 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-04-21T13:55:16Z</dc:date>
    <item>
      <title>ABAP Select statement performance (with nested NOT IN selects)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141104#M451047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm working on the ST module and am working with the document flow table VBFA. The query takes a large amount of time, and is timing out in production. I am hoping that someone would be able to give me a few tips to make this run faster. In our test environment, this query take 12+ minutes to process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT vbfa~vbeln&lt;/P&gt;&lt;P&gt;           vbfa~vbelv&lt;/P&gt;&lt;P&gt;           Sub~vbelv&lt;/P&gt;&lt;P&gt;           Material~matnr&lt;/P&gt;&lt;P&gt;           Material~zzactshpdt&lt;/P&gt;&lt;P&gt;           Material~werks&lt;/P&gt;&lt;P&gt;           Customer~name1&lt;/P&gt;&lt;P&gt;           Customer~sortl&lt;/P&gt;&lt;P&gt;      FROM vbfa JOIN vbrk AS Parent ON ( Parent&lt;SUB&gt;vbeln = vbfa&lt;/SUB&gt;vbeln )&lt;/P&gt;&lt;P&gt;             JOIN vbfa AS Sub ON ( Sub&lt;SUB&gt;vbeln = vbfa&lt;/SUB&gt;vbeln )&lt;/P&gt;&lt;P&gt;             JOIN vbap AS Material ON ( Material&lt;SUB&gt;vbeln = Sub&lt;/SUB&gt;vbelv )&lt;/P&gt;&lt;P&gt;             JOIN vbak AS Header ON ( Header&lt;SUB&gt;vbeln = Sub&lt;/SUB&gt;vbelv )&lt;/P&gt;&lt;P&gt;             JOIN vbpa AS Partner ON ( Partner&lt;SUB&gt;vbeln = Sub&lt;/SUB&gt;vbelv )&lt;/P&gt;&lt;P&gt;             JOIN kna1 AS Customer ON ( Customer&lt;SUB&gt;kunnr = Partner&lt;/SUB&gt;kunnr )&lt;/P&gt;&lt;P&gt;      INTO (WA_Transfers-vbeln,&lt;/P&gt;&lt;P&gt;            WA_Transfers-vbelv,&lt;/P&gt;&lt;P&gt;            WA_Transfers-order,&lt;/P&gt;&lt;P&gt;            WA_Transfers-MATNR,&lt;/P&gt;&lt;P&gt;            WA_Transfers-sdate,&lt;/P&gt;&lt;P&gt;            WA_Transfers-sfwerks,&lt;/P&gt;&lt;P&gt;            WA_Transfers-name1,&lt;/P&gt;&lt;P&gt;            WA_Transfers-stwerks)&lt;/P&gt;&lt;P&gt;      WHERE vbfa~vbtyp_n = 'M'       "Invoice&lt;/P&gt;&lt;P&gt;      AND vbfa~fktyp = 'L'           "Delivery Related Billing Doc&lt;/P&gt;&lt;P&gt;      AND vbfa~vbtyp_v = 'J'         "Delivery Doc&lt;/P&gt;&lt;P&gt;      AND vbfa~vbelv IN S_VBELV&lt;/P&gt;&lt;P&gt;      AND Sub~vbtyp_n = 'M'          "Invoice Document Type&lt;/P&gt;&lt;P&gt;      AND Sub~vbtyp_v = 'C'          "Order Document Type&lt;/P&gt;&lt;P&gt;      AND Partner~parvw = 'WE'       "Ship To Party(actual desc. is SH)&lt;/P&gt;&lt;P&gt;      AND Material~zzactshpdt IN S_SDATE&lt;/P&gt;&lt;P&gt;      AND ( Parent&lt;SUB&gt;fkart = 'ZTRA' OR Parent&lt;/SUB&gt;fkart = 'ZTER' )&lt;/P&gt;&lt;P&gt;      AND vbfa~vbelv NOT IN&lt;/P&gt;&lt;P&gt;         ( SELECT subvbfa~vbelv&lt;/P&gt;&lt;P&gt;           FROM vbfa AS subvbfa&lt;/P&gt;&lt;P&gt;           WHERE subvbfa&lt;SUB&gt;vbelv = vbfa&lt;/SUB&gt;vbelv&lt;/P&gt;&lt;P&gt;           AND   subvbfa~vbtyp_n = 'V' )           "Purchase Order&lt;/P&gt;&lt;P&gt;      AND vbfa~vbelv NOT IN&lt;/P&gt;&lt;P&gt;         ( SELECT DelList~vbeln&lt;/P&gt;&lt;P&gt;           FROM vbfa AS DelList&lt;/P&gt;&lt;P&gt;           WHERE DelList&lt;SUB&gt;vbeln = vbfa&lt;/SUB&gt;vbelv&lt;/P&gt;&lt;P&gt;           AND   DelList~vbtyp_v = 'C'             "Order Document Type&lt;/P&gt;&lt;P&gt;           AND   DelList~vbelv IN                  "Delivery Doc&lt;/P&gt;&lt;P&gt;              ( SELECT OrderList~vbelv&lt;/P&gt;&lt;P&gt;                FROM vbfa AS OrderList&lt;/P&gt;&lt;P&gt;                WHERE OrderList~vbtyp_n = 'H' )    "Return Ord&lt;/P&gt;&lt;P&gt;              ).&lt;/P&gt;&lt;P&gt;      APPEND WA_Transfers TO ITAB_Transfers.&lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Apr 2007 22:51:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141104#M451047</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-19T22:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Select statement performance (with nested NOT IN selects)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141105#M451048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Break up the query into sub queries and use internal tables for ABAP procesing by removing the Inner queries.&lt;/P&gt;&lt;P&gt;2. Most of the join conditions have been performed without the complete primary key.Infact the self join on VBFA is based on only on VBELN instead of the entire key VBELV  POSNV VBELN POSNN VBTYP_N. It really depends upon the business case to justify whether it is requried at all. More information in this regard shud help&lt;/P&gt;&lt;P&gt;3. For ideal cases donot use more than 3 table joins.&lt;/P&gt;&lt;P&gt;Although the ABAP time would increase it would lead to significant lesser time as for each Select ...end select it is now hitting the DB with addtional inner queries which we are not sure how the Query optimizer is handling.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2007 01:22:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141105#M451048</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-20T01:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Select statement performance (with nested NOT IN selects)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141106#M451049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) Break up your query into at least 2 or three separate queries.&lt;/P&gt;&lt;P&gt;2) Use "INTO TABLE" instead of into a work area and using an endselect loop to minimize SAP to DB roundtrips.&lt;/P&gt;&lt;P&gt;3)  Remove your subqueries - instead try to find an alternative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AND vbfa~vbelv NOT IN&lt;/P&gt;&lt;P&gt;( SELECT subvbfa~vbelv&lt;/P&gt;&lt;P&gt;FROM vbfa AS subvbfa&lt;/P&gt;&lt;P&gt;WHERE subvbfa&lt;SUB&gt;vbelv = vbfa&lt;/SUB&gt;vbelv&lt;/P&gt;&lt;P&gt;AND subvbfa~vbtyp_n = 'V' ) "Purchase Order&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create a range for data element VBTYP and include M and exclude V.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;r_vbtyp-sign   = 'I'.  "include&lt;/P&gt;&lt;P&gt;r_vbtyp-line-option = 'EQ'. &lt;/P&gt;&lt;P&gt;r_vbtyp-line-low    = 'M'. &lt;/P&gt;&lt;P&gt;append r_vbtyp.&lt;/P&gt;&lt;P&gt;r_vbtyp-sign   = 'E.  "exclude&lt;/P&gt;&lt;P&gt;r_vbtyp-line-option = 'EQ'. &lt;/P&gt;&lt;P&gt;r_vbtyp-line-low    = 'V'. &lt;/P&gt;&lt;P&gt;append r_vbtyp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AND Sub~vbtyp_n in r_vbtyp "Invoice Document Type&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sure that with the second one, there is a way to optimize/remove it as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2007 01:39:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141106#M451049</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-20T01:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Select statement performance (with nested NOT IN selects)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141107#M451050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Both helpful suggestions. I've attempted to break the query into its subcomponents, but there isn't much (0-10%) improvement. The problem lies in the aspect that this is a huge table, and I'm following an iterative path to find an associated document that does not exist...(in the same table) so I need to have a NOT IN select (or code of the equivalent). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm coming to the realization that I'm going to have to run this as a batch or in the background. Although I'm going to leave this open for a few more days to see if someone has any other suggestions? &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2007 21:41:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141107#M451050</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-20T21:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Select statement performance (with nested NOT IN selects)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141108#M451051</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 are correct. the NOT IN clause will negelect the index search and will lead to full table scan. it is suggested to have EQ condition in the WHERE clause, if possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My observations:&lt;/P&gt;&lt;P&gt;1. Avoid SELECT-ENDSELECT. &lt;/P&gt;&lt;P&gt;2. Avoid NOT IN condition in your where clause.&lt;/P&gt;&lt;P&gt;3. Avoid complex joins.&lt;/P&gt;&lt;P&gt;4. Avoid sub queries.&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>Sat, 21 Apr 2007 09:31:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141108#M451051</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-21T09:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Select statement performance (with nested NOT IN selects)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141109#M451052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am sending u some of the performance isuues that are to be kept in mind while coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.Donot use Select *...... instead use Select &amp;lt;required list&amp;gt;......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.Donot fetch data from CLUSTER tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3.Donot use Nested Select statements as. U have used nested select which reduces performance to a greater extent.&lt;/P&gt;&lt;P&gt;  Instead  use  views/join .&lt;/P&gt;&lt;P&gt; Also keep in mind that not use join condition for more for more than three tables unless otherwise required.&lt;/P&gt;&lt;P&gt;So split select statements into three or four and use Select ......for all entries....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 4.Extract  the data from the database  atonce consolidated upfront into table.&lt;/P&gt;&lt;P&gt;  i.e. use INTO TABLE &amp;lt;ITAB&amp;gt; clause instead of using &lt;/P&gt;&lt;P&gt;Select----&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;End Select.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5.Never use order by clause in Select ..... statement. instead use SORT&amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6.When  ever u need to calculate max,min,avg,sum,count use AGGREGATE FUNCTIONS and GROUP BY clause insted of calculating by userself..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;7.Donot use the same table once for Validation and another time for data extraction.select data  only once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;8.When the intention is for validation use Select single ....../Select.......up to one rows ......statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9.If possible always use array operations to update the database tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;10.Order of the fields in the where clause select statement  must be in the same order in the index of table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;11.Never release the object unless throughly checked by st05/se30/slin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;12.Avoid using identical select statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Apr 2007 13:55:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-select-statement-performance-with-nested-not-in-selects/m-p/2141109#M451052</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-21T13:55:16Z</dc:date>
    </item>
  </channel>
</rss>

