<?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 nested loops in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007358#M1496134</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why avoid nested loops? You probably heard rumours that performance will suffer. Not true if the inner table is small (like probably itab2 here) or you are using sorted tables and loop at the table key.&lt;/P&gt;&lt;P&gt;See our ABAP performance sub-forum for more background.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Jun 2010 09:02:25 GMT</pubDate>
    <dc:creator>ThomasZloch</dc:creator>
    <dc:date>2010-06-18T09:02:25Z</dc:date>
    <item>
      <title>Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007354#M1496130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an internal table (itab) with a field having vale in the form as shown below;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;0001-0003;0005;0007-0009 (In one row)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This means it has values  0001 to 0003 0005 0007 to 0009&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to compare these values with some other table itab3 which has these values singly means 0001 0002 0003...etc (all in different rows ). so for that I have used nested loops because i need to expand all values to compare with itab3 table something like this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at itab
    split &amp;lt;itab-field1&amp;gt; at ';' into itab2.

  loop at itab2
     split itab2-field at '-' into var1 var2.

        while var1 le var2.
           append var1 to new table
          increment var1      
       endwhile
  endloop
endloop&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By this way I get vaues in new table as :&lt;/P&gt;&lt;P&gt;0001&lt;/P&gt;&lt;P&gt;0002&lt;/P&gt;&lt;P&gt;0003&lt;/P&gt;&lt;P&gt;0005&lt;/P&gt;&lt;P&gt;0007&lt;/P&gt;&lt;P&gt;0008&lt;/P&gt;&lt;P&gt;0009&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So plz tell me is thr some other way by which I can avoid nested loops&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 06:31:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007354#M1496130</guid>
      <dc:creator>Karan_Chopra_</dc:creator>
      <dc:date>2010-06-18T06:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007355#M1496131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Create two external loops like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  loop at itab1&lt;/P&gt;&lt;P&gt;     split itab1-field at '-' into var1 var2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;        while var1 le var2.&lt;/P&gt;&lt;P&gt;           append var1 to new table&lt;/P&gt;&lt;P&gt;          increment var1      &lt;/P&gt;&lt;P&gt;       endwhile&lt;/P&gt;&lt;P&gt;  endloop&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  loop at itab2&lt;/P&gt;&lt;P&gt;     split itab2-field at '-' into var1 var2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;        while var1 le var2.&lt;/P&gt;&lt;P&gt;read new table with table key  field1 = var1 transporting no fields&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0&lt;/P&gt;&lt;P&gt;           append var1 to new table&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;          increment var1      &lt;/P&gt;&lt;P&gt;       endwhile&lt;/P&gt;&lt;P&gt;endloop&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 08:16:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007355#M1496131</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-18T08:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007356#M1496132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;this is not serving the purpose &lt;/P&gt;&lt;P&gt;i have to use itab1 when looping thru itab 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Karan Chopra on Jun 18, 2010 1:51 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 08:19:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007356#M1496132</guid>
      <dc:creator>Karan_Chopra_</dc:creator>
      <dc:date>2010-06-18T08:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007357#M1496133</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; So plz tell me is thr some other way by which I can avoid nested loops&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 08:37:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007357#M1496133</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2010-06-18T08:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007358#M1496134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why avoid nested loops? You probably heard rumours that performance will suffer. Not true if the inner table is small (like probably itab2 here) or you are using sorted tables and loop at the table key.&lt;/P&gt;&lt;P&gt;See our ABAP performance sub-forum for more background.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:02:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007358#M1496134</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-06-18T09:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007359#M1496135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No there is huge data this just an example I gave &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it can be 0001-0100; 0150-0500 n so on (so looping hundred of times or single row )&lt;/P&gt;&lt;P&gt;Now u can imagine how big it can be&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:20:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007359#M1496135</guid>
      <dc:creator>Karan_Chopra_</dc:creator>
      <dc:date>2010-06-18T09:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007360#M1496136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Even nested loops with big tables are tolerable when hashed tables are used if possible and field symbols are used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dont understand why so many developpers are still using tables with header lines, but this i complete different story.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:26:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007360#M1496136</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2010-06-18T09:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007361#M1496137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another way is not to build a list of valid keys but to translate your values into a range table. But this is not avoiding a nested loop. If you lack performance, you should not use tables with header lines.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:28:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007361#M1496137</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2010-06-18T09:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007362#M1496138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see, well, your inner loop does not have a WHERE condition, you want to always work through the entire table itab2, so it does not even have to be sorted, even more so if itab1 has only one entry (if I understand correctly).&lt;/P&gt;&lt;P&gt;Why don't you compare runtimes if in doubt, nested loop vs. some probably tedious and error prone alternative that I don't want to suggest.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. moving this to ABAP performance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:29:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007362#M1496138</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-06-18T09:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007363#M1496139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not using with header line but with wa&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thing is our client is &amp;lt;&amp;lt; possibly confidential information removed &amp;gt;&amp;gt; and they have data in millions and performance is the main issue which they hav to deat with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;soo its prohibited frm thr side to use nested loops&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Jun 20, 2010 3:14 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:30:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007363#M1496139</guid>
      <dc:creator>Karan_Chopra_</dc:creator>
      <dc:date>2010-06-18T09:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007364#M1496140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thats a silly programming guideline.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not use into, use field symbols and assigning whereever possible. Dont build a list of all valid values, translate your specifications into a range table. Yopu can use the logical operator in to check if a value matches the range table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Translate single values into EQ, and ranges into BT&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:36:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007364#M1496140</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2010-06-18T09:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007365#M1496141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this code&lt;/P&gt;&lt;P&gt;Instead of the write statement , append the values to another itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

