<?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: Internal table using collect in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067467#M93732</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nandha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please give somemore information with a clear example? Please correct me if I am wrong. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have an internal table ITAB with 4 fields, let us say A, B, C and D. You gave us the values of the internal table as follows&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
A   B  C
1  Nan 30
2  Rav 40
3  Ram 20
4  Raj 20
5  Nan 10&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you want to know how many times a value in column B is repeated and have that to be in your 4th column D. I don't think you can achieve that using COLLECT. You have to do it in a loop and by sorting your ITAB. Try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT itab BY b.
LOOP AT itab.
  IF v_previous_b_value = itab-b.
*-- the value in column B hasn't changed, increment the count
    b_count = b_count + 1.
  ELSE.
*-- it is a new B value, modify the internal table
*   with previous B value count
    IF sy-tabix = 1.
*-- this is the first record, do not do the update
      b_count = 1.
    ELSE.
      itab-d = b_count.
      MODIFY itab TRANSPORTING b_count WHERE b = v_previous_b_value.
      b_count = 1.
    ENDIF.
  ENDIF.
  v_previous_b_value = itab-b.
ENDLOOP.
*-- for the last record
itab-d = b_count.
MODIFY itab TRANSPORTING b_count WHERE b = v_previous_b_value.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am just typing this out directly without testing, but I think you will get the idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Nov 2005 05:22:17 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-11-25T05:22:17Z</dc:date>
    <item>
      <title>Internal table using collect</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067463#M93728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; I have some problem in internal table using collect.&lt;/P&gt;&lt;P&gt;thatis&lt;/P&gt;&lt;P&gt;it1-1 it-2  it-3 it-4(Count of it-2)&lt;/P&gt;&lt;P&gt;1      Nan  30    2&lt;/P&gt;&lt;P&gt;2      Rav  40    1&lt;/P&gt;&lt;P&gt;3      Ram  20    1&lt;/P&gt;&lt;P&gt;4      Raj  20    1&lt;/P&gt;&lt;P&gt;5      Nan  10    2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is my internal table.&lt;/P&gt;&lt;P&gt;here it-4 is no.of time repeated counted through loop.&lt;/P&gt;&lt;P&gt;Now i am giving collect means no.of time repeated will show all '1' only not no.of times repeated. here i want to count before display and before collect.1 ,2 and 3 fields are collected from database field 4 generated dynamically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or else i want to copy same fields to another it means field 4 last line count only showing otherslines are displaying 0's&lt;/P&gt;&lt;P&gt;What i can do?.  &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nandha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2005 12:32:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067463#M93728</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-11-24T12:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Internal table using collect</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067464#M93729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nandha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Keep in the mind that it1 it2 should be of non-numneric fields. &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Is that it3 and it4 are numeric ??? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; so Using COLLECT will add values in it3 and it4 making single row for Nan eg : .&lt;/P&gt;&lt;P&gt; Rav 40 1&lt;/P&gt;&lt;P&gt; Ram 20 1&lt;/P&gt;&lt;P&gt; Raj 20 1&lt;/P&gt;&lt;P&gt; Nan &amp;lt;b&amp;gt;40 4&amp;lt;/b&amp;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;Kam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2005 12:40:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067464#M93729</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-11-24T12:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Internal table using collect</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067465#M93730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the first field in numeric then use of collect would result in&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2 Rav 40 1&lt;/P&gt;&lt;P&gt;3 Ram 20 1&lt;/P&gt;&lt;P&gt;4 Raj 20 1&lt;/P&gt;&lt;P&gt;6 Nan 40 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is non-numeric,&lt;/P&gt;&lt;P&gt;then, this will result&lt;/P&gt;&lt;P&gt;1 Nan 30 2&lt;/P&gt;&lt;P&gt;2 Rav 40 1&lt;/P&gt;&lt;P&gt;3 Ram 20 1&lt;/P&gt;&lt;P&gt;4 Raj 20 1&lt;/P&gt;&lt;P&gt;5 Nan 10 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2005 13:56:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067465#M93730</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-11-24T13:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Internal table using collect</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067466#M93731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; This is ok but i don't want to sum 4th column.4th column value is the count of third column &lt;/P&gt;&lt;P&gt;i.e nan tow times repeated means it'll show 2 &lt;/P&gt;&lt;P&gt;that 2 i need without changes&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nandha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2005 02:58:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067466#M93731</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-11-25T02:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Internal table using collect</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067467#M93732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nandha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please give somemore information with a clear example? Please correct me if I am wrong. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have an internal table ITAB with 4 fields, let us say A, B, C and D. You gave us the values of the internal table as follows&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
A   B  C
1  Nan 30
2  Rav 40
3  Ram 20
4  Raj 20
5  Nan 10&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you want to know how many times a value in column B is repeated and have that to be in your 4th column D. I don't think you can achieve that using COLLECT. You have to do it in a loop and by sorting your ITAB. Try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT itab BY b.
LOOP AT itab.
  IF v_previous_b_value = itab-b.
*-- the value in column B hasn't changed, increment the count
    b_count = b_count + 1.
  ELSE.
*-- it is a new B value, modify the internal table
*   with previous B value count
    IF sy-tabix = 1.
*-- this is the first record, do not do the update
      b_count = 1.
    ELSE.
      itab-d = b_count.
      MODIFY itab TRANSPORTING b_count WHERE b = v_previous_b_value.
      b_count = 1.
    ENDIF.
  ENDIF.
  v_previous_b_value = itab-b.
ENDLOOP.
*-- for the last record
itab-d = b_count.
MODIFY itab TRANSPORTING b_count WHERE b = v_previous_b_value.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am just typing this out directly without testing, but I think you will get the idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2005 05:22:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/internal-table-using-collect/m-p/1067467#M93732</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-11-25T05:22:17Z</dc:date>
    </item>
  </channel>
</rss>

