<?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: LOOP AT ... WHERE ... in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148412#M991953</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;Using Loop at.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;always create performance issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to improve the performance you can do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use DESCRIBE command to get the line no of the table. Say it becomes N&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Now use Do N TIMES........ ENDDO. for looping to get the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may use WHILE..........ENDWHILE with suitable condition, too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anirban&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Jul 2008 06:18:00 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-07-18T06:18:00Z</dc:date>
    <item>
      <title>LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148411#M991952</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 like using the LOOP AT ... WHERE ... statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However it is really slow, if the internal table contains many (over 10000 entries), even if it is perfectly ordered and I'm using the full key in the WHERE condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you suggest me any similar statements with a better performance on larger internal tables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Tamá&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:14:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148411#M991952</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148412#M991953</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;Using Loop at.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;always create performance issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to improve the performance you can do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use DESCRIBE command to get the line no of the table. Say it becomes N&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Now use Do N TIMES........ ENDDO. for looping to get the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may use WHILE..........ENDWHILE with suitable condition, too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anirban&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:18:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148412#M991953</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148413#M991954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if you have a loop inside a loop you can better use parralel cursor for this&lt;/P&gt;&lt;P&gt;see a thread like this&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="5754791"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;for example &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;perhaps put some more of you're code for a good answer this is to less to make a suggestion for .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;kind regards&lt;/P&gt;&lt;P&gt;arthur de smidt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: A. de Smidt on Jul 18, 2008 8:20 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:18:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148413#M991954</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148414#M991955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tamas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE &lt;/P&gt;&lt;P&gt;evaluates the specified condition internally. &lt;/P&gt;&lt;P&gt;As with any logical expressions, the performance is better if the &lt;/P&gt;&lt;P&gt;operands of a comparison share a common type. &lt;/P&gt;&lt;P&gt;The performance can be further enhanced if LOOP ... WHERE is combined &lt;/P&gt;&lt;P&gt;with FROM i1 and/or TO i2, if possible. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:20:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148414#M991955</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148415#M991956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anirban,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;earlier you wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at....
always create performance issue.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;are you become crazy on SDN?&lt;STRONG&gt;think before posting so than no need to update your own reply.&lt;/STRONG&gt;i would suggest you that please read the question first than if possible only than reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you reapeat tamas's question into  your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Amit Gujargoud on Jul 18, 2008 8:23 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:22:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148415#M991956</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148416#M991957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tamas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Using Loop at Where statement is the better option while we are dealing with large amount of data.&lt;/P&gt;&lt;P&gt;If we use only LOOP statement, then it runs for all the records of the table by checking the condition for each and every record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But whereas  LOOP AT ... WHERE directly processes the records statisfying the condition in WHERE, ignoring all other records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this following link for code optimization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sapbrainsonline.com/ARTICLES/TECHNICAL/optimization/optimization.html" target="test_blank"&gt;http://www.sapbrainsonline.com/ARTICLES/TECHNICAL/optimization/optimization.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chandra Sekhar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:23:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148416#M991957</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148417#M991958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please check the sample progam below, this is available in saptechncal.com(Author :Suresh Kumar Parvathaneni ), as I am unable to post the link, i'm copying the code. Hope this helps&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT ZINTERNAL_TABLE_OPERATIONS.* Program to find the best method in reading the internal tables
* Author: Suresh Kumar Parvathaneni* Type declaration
TYPES:
  BEGIN OF TY_MARA,
    MATNR LIKE MARA-MATNR,
    MTART LIKE MARA-MTART,
  END OF TY_MARA.* Internal table declaration
DATA:
  T_MARA TYPE STANDARD TABLE OF TY_MARA,
  T_MARA1 TYPE SORTED TABLE OF TY_MARA
          WITH NON-UNIQUE KEY MTART.* Variable declaration
DATA:
  W_COUNTER TYPE I,
  W_RUNTIME1 TYPE I,
  W_RUNTIME2 TYPE I,
  W_TABIX LIKE SY-TABIX.* Table workarea definition