DATA:lv_str1 TYPE char255,
     lv_low(04) TYPE n,
     lv_high(04) TYPE n.
TYPES:BEGIN OF ty_itab,
      line TYPE char255,
      END OF ty_itab.

DATA:itab TYPE TABLE OF ty_itab,
     wa TYPE ty_itab.

wa-line = '0001-0003;0005;0007-0009'.
APPEND wa TO itab.

LOOP AT itab INTO wa.
  DO.
    IF wa-line CA ';'.
      lv_str1 = wa-line+0(sy-fdpos).
      sy-fdpos = sy-fdpos + 1.
      wa-line+0(sy-fdpos) = ' '.
      CONDENSE wa-line.
      IF lv_str1 CA '-'.
        lv_low = lv_str1+0(sy-fdpos).
        lv_high = lv_str1+sy-fdpos(*).
        WHILE NOT lv_low GT lv_high.
          WRITE lv_low.
          SKIP 1.
          ADD 1 TO lv_low.
        ENDWHILE.
      ELSE.
        WRITE lv_str1.
        SKIP 1.
      ENDIF.
    ELSE.
      IF wa-line CA '-'.
        lv_low = wa-line+0(sy-fdpos).
        lv_high = wa-line+sy-fdpos(*).
        WHILE NOT lv_low GT lv_high.
          WRITE lv_low.
          SKIP 1.
          ADD 1 TO lv_low.
        ENDWHILE.
      ELSE.
        WRITE lv_str1.
        SKIP 1.
      ENDIF.
      EXIT.
    ENDIF.
  ENDDO.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 09:50:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007365#M1496141</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-06-18T09:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007366#M1496142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DO.
...
ENDDO.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is not a loop?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 10:20:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007366#M1496142</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2010-06-18T10:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007367#M1496143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kiran,&lt;/P&gt;&lt;P&gt; the code you wrote is already optimized, there is nothing much we can improve. Declare ITAB2 as below and you can avoid one SPLIT statement inside loop   &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&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;DATA: L_WA(50) TYPE C VALUE '0001-0003;0005;0007-0009'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF ITAB2 OCCURS 0,&lt;/P&gt;&lt;P&gt;        from(4) TYPE C,&lt;/P&gt;&lt;P&gt;        DELIMITER TYPE C,&lt;/P&gt;&lt;P&gt;        TO(4) TYPE C,&lt;/P&gt;&lt;P&gt;      END OF ITAB2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SPLIT L_WA AT ';' INTO TABLE ITAB2 .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 10:54:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007367#M1496143</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-18T10:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007368#M1496144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But still it avoids 2 splits &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes Rainer, you are right but still my code improves performance.I checked it .&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

