<?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 question in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672030#M1289782</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;Take one more internal table itab2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;move the contents of itab1 to itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab2[] = itab1[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now go for LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data v_count type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;clear v_count.&lt;/P&gt;&lt;P&gt; loop at itab2 where a = itab1-a  and b = itab1-b and c = itab1-c and d = itab1-d.&lt;/P&gt;&lt;P&gt;  v_count = v_count + 1.&lt;/P&gt;&lt;P&gt;  itab2-d = v_count.  &lt;/P&gt;&lt;P&gt;  modify itab2.&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;Finally itab2 contains unique records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kumar Bandanadham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 May 2009 12:11:41 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-05-26T12:11:41Z</dc:date>
    <item>
      <title>Loop question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672027#M1289779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;I have a requirement to make records unique before updating a table. the scenario is as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table - fields A to G ( A, B, C and D are primary )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data provider changed so they cannot provide an entry for field D, meaning a combination of A B and C may not be unique. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg :  A         B      C      D&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------" /&gt;&lt;P&gt;        X01    032   202  &lt;/P&gt;&lt;P&gt;        X02    032   002  &lt;/P&gt;&lt;P&gt;        X02    032   002  &lt;/P&gt;&lt;P&gt;        X04    032   662  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Records 2 and 3 are not unique, I need to make it unique by incrementing the value of D by 1 for each record before updating the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how do I loop within a combination of records in this case to update the field D ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2009 11:48:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672027#M1289779</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-26T11:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Loop question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672028#M1289780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; 1 way is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab by a b c d&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab into wa.&lt;/P&gt;&lt;P&gt;  loop at itab where itab-a eq wa-a and itab-b eq wa-b and itab-c eq wa-c and itab-d eq wa-d.&lt;/P&gt;&lt;P&gt;     add 1 to d.&lt;/P&gt;&lt;P&gt;     modify itab.&lt;/P&gt;&lt;P&gt;     exit.&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;Regards&lt;/P&gt;&lt;P&gt;Nicole&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2009 11:58:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672028#M1289780</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-26T11:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672029#M1289781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can keep value of D as 1 for every entry. Also you need to check that a particular combination is exsisting already in the table. if yes then increment value of D.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;eg: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

sort itab by a b c.
loop at t_itab into f_itab.
at new a.
   f_itab-d = 1.
end at.
read table t_itab into f_itab1      "&amp;lt;-- different work area.
    with key a = f_itab-a  b = f_itab-b  c = f_itab-c binary search.
if sy-subrc is initial.
  add 1 to f_itab-d.
endif.
append f_itab to t_itab1.
clear f_itab.
delete t_itab index sy-tabix.

endloop.
" Now required unique entries are available in table t_itab1
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&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;Regrads,&lt;/P&gt;&lt;P&gt;Sachinkumar Mehta.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2009 12:02:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672029#M1289781</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-26T12:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Loop question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672030#M1289782</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;Take one more internal table itab2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;move the contents of itab1 to itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab2[] = itab1[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now go for LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data v_count type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;clear v_count.&lt;/P&gt;&lt;P&gt; loop at itab2 where a = itab1-a  and b = itab1-b and c = itab1-c and d = itab1-d.&lt;/P&gt;&lt;P&gt;  v_count = v_count + 1.&lt;/P&gt;&lt;P&gt;  itab2-d = v_count.  &lt;/P&gt;&lt;P&gt;  modify itab2.&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;Finally itab2 contains unique records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kumar Bandanadham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2009 12:11:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672030#M1289782</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-26T12:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Loop question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672031#M1289783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Suker,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check the test program to apply the logic before updating the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:
       l_itab TYPE TABLE OF ztest_str11,
       l_str  TYPE ztest_str11, " Structure with field1, field2...
       l_str_temp TYPE ztest_str11,
       l_count  TYPE i VALUE 1.

CLEAR l_str.
l_str-field1  = 12.
l_str-field2  = 11.
l_str-field3  = 1.
l_str-field4  = ''.
l_str-field5  = ''.
APPEND l_str TO l_itab.

CLEAR l_str.
l_str-field1  = 12.
l_str-field2  = 11.
l_str-field3  = 2.
l_str-field4  = ''.
l_str-field5  = ''.
APPEND l_str TO l_itab.

CLEAR l_str.
l_str-field1  = 12.
l_str-field2  = 11.
l_str-field3  = 1.
l_str-field4  = ''.
l_str-field5  = ''.
APPEND l_str TO l_itab.

CLEAR l_str.
l_str-field1  = 12.
l_str-field2  = 11.
l_str-field3  = 1.
l_str-field4  = ''.
l_str-field5  = ''.
APPEND l_str TO l_itab.

CLEAR l_str.
l_str-field1  = 12.
l_str-field2  = 11.
l_str-field3  = 2.
l_str-field4  = ''.
l_str-field5  = ''.
APPEND l_str TO l_itab.

CLEAR l_str.

SORT l_itab BY field1 field2 field3 field4.

LOOP AT l_itab INTO l_str.
  IF l_str_temp &amp;lt;&amp;gt; l_str.
    l_count = 1.
    l_str_temp = l_str.
    l_str-field4 = l_count.
    MODIFY l_itab FROM l_str.
  ELSE.
    l_count = l_count + 1.
    l_str-field4 = l_count.
    MODIFY l_itab FROM l_str.
  ENDIF.
  CLEAR l_str.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After your internal table has the correct data, then update the entries in the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;George&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2009 12:29:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672031#M1289783</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-26T12:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Loop question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672032#M1289784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As long as A, B and C are not numerical fields and field D is, create an additional internal table with the same definition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT your_table INTO wa_your_table.

     wa_your_table-D = 1.
     COLLECT wa_your_table INTO a_new_table.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As long as A, B and C are the same, the value of D will be incremented with 1 by the COLLECT statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2009 13:07:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-question/m-p/5672032#M1289784</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-26T13:07:41Z</dc:date>
    </item>
  </channel>
</rss>