DATA:
  WA_MARA TYPE TY_MARA.SELECT MATNR                           " Material Number
       MTART                           " Material Type
  FROM MARA
  INTO TABLE T_MARA.T_MARA1[] = T_MARA[].* CASE 1: Processing internal table using LOOP..WHERE ConditionGET RUN TIME FIELD W_RUNTIME1.LOOP AT T_MARA INTO WA_MARA WHERE MTART EQ 'FHMI'.
  ADD 1 TO W_COUNTER.
ENDLOOP.GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.CLEAR W_COUNTER.* CASE 2: Using a Sorted tableGET RUN TIME FIELD W_RUNTIME1.
LOOP AT T_MARA1 INTO WA_MARA WHERE MTART EQ 'FHMI'.
  ADD 1 TO W_COUNTER.
ENDLOOP.GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.CLEAR W_COUNTER.* CASE 3: Using INDEX on a sorted tableGET RUN TIME FIELD W_RUNTIME1.
READ TABLE T_MARA1 INTO WA_MARA WITH KEY MTART = 'FHMI'.
IF SY-SUBRC EQ 0.
  W_TABIX = SY-TABIX + 1.
  ADD 1 TO W_COUNTER.
  LOOP AT T_MARA1 INTO WA_MARA FROM W_TABIX.
    IF WA_MARA-MTART NE 'FHMI'.
      EXIT.
    ENDIF.
    ADD 1 TO W_COUNTER.
  ENDLOOP.
ENDIF.
GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.Following is the analysis report in microseconds, as per the data volume:   

Records: 21,390 

Iteration No 
 Using Normal LOOP &amp;amp; WHERE 
 Using Sorted table LOOP &amp;amp; WHERE 
 Using INDEX on Sorted table 
 
1 
 897 
 887 
 11 
 
2 
 839 
 879 
 10 
 
3 
 839 
 877 
 10 
 
4 
 834 
 880 
 9 
 
5 
 842 
 837 
 10 
 

Records: 132,693 

Iteration No 
 Using Normal LOOP &amp;amp; WHERE 
 Using Sorted table LOOP &amp;amp; WHERE 
 Using INDEX on Sorted table 
 
1 
 34239  
 35774  
 3567 
 
2 
 34271  
 38250  
 3592 
 
3 
 34492  
 36534  
 3554 
 
4 
 34198  
 35695  
 3584 
 

Sorted table might have given a better performance here if the field in the WHERE condition is the first field in the internal table. However, from the above statistics, we can say that method 3 is better than the other 2 methods. In production environment, the data would be huge and the performance could be much improved with this simple technique. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:27:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148417#M991958</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148418#M991959</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;go for some performance techniques.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by using  sort the internal table and by suing  read statement with  binary search. always checking sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sriram.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:29:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148418#M991959</guid>
      <dc:creator>venkatasriram_mygapula</dc:creator>
      <dc:date>2008-07-18T06:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148419#M991960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Please check this sample code:&lt;/P&gt;&lt;P&gt;My previous code was like this as given below...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: 
  i_vbak  TYPE TABLE OF vbak,
  w_vbak  LIKE LINE OF i_vbak.

SELECT * 
  FROM vbak 
  INTO TABLE i_vbak.

LOOP AT i_vbak INTO w_vbak
                 WHERE vkorg EQ 'R100'.

WRITE:/ w_vbak-vkorg.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now i have done this like below for increasing performance..&lt;/P&gt;&lt;P&gt;It will increase the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:
  i_vbak  TYPE TABLE OF vbak,
  w_vbak  LIKE LINE OF i_vbak,
  w_tabix TYPE syst-tabix.

SELECT *
  FROM vbak
  INTO TABLE i_vbak.

SORT i_vbak BY vkorg.

READ TABLE i_vbak INTO w_vbak
                  WITH KEY vkorg = 'R100'
                  BINARY SEARCH.