data:start type i,
     end type i,
     res type i.

data:begin of itab1 occurs 0,
     str type char255,
     end of itab1.
data:begin of itab2 occurs 0,
     str type char255,
     end of itab2.
data:var1 type char04,
     var2 type char04.

get RUN TIME FIELD start.
itab1-str = '0001-0003;0005;0007-0009'.
append itab1.
loop at itab1.
    split itab1-str at ';' into table itab2.

  loop at itab2.
     split itab2-str at '-' into var1 var2.
        while var1 le var2.
           var1 = var1 + 1.
       endwhile.
  endloop.
endloop.
get RUN TIME FIELD end.
res = end - start.
write :'code1-', res.

skip 1.

DATA:lv_str1 TYPE char255,
     lv_low(04) TYPE n,
     lv_high(04) TYPE n.
TYPES:BEGIN OF ty_itab,
      line TYPE char255,
      END OF ty_itab.

DATA:itab TYPE TABLE OF ty_itab,
     wa TYPE ty_itab.

clear:start,end,res.

get RUN TIME FIELD start.

wa-line = '0001-0003;0005;0007-0009'.
APPEND wa TO itab.

LOOP AT itab INTO wa.
  DO.
    IF wa-line CA ';'.
      lv_str1 = wa-line+0(sy-fdpos).
      sy-fdpos = sy-fdpos + 1.
      wa-line+0(sy-fdpos) = ' '.
      CONDENSE wa-line.
      IF lv_str1 CA '-'.
        lv_low = lv_str1+0(sy-fdpos).
        lv_high = lv_str1+sy-fdpos(*).
        WHILE NOT lv_low GT lv_high.
           ADD 1 TO lv_low.
        ENDWHILE.
      ELSE.
      ENDIF.
    ELSE.
      IF wa-line CA '-'.
        lv_low = wa-line+0(sy-fdpos).
        lv_high = wa-line+sy-fdpos(*).
        WHILE NOT lv_low GT lv_high.
          ADD 1 TO lv_low.
        ENDWHILE.
      ELSE.
      ENDIF.
      EXIT.
    ENDIF.
  ENDDO.
ENDLOOP.
skip 1.
get RUN TIME FIELD end.
res = end - start.
write: 'code2-',res.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Keshav.T on Jun 18, 2010 5:24 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Keshav.T on Jun 18, 2010 5:25 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 11:42:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007368#M1496144</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-06-18T11:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007369#M1496145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: result_tab1 TYPE match_result_tab.
DATA: result_tab2 TYPE match_result_tab.

FIND ALL OCCURRENCES OF REGEX '([0-9]{4})-([0-9]{4})'
     IN '0001-0003;0005;0007-0009'
     RESULTS result_tab1.

FIND ALL OCCURRENCES OF REGEX '([^-][0-9]{4}[^-])'
     IN '0001-0003;0005;0007-0009'
     RESULTS result_tab2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your Kernel supports regular expressions. For each line in result_tab1 you will have the index of each from/to in the submatches, and in each line of result_tab2 you will find the index of all solo numbers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 14:50:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007369#M1496145</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-18T14:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007370#M1496146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also use only one Regex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: result_tab TYPE match_result_tab.
DATA: input TYPE string VALUE '0001-0003;0005;0007-0009'.
DATA: var1 TYPE numc4.
DATA: var2 TYPE numc4.
DATA: results TYPE STANDARD TABLE OF numc4 WITH DEFAULT KEY.

FIELD-SYMBOLS: &amp;lt;result&amp;gt; TYPE match_result.
FIELD-SYMBOLS: &amp;lt;submatch&amp;gt; TYPE submatch_result.

FIND ALL OCCURRENCES OF REGEX '([0-9]{4})-([0-9]{4})|([^-][0-9]{4}[^-])'
     IN input
     RESULTS result_tab.

