<?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: Avoid Where in loop..and select single in loop. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458690#M1415204</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;I agree with Siegfried Boes comment in the threads. And I would just like to add one more point. As I'm not aware of the number of Table entries, you can use a Field-Symbol which will be faster compared to a normal internal table. And hence your overall performance will significantly improve. &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;Thanks, &lt;/P&gt;&lt;P&gt;Samantak.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Jan 2010 15:14:59 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-01-08T15:14:59Z</dc:date>
    <item>
      <title>Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458684#M1415198</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;I want to avoid Where condition in loop  and select single in loop...statement for my code can anyone help me in this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; LOOP AT it_cdred INTO wa_cdred WHERE fname = 'SGTXT'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        wa_change_temp-mandt               = sy-mandt.&lt;/P&gt;&lt;P&gt;        wa_change_temp-changed_dt          = wa_cdred-udate.&lt;/P&gt;&lt;P&gt;SELECT SINGLE awkey FROM bkpf INTO lv_awkey WHERE bukrs = wa_change_temp-bukrs&lt;/P&gt;&lt;P&gt;                                                     AND  belnr = wa_change_temp-belnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can any one help me in this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tks,&lt;/P&gt;&lt;P&gt;Kmr&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 07:12:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458684#M1415198</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-07T07:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458685#M1415199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it is not possible to avoid a WHERE in a LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must take care that the table is sorted in the order of the used fields and that you use an READ BINARY SEARCH and an EXIT-condition, see&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Measurements on internal tables: Reads and Loops:&lt;/P&gt;&lt;P&gt;/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or use a SORTED TABLE with appropriate keys.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of the SELECT SINGLE youz should use an FOR ALL ENTIRIES outside of the LOOP and inside of the LOOP&lt;/P&gt;&lt;P&gt;an optimized READ, BINARY SEARCH or again better SORTED TABLE, the other part of the blog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 08:26:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458685#M1415199</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-07T08:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458686#M1415200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;before the loop pick the data from table bkpf using for all entries.&lt;/P&gt;&lt;P&gt;Then in loop read the internal table using binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this loop inside a loop ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 08:33:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458686#M1415200</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-01-07T08:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458687#M1415201</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;Select single can be replaced by fetch of records from database table and then read of records using binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To remove where clause from  loop, you need to consider the same condition while fetch of records in this internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 16:30:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458687#M1415201</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-07T16:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458688#M1415202</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;try this way....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    sort it_cdred  by fname.
    READ TABLE it_cdred INTO wa_cdred  WITH KEY
                   fname = 'SGTXT'    BINARY Search.
    IF sy-subrc = 0.
        W_L_TABX = SY-TABIX.
       DO.
           READ TABLE it_cdred INTO wa_cdred   INDEX W_L_TABIX.
           IF SY-SUBRC NE 0  OR wa_cdred-fname NE 'SGTXT'   . 
             EXIT.
          ENDIF.
          SELECT SINGLE awkey FROM bkpf INTO lv_awkey 
                                                WHERE bukrs = wa_change_temp-bukrs
                                                 AND  belnr = wa_change_temp-belnr.
    "Move to target table or Modify
          W_L_TABX = W_L_TABX + 1.
    ENDDO.
  ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prabhuds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 16:39:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458688#M1415202</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-07T16:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458689#M1415203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please do not recommend weird workarounds:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DO.
      READ TABLE it_cdred INTO wa_cdred   INDEX W_L_TABIX.
       IF SY-SUBRC NE 0  OR wa_cdred-fname NE 'SGTXT'   . 
             EXIT.
       ENDIF.
...
ENDDO.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is identical to well known workaround, which is descirbed in the blog&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT it_cdred INTO wa_cdred FROM  INDEX W_L_TABIX.
       IF SY-SUBRC NE 0  OR wa_cdred-fname NE 'SGTXT'   . 
             EXIT.
       ENDIF.
...
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not repeat it every time, because it is crucial, that the exit is used etc, ... which is better explained in the blog.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jan 2010 09:36:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458689#M1415203</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-08T09:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458690#M1415204</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;I agree with Siegfried Boes comment in the threads. And I would just like to add one more point. As I'm not aware of the number of Table entries, you can use a Field-Symbol which will be faster compared to a normal internal table. And hence your overall performance will significantly improve. &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;Thanks, &lt;/P&gt;&lt;P&gt;Samantak.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jan 2010 15:14:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458690#M1415204</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-08T15:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458691#M1415205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it_cdred_tmp[] = it_cdred[]&lt;/P&gt;&lt;P&gt;delete it_cdred_tmp where fname &amp;lt;&amp;gt; u2018SGTXTu2019.&lt;/P&gt;&lt;P&gt;Sort i it_cdred_tmp by bukrs belnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select awkey FROM bkpf into talble it_awkey for all entries of it_cdred_tmp&lt;/P&gt;&lt;P&gt;Where bukrs = it_cdred_tmp -bukrs&lt;/P&gt;&lt;P&gt;AND belnr = it_cdred_tmp u2013belnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After you can take a loop on it_cdred_tmp ot it_cdred according your requierement and use a read table with binary search on it_awkey&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Feb 2010 16:11:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458691#M1415205</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-18T16:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458692#M1415206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Use for all entries and then select all the entries from the table and then use loop and then use read statement inside the loop.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Use BINARY SEARCH statement with read statement(sort the internal table by with the key u are reading it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if it helps else will provide the sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vivek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2010 10:11:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458692#M1415206</guid>
      <dc:creator>VivekG</dc:creator>
      <dc:date>2010-02-21T10:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458693#M1415207</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;I am giving the sample code also below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select bukrs belnr awkey from bkpf into table li_bkpf&lt;/P&gt;&lt;P&gt;                                   for all entries in it_cdred&lt;/P&gt;&lt;P&gt;                                   where bukrs = it_cdred-bkrs &lt;/P&gt;&lt;P&gt;                                     and belnr = it_cdred-belnr&lt;/P&gt;&lt;P&gt;                                     and fname = 'SGTXT'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT it_cdred INTO wa_cdred.&lt;/P&gt;&lt;P&gt;read table li_bkpf into lw_bkpf with key bukrs = it_cdred-bkrs &lt;/P&gt;&lt;P&gt;                                      belnr = it_cdred-belnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lv_awkey = lw_bkpf-awkey.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&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;Vivek Gupta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2010 10:26:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458693#M1415207</guid>
      <dc:creator>VivekG</dc:creator>
      <dc:date>2010-02-21T10:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid Where in loop..and select single in loop.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458694#M1415208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;o.k., last comment there are 2 possiblities where a LOOP WHERE might appear:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. As explained in my above posts it is the unavoidable solution for nested loops where the inner loop must find several&lt;/P&gt;&lt;P&gt;records. Then it must be optimized with a sorted table or workaround see above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. It can happen, that there is no outer loop. Then the internal table contains to many data, maybe data which are never needed at all. Then it is much better to move the conditon into the WHERE condition of the SELECT. I do not see the FOR ALL ENTRIES, it is a fixed condition and just be added to the SELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have read several times, that people do not add NOT EQUAL conditions or conditions to non-primary key fields to the SELECT, this is incorrect. Just add it and you save a lot of time in SELECT and some time in the LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Feb 2010 09:25:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-where-in-loop-and-select-single-in-loop/m-p/6458694#M1415208</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-22T09:25:23Z</dc:date>
    </item>
  </channel>
</rss>

