<?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 regarding internal table loops in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898015#M375262</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have a situation, i need to filter records by adding on the where conditon  in a internal table itab1 as i go down the program .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is a sample,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table itab1 with  key  col1 = '123'&lt;/P&gt;&lt;P&gt;                                      col2 = 'abc'.&lt;/P&gt;&lt;P&gt;  while sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    append itab1 to itab2.&lt;/P&gt;&lt;P&gt;    sort itab2 by col1 col2 col3.&lt;/P&gt;&lt;P&gt;    read table itab1 with  key  col1 = '123'&lt;/P&gt;&lt;P&gt;                                      col2 = 'abc'.&lt;/P&gt;&lt;P&gt;  endwhile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the next step i want to use the same logic but one more variable in where conditon.. &amp;lt;b&amp;gt;col3 = 'xyz'&amp;lt;/b&amp;gt;, but here, i am going in to infinite while loop selecting same  record ...how do i overcome that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when i come to next step i want to select form itab2 and now what is situation of itab1 outside the loop? is it empty , can i use it to select from itab2 or should i declare itab3 ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;plz help me...i am not a abap guy..so kindaa stuck at this simple situation....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        ravi a&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Jan 2007 19:40:18 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-01-26T19:40:18Z</dc:date>
    <item>
      <title>regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898015#M375262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have a situation, i need to filter records by adding on the where conditon  in a internal table itab1 as i go down the program .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is a sample,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table itab1 with  key  col1 = '123'&lt;/P&gt;&lt;P&gt;                                      col2 = 'abc'.&lt;/P&gt;&lt;P&gt;  while sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    append itab1 to itab2.&lt;/P&gt;&lt;P&gt;    sort itab2 by col1 col2 col3.&lt;/P&gt;&lt;P&gt;    read table itab1 with  key  col1 = '123'&lt;/P&gt;&lt;P&gt;                                      col2 = 'abc'.&lt;/P&gt;&lt;P&gt;  endwhile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the next step i want to use the same logic but one more variable in where conditon.. &amp;lt;b&amp;gt;col3 = 'xyz'&amp;lt;/b&amp;gt;, but here, i am going in to infinite while loop selecting same  record ...how do i overcome that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when i come to next step i want to select form itab2 and now what is situation of itab1 outside the loop? is it empty , can i use it to select from itab2 or should i declare itab3 ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;plz help me...i am not a abap guy..so kindaa stuck at this simple situation....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        ravi a&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2007 19:40:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898015#M375262</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-26T19:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898016#M375263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Below code moves data from itab to itab2 provided both have the same structure with same field names.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;loop at itab where col1 = '123' and col2 = 'abc'. &lt;/P&gt;&lt;P&gt;  move corresponding fields of itab1 to itab2.&lt;/P&gt;&lt;P&gt;  append itab2.&lt;/P&gt;&lt;P&gt;  clear itab2.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this what you are looking for?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Santosh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2007 19:48:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898016#M375263</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-26T19:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898017#M375264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ravi,&lt;/P&gt;&lt;P&gt;Could you please give some details of the situation you are handelling?&lt;/P&gt;&lt;P&gt;You can give contents of table or there might be other good ways to handle this.&lt;/P&gt;&lt;P&gt;From your explaination its purpose is not much clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;ags..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2007 19:50:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898017#M375264</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-26T19:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898018#M375265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you trying to do something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

DATA new_index LIKE sy-tabix.

READ TABLE itab1 WITH KEY col1 = '123'.
col2 = 'abc'.
new_index = sy-tabix.
WHILE sy-subrc = 0.
  APPEND itab1 TO itab2.
  new_index = new_index + 1.
  READ TABLE itab1 INDEX new_index.
  col2 = 'abc'.
ENDWHILE.
SORT itab2 BY col1 col2 col3.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2007 19:58:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898018#M375265</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-26T19:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898019#M375266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An alternative solution may be as given below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given itab1 is already declared. Also the selection from itab1 based on col1 and col2 is using fixed values like.'123' etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Data: itab2 like itab1,
         itab3 like itab1.

* copy itab1 into the other table
  itab2 = itab1.

* delete the irrelevant rows from itab2 based on the where clause
  delete itab2 where col1 ne '123' and col2 ne 'ABC'.

* copy itab2 into the other table
  itab3 = itab2.

* delete the irrelevant rows from itab3 based on the where clause
  delete itab3 where col1 ne '123' and col2 ne 'ABC' and col3 ne 'XYZ'.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After this, itab2 will have records that match with value in col1 and col2 as '123' and 'ABC' respectively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab3 will have records that match with value in col1, col2 and col3 as '123', 'ABC' and 'XYZ' respectively. Also it will have only those records which were also selected in itab2 as it was a copy of itab2.&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;Sanjeev&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2007 20:49:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898019#M375266</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-26T20:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898020#M375267</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;Its better to have one more internal table with the final result you want:&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  loop at itab1 where col1 = '123' and col2 = 'abc'.&lt;/P&gt;&lt;P&gt;   &lt;/P&gt;&lt;P&gt;   loop at itab2 where col1 = itab1-col1&lt;/P&gt;&lt;P&gt;                        and  col2 = itab1-col2&lt;/P&gt;&lt;P&gt;                        and col3 = 'xyz'.&lt;/P&gt;&lt;P&gt;     move-corresponding itab1 to itab3.&lt;/P&gt;&lt;P&gt;     move-corresponding itab2 to itab3.&lt;/P&gt;&lt;P&gt;     append itab3.&lt;/P&gt;&lt;P&gt;   endloop.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Subramanian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jan 2007 21:17:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898020#M375267</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-26T21:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898021#M375268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot guys for all the helpful and fast answers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jan 2007 03:30:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898021#M375268</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-29T03:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: regarding internal table loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898022#M375269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;     the obvious answer is it goes into infinite loop.  why? the logic u wrote for the read table id always true. and the read table written inside the while condition will not effect the SY-SUBRC for the while condition. what is the logic  u actually want to write. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Aravind&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jan 2007 04:12:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-internal-table-loops/m-p/1898022#M375269</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-29T04:12:07Z</dc:date>
    </item>
  </channel>
</rss>