CHECK sy-subrc EQ 0.

LOOP AT i_vbak INTO w_vbak
              FROM sy-tabix.
  IF w_vbak-vkorg = 'R100'.
    WRITE:/
      w_vbak-vkorg.
  ELSE.
    EXIT.
  ENDIF.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Adil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:48:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148419#M991960</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148420#M991961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can avoid loop inside a loop by using &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT NEW&lt;/P&gt;&lt;P&gt;AT END&lt;/P&gt;&lt;P&gt;ON CHANGE OF &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this will be performance wise better then nested loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Bikas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 06:54:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148420#M991961</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T06:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148421#M991962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi Tamás,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what you mean by "even if it is perfectly ordered"?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The internal table has to be SORTED or HASHED typed, than is the LOOP AT ... WHERE ... faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pls. try the following test program (or create something similar):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA : gt_bkpf_st TYPE STANDARD TABLE OF bkpf,
       gt_bkpf_so TYPE SORTED   TABLE OF bkpf
                  WITH UNIQUE KEY mandt bukrs belnr gjahr,
       gt_bkpf_ha TYPE HASHED   TABLE OF bkpf
                  WITH UNIQUE KEY mandt bukrs belnr gjahr.

FIELD-SYMBOLS : &amp;lt;gw_bkpf&amp;gt; TYPE bkpf.

DATA : gw_timestamp TYPE timestampl.

SELECT * UP TO 100000 ROWS
       INTO TABLE gt_bkpf_ha
       FROM bkpf
       ORDER BY PRIMARY KEY.

gt_bkpf_st = gt_bkpf_so = gt_bkpf_ha.

SORT gt_bkpf_st BY mandt bukrs belnr gjahr.

GET TIME STAMP FIELD gw_timestamp.
WRITE : / gw_timestamp.
LOOP AT gt_bkpf_st ASSIGNING &amp;lt;gw_bkpf&amp;gt; WHERE bukrs EQ ....
  &amp;lt;gw_bkpf&amp;gt;-blart = 'SA'.
ENDLOOP.

GET TIME STAMP FIELD gw_timestamp.
WRITE : / gw_timestamp.
LOOP AT gt_bkpf_so ASSIGNING &amp;lt;gw_bkpf&amp;gt; WHERE bukrs EQ ....
  &amp;lt;gw_bkpf&amp;gt;-blart = 'SA'.
ENDLOOP.

GET TIME STAMP FIELD gw_timestamp.
WRITE : / gw_timestamp.
LOOP AT gt_bkpf_ha ASSIGNING &amp;lt;gw_bkpf&amp;gt; WHERE bukrs EQ ....
  &amp;lt;gw_bkpf&amp;gt;-blart = 'SA'.
ENDLOOP.

GET TIME STAMP FIELD gw_timestamp.
WRITE : / gw_timestamp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even the standard table is SORTed, the LOOP AT ... WHERE operation took more time, than on the sorted and the hashed table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;ec&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 07:22:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148421#M991962</guid>
      <dc:creator>JozsefSzikszai</dc:creator>
      <dc:date>2008-07-18T07:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP AT ... WHERE ...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148422#M991963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got the same results, however it is a bit harder to code, especially if there are many fields to check, but of course it seems this kind of code has the best performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE T_MARA1 INTO WA_MARA WITH KEY MTART = 'FHMI'.
IF SY-SUBRC EQ 0.
  W_TABIX = SY-TABIX + 1.
  ADD 1 TO W_COUNTER.
  LOOP AT T_MARA1 INTO WA_MARA FROM W_TABIX.
    IF WA_MARA-MTART NE 'FHMI'.
      EXIT.
    ENDIF.
    ADD 1 TO W_COUNTER.
  ENDLOOP.
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2008 07:39:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where/m-p/4148422#M991963</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-18T07:39:58Z</dc:date>
    </item>
  </channel>
</rss>