LOOP AT result_tab ASSIGNING &amp;lt;result&amp;gt;.
  CLEAR: var1, var2.

  READ TABLE &amp;lt;result&amp;gt;-submatches ASSIGNING &amp;lt;submatch&amp;gt; INDEX 1.

  IF ( &amp;lt;submatch&amp;gt;-offset &amp;gt; -1 ).
    var1 = input+&amp;lt;submatch&amp;gt;-offset(&amp;lt;submatch&amp;gt;-length).
    READ TABLE &amp;lt;result&amp;gt;-submatches ASSIGNING &amp;lt;submatch&amp;gt; INDEX 2.
    var2 = input+&amp;lt;submatch&amp;gt;-offset(&amp;lt;submatch&amp;gt;-length).

    WHILE var1 LE var2.
      APPEND var1 TO results.
      ADD 1 TO var1.
    ENDWHILE.

  ELSE.
    READ TABLE &amp;lt;result&amp;gt;-submatches ASSIGNING &amp;lt;submatch&amp;gt; INDEX 3.
    APPEND input+&amp;lt;submatch&amp;gt;-offset(&amp;lt;submatch&amp;gt;-length) TO results.
  ENDIF.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each line of the result table will contain three submatches, if the index of line 1 and to is greater than -1 it's an range, if the index of line 3 is greater than -1 it's a single value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Carsten Grafflage on Jun 18, 2010 5:20 PM (working code added)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 15:03:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007370#M1496146</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-18T15:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007371#M1496147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;I have to compare these values with some other table itab3 which has these values singly means 0001 0002 0003...etc (all in different rows ). so for that I have used nested loops because i need to expand all values to compare with itab3&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If your only requirement is to compare the two tables to determine if they are equal or not, then it depends for example how the data is stored in the internal tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;E.g. assuming that they are &lt;STRONG&gt;nicely sorted&lt;/STRONG&gt; you would get away with looping over &lt;EM&gt;itab3&lt;/EM&gt; and comparing the values against a value or interval of a current row in &lt;EM&gt;itab&lt;/EM&gt; (starting with row 1). You just need to keep track at which row in &lt;EM&gt;itab&lt;/EM&gt; and at which &lt;EM&gt;record&lt;/EM&gt; (i.e. value or interval) within that row you are. Once you matched a complete interval or value, move on to the next record in &lt;EM&gt;itab&lt;/EM&gt; or if no further one exists, simply go to the next row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way you'd get away with a single iteration over &lt;EM&gt;itab3&lt;/EM&gt; and &lt;EM&gt;itab&lt;/EM&gt;. Obviously this would be much better from a memory perspective (no possibly huge intermediate internal table) and you'd avoid some of the iterations you'd need with your approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And even if the tables are not sorted one could still think of other solutions than expanding the more compact table. In the end the real questions are what are your functional requirements, how does the data look like and what is the most efficient technical way to get a solution (and obviously efficient depends on available system resources and possibly silly requirements like nested loops, though the latter one hopefully could argue against).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, harald&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jun 2010 07:31:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007371#M1496147</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-19T07:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007372#M1496148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;]loop at itab&lt;/P&gt;&lt;P&gt;    split &amp;lt;itab-field1&amp;gt; at ';' into itab2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  loop at itab2&lt;/P&gt;&lt;P&gt;     split itab2-field at '-' into var1 var2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;        while var1 le var2.&lt;/P&gt;&lt;P&gt;           append var1 to new table&lt;/P&gt;&lt;P&gt;          increment var1      &lt;/P&gt;&lt;P&gt;       endwhile&lt;/P&gt;&lt;P&gt;  endloop&lt;/P&gt;&lt;P&gt;endloop&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your problem is not a standard LOOP in LOOP problem which can be solved with sorted, hashed or standard tables with binary search. That LOOP in LOOP comes when you have to compare the result of this processing with itab3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here you should simply think about a more clever processing of your lines, there must be solution which creates a sorted&lt;/P&gt;&lt;P&gt;table, split step by step and process the one which have '-', do appends in the right order. I think the details are your task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Jun 2010 20:10:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoid-nested-loops/m-p/7007372#M1496148</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-20T20:10:00Z</dc:date>
    </item>
  </channel>
</rss>

