<?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 in Loop performance tuning in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296576#M1989894</link>
    <description>&lt;P&gt;Please, never use SELECT inside the loops.&lt;/P&gt;&lt;P&gt;Use SELECT ... INTO TABLE itab ... before the loops.&lt;/P&gt;&lt;P&gt;Use the transaction code SAT to troubleshoot performance issues.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Aug 2020 04:37:43 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2020-08-17T04:37:43Z</dc:date>
    <item>
      <title>Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296573#M1989891</link>
      <description>&lt;P&gt;Dear friends. &lt;/P&gt;
  &lt;P&gt;Can you please advise on the below code. &lt;/P&gt;
  &lt;P&gt;I know that using a select statement within a loop gives bad performance but I am not good in abap. Can you please help me to fine tune the below code for optimum performance.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;LOOP AT ITB_EINA.
    ON CHANGE OF ITB_EINA-MATNR.
      CLEAR WK_MTART.
      SELECT SINGLE * FROM MARA
        WHERE MATNR = ITB_EINA-MATNR.
      IF SY-SUBRC = 0.
        WK_MTART = MARA-MTART.
      ENDIF.
    ENDON.
    IF WK_MTART = 'ROH'.
      MOVE-CORRESPONDING ITB_EINA TO ITB_EINA2.
      APPEND ITB_EINA2.
    ENDIF.
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2020 01:27:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296573#M1989891</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-08-17T01:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296574#M1989892</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;types : begin of lty_matnr,
	  matnr type matnr,
	end of lty_matnr.

data : lt_matnr type table of lty_matnr.

LOOP AT ITB_EINA.
    ON CHANGE OF ITB_EINA-MATNR.
  append itab_eina-matnr to lt_matnr.	
ENDLOOP.

*make sure lt_matnr has no duplicates and not empty for better performance

sort lt_matnr by matnr.
delete adjacent duplicates from lt_matnr.

if  lt_matnr is not initial.
  select matnr MTART
  from MARA
  into lt_matnr2
  for all entries in lt_matnr 
  where matnr = lt_matnr-matnr.
    if sy-subrc eq 0.
     LOOP AT ITB_EINA.
	&amp;lt;your logic goes here&amp;gt;
     endloop.
    endif.
endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prasanna CD.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 02:50:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296574#M1989892</guid>
      <dc:creator>cdprasanna</dc:creator>
      <dc:date>2020-08-17T02:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296575#M1989893</link>
      <description>&lt;P&gt;Not related to your question but you are cumulating many obsolete and prone-to-errors ABAP constructs (header lines and ON CHANGE OF cannot be used in ABAP Objects, since around 2000):&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Header line (ITB_EINA, ITB_EINA2)&lt;/LI&gt;&lt;LI&gt;Use of implicit work area/no explicit target for SELECT (MARA structure)&lt;/LI&gt;&lt;LI&gt;ON CHANGE OF&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Don't use them! Instead, use for instance:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;LOOP AT itb_eina REFERENCE INTO DATA(eina). (&amp;gt;= 7.40)&lt;/LI&gt;&lt;LI&gt;SELECT SINGLE ... INTO  @DATA(mara) (&amp;gt;= 7.40)&lt;/LI&gt;&lt;LI&gt;IF eina-&amp;gt;matnr &amp;lt;&amp;gt; previous_eina-&amp;gt;matnr&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 17 Aug 2020 04:34:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296575#M1989893</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-08-17T04:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296576#M1989894</link>
      <description>&lt;P&gt;Please, never use SELECT inside the loops.&lt;/P&gt;&lt;P&gt;Use SELECT ... INTO TABLE itab ... before the loops.&lt;/P&gt;&lt;P&gt;Use the transaction code SAT to troubleshoot performance issues.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 04:37:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296576#M1989894</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-08-17T04:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296577#M1989895</link>
      <description>&lt;P&gt;Or rather than&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IF eina-&amp;gt;matnr &amp;lt;&amp;gt; previous_eina-&amp;gt;matnr&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Use GROUP BY if you want to be really modern.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 10:25:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296577#M1989895</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2020-08-17T10:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296578#M1989896</link>
      <description>&lt;P&gt;No check whether it_mara is empty before the SELECT. Still using obsolete forms:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Table ITB_EINA with header line&lt;/LI&gt;&lt;LI&gt;ON CHANGE&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 17 Aug 2020 10:27:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296578#M1989896</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2020-08-17T10:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Select in Loop performance tuning</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296579#M1989897</link>
      <description>&lt;P&gt;Don't use tables with headers. Don't use ON CHANGE. Both are obsolete.&lt;/P&gt;&lt;P&gt;If you define&lt;STRONG&gt; lt_matnr&lt;/STRONG&gt; as &lt;STRONG&gt;SORTED TABLE OF lty_matnr WITH UNIQUE KEY matnr.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Then you don't need:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;sort lt_matnr by matnr.
delete adjacent duplicates from lt_matnr.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2020 13:14:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-in-loop-performance-tuning/m-p/12296579#M1989897</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2020-08-17T13:14:16Z</dc:date>
    </item>
  </channel>
</rss>

