<?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: Count the values in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039907#M1350704</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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can keep the logic simple by this approach. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 1: Sort the internal table by the 2nd Column. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 2: By processing the individual lines of the internal table you can track the changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code extract is given below:&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 : Count type i value 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at new column2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;count = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;count = count + 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;your  own logic here.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&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;&lt;/P&gt;&lt;P&gt;Samantak.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Aug 2009 17:47:37 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-08-08T17:47:37Z</dc:date>
    <item>
      <title>Count the values</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039905#M1350702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai Friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 A 10&lt;/P&gt;&lt;P&gt;1 A 20&lt;/P&gt;&lt;P&gt;1 A 30&lt;/P&gt;&lt;P&gt;1 B 30&lt;/P&gt;&lt;P&gt;1 B 20&lt;/P&gt;&lt;P&gt;1 C 20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the count of 1st column when there is a change in second column. That is,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 A 10 &lt;/P&gt;&lt;P&gt;1 A 20&lt;/P&gt;&lt;P&gt;1 A 30 count is 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 B 30&lt;/P&gt;&lt;P&gt;1 B 20 count is 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 C 20 count is 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Aug 2009 15:59:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039905#M1350702</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-08T15:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count the values</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039906#M1350703</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;The itab must be sorted accordingly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: ld_sum             TYPE i,
DATA: ls_record         LIKE LINE OF lt_itab,
DATA: ls_record_old  LIKE LINE OF lt_itab.

  SORT lt_itab BY column2.
  
  ld_sum = 0.
  READ TABLE lt_itab INTO ls_record_old INDEX 1.
  LOOP AT lt_itab INTO ls_record.

    IF ( ls_record-column2 = ls_record_old-column2 ).
     ADD ls_record-column1 TO ld_sum.
    ELSE.
      " NOTE: Here you have store the value of LD_SUM somewhere

      ld_sum = ls_record-column1.
    ENDIF.

    ls_record_old = ls_record.
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards &lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Aug 2009 17:00:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039906#M1350703</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-08-08T17:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count the values</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039907#M1350704</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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can keep the logic simple by this approach. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 1: Sort the internal table by the 2nd Column. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 2: By processing the individual lines of the internal table you can track the changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code extract is given below:&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 : Count type i value 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at new column2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;count = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;count = count + 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;your  own logic here.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&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;&lt;/P&gt;&lt;P&gt;Samantak.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Aug 2009 17:47:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039907#M1350704</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-08T17:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count the values</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039908#M1350705</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;Please check this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF itab OCCURS 0,
        f1 TYPE char10,
        f2 TYPE char10,
        f3 TYPE char10,
      END OF itab.

DATA: count TYPE i.

itab-f1 = '1'.
itab-f2 = 'A'.
itab-f3 = '10'.
APPEND itab.

itab-f1 = '1'.
itab-f2 = 'A'.
itab-f3 = '20'.
APPEND itab.

itab-f1 = '1'.
itab-f2 = 'A'.
itab-f3 = '30'.
APPEND itab.

itab-f1 = '1'.
itab-f2 = 'B'.
itab-f3 = '30'.
APPEND itab.

itab-f1 = '1'.
itab-f2 = 'B'.
itab-f3 = '20'.
APPEND itab.

itab-f1 = '1'.
itab-f2 = 'C'.
itab-f3 = '20'.
APPEND itab.

count = 0.
LOOP AT itab.
  WRITE:/ itab-f1, itab-f2, itab-f3.
  count = count + 1.
  AT END OF f2.
    WRITE:/'Count is ', count.
    CLEAR count.
  ENDAT.

ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 05:09:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-the-values/m-p/6039908#M1350705</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-10T05:09:41Z</dc:date>
    </item>
  </channel>
</rss>

