<?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 on table with same field in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984648#M1161317</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the solution I proposed will not change anything with the internal table you want to check. &lt;/P&gt;&lt;P&gt;Your question was how to detect non-unique values in a certain table field. In your example, how to detect the second occurence of '10' in field 'field2'.&lt;/P&gt;&lt;P&gt;The solution is to create a second internal table just for the values of this field. This new table is good for nothing except the detection of non-unique entries - just what you want.&lt;/P&gt;&lt;P&gt;Please have a look at my solution again. ITAB is the internal table you have the values in. It is not modified at all - not the structure, not the contents. I will just LOOP at it to see the contents. I use 'ASSIGNING &amp;lt;field-symbol&amp;gt; because this makes the loop up to 6 times faster. In the loop, I put the value of 'field2' into the second, hashed table. If this is successful, it is the first occurence of this value.- If not, you have a duplicate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just copy and paste my code - it will work for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Jan 2009 11:54:40 GMT</pubDate>
    <dc:creator>Clemenss</dc:creator>
    <dc:date>2009-01-02T11:54:40Z</dc:date>
    <item>
      <title>loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984639#M1161308</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 have internal table and i want to now if i have the same field in table twice ,&lt;/P&gt;&lt;P&gt;i want to insert some code ,what is the &lt;STRONG&gt;best&lt;/STRONG&gt; way to do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;itab
field1    field2
a                 1    
b               10
c               10 
d                 5
e                 6&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i want to loop on itab and if in field2 i have 10 more then one time,&lt;/P&gt;&lt;P&gt;insert some code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 20:11:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984639#M1161308</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T20:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984640#M1161309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use Some sort of logic like below,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Sort itab by field2.
loop at itab.
if temp = itab-field2.
inset code.
endif.
temp = itab-field2.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 20:36:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984640#M1161309</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T20:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984641#M1161310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Go for &lt;STRONG&gt;control loop statements&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: pos type i.

Loop at itab.
  at new field2.
    pos = sy-tabix.  "rememebr position of first occurence of field2 value
  endat.

  at end of field2.
    if pos ne sy-tabix.   "check if first occurence is the last one
       "value for field2 is place more than one time in itab
       "do your coding here
    endif.
   clear pos.
  endat.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note that &lt;STRONG&gt;field1&lt;/STRONG&gt; and &lt;STRONG&gt;field2&lt;/STRONG&gt; must be declared as key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 20:37:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984641#M1161310</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-01-01T20:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984642#M1161311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for this purpose a hashed table is useful:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
field-symbols:
* use a field-symbol for optimal loop performance regardless of itab structure
  &amp;lt;line&amp;gt; like line of itab.
data:
  lt_field2_unique like hashed table of itab-field2 with unique key table line.
loop at itab assigning &amp;lt;line&amp;gt;.
* put field2 value into internal table - HASHED guarantees only unique entries
  insert &amp;lt;line&amp;gt;-field2 into table lt_field2_unique.
  if sy-subrc NE 0.
* duplicate insert fails - Duplicate detected - insert your code here
  endif. 
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards and Happy New Year!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 20:57:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984642#M1161311</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2009-01-01T20:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984643#M1161312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Clemens ,&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;the internal table is table that i don't think that i can change the key ,&lt;/P&gt;&lt;P&gt;the table is table extract  from maintenance  view and i move it to internal table and their i do manipulation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 21:07:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984643#M1161312</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T21:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984644#M1161313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Clemens ,&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;the internal table is table that i don't think that i can use like hash,&lt;/P&gt;&lt;P&gt;the table is table extract  from maintenance  view and i move it to my internal table&lt;/P&gt;&lt;P&gt;and their i do the manipulation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;And Happy New Year &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 21:09:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984644#M1161313</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-01T21:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984645#M1161314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So you can declare your internal table with key fields different from maintenance view.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
types: begin of t_tab,
            field1 type ...
            field2 type ...
          end of t_tab.

data: itab table table of t_tab with key field1 field2 with header line.

"now just extract data from your view to your internal table, I think only field names are critical here so you can use (in a loop)

move-corresponding view_structure to itab.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try it out.&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2009 21:16:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984645#M1161314</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-01-01T21:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984646#M1161315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Marcin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i try it and let u now .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jan 2009 07:48:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984646#M1161315</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-02T07:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984647#M1161316</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 like this:&lt;/P&gt;&lt;P&gt;data: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;      field1 type c,&lt;/P&gt;&lt;P&gt;      field2(10) type c,&lt;/P&gt;&lt;P&gt;      end of itab.&lt;/P&gt;&lt;P&gt;data: c1 like itab-field2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-field1 = 'a'.&lt;/P&gt;&lt;P&gt;itab-field2 = '1'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-field1 = 'b'.&lt;/P&gt;&lt;P&gt;itab-field2 = '10'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-field1 = 'c'.&lt;/P&gt;&lt;P&gt;itab-field2 = '10'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-field1 = 'd'.&lt;/P&gt;&lt;P&gt;itab-field2 = '5'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;itab-field1 = 'e'.&lt;/P&gt;&lt;P&gt;itab-field2 = '6'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;if c1 &amp;lt;&amp;gt; itab-field2.&lt;/P&gt;&lt;P&gt;  write:/ itab-field1, itab-field2.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;  itab-field2 = 'duplicate'.&lt;/P&gt;&lt;P&gt;  write:/ itab-field1, itab-field2.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;c1 = itab-field2.&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;Bhaskar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jan 2009 08:41:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984647#M1161316</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-02T08:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: loop on table with same field</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984648#M1161317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the solution I proposed will not change anything with the internal table you want to check. &lt;/P&gt;&lt;P&gt;Your question was how to detect non-unique values in a certain table field. In your example, how to detect the second occurence of '10' in field 'field2'.&lt;/P&gt;&lt;P&gt;The solution is to create a second internal table just for the values of this field. This new table is good for nothing except the detection of non-unique entries - just what you want.&lt;/P&gt;&lt;P&gt;Please have a look at my solution again. ITAB is the internal table you have the values in. It is not modified at all - not the structure, not the contents. I will just LOOP at it to see the contents. I use 'ASSIGNING &amp;lt;field-symbol&amp;gt; because this makes the loop up to 6 times faster. In the loop, I put the value of 'field2' into the second, hashed table. If this is successful, it is the first occurence of this value.- If not, you have a duplicate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just copy and paste my code - it will work for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jan 2009 11:54:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-on-table-with-same-field/m-p/4984648#M1161317</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2009-01-02T11:54:40Z</dc:date>
    </item>
  </channel>
</rss>

