<?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 in internal table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892395#M53649</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Judith,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure that is correct. SY-INDEX will hold the index of the last record that was looped at, but this may not necessarily be equal to the number of records matching the condition. (By the way, possibly you mean SY-TABIX).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the following example. After looping through the table, SY-TABIX = 3. There are, however, only 2 records matching the condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;        val1 type c,&lt;/P&gt;&lt;P&gt;        val2 type c,&lt;/P&gt;&lt;P&gt;      end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val1 = 'A'.&lt;/P&gt;&lt;P&gt;itab-val2 = 'C'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val1 = 'A'.&lt;/P&gt;&lt;P&gt;itab-val2 = 'B'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val1 = 'A'.&lt;/P&gt;&lt;P&gt;itab-val2 = 'C'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab where val2 = 'C'.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write: sy-tabix.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 May 2005 12:05:37 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-05-26T12:05:37Z</dc:date>
    <item>
      <title>Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892390#M53644</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;How can i get the number of records(count) in an Internal table based on some condition.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 08:21:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892390#M53644</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-05-26T08:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892391#M53645</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;data cnt type i.&lt;/P&gt;&lt;P&gt;i = 0.&lt;/P&gt;&lt;P&gt;Loop at internaltable into workarea where condition.&lt;/P&gt;&lt;P&gt;i = i + 1.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write : 'Count:',i.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 08:27:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892391#M53645</guid>
      <dc:creator>jayanthi_jayaraman</dc:creator>
      <dc:date>2005-05-26T08:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892392#M53646</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;Loop at itab where &amp;lt;cond&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;add 1 to counter&amp;lt;/b&amp;gt;.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also,If u r doing a looping alone then, After looping at the internal table (after endloop) u can also get the value of &amp;lt;b&amp;gt;sy-index&amp;lt;/b&amp;gt;. This will hold the count in that internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sapdevelopment.co.uk/reporting/ind/ind_count.htm" target="test_blank"&gt;http://www.sapdevelopment.co.uk/reporting/ind/ind_count.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Judith.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Judith Jessie Selvi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 08:30:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892392#M53646</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-05-26T08:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892393#M53647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Suzane,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You cannot find the count in one direct statement. You will have to use the count() in your select, or if that is not possible, then:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Easy option:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab where field1 = condition1.&lt;/P&gt;&lt;P&gt;  counter = counter + 1.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A lesser easy way, and not always feasible:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab_copy[] = itab[].&lt;/P&gt;&lt;P&gt;delete itab_copy where field1 NE condition1.&lt;/P&gt;&lt;P&gt;describe table itab_copy lines lv_lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, Rahul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 08:30:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892393#M53647</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-05-26T08:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892394#M53648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the only possible way is by looping over the table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Counter = 0.&lt;/P&gt;&lt;P&gt;LOOP AT itab WHERE cond1 AND cond2. &lt;/P&gt;&lt;P&gt;Counter = counter + 1.&lt;/P&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might gain some speed if it is a large table by &lt;/P&gt;&lt;P&gt;using field symbols or references, this avoids the cost of copying the table record to the work area.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at itab assigning &amp;lt;FS&amp;gt; where cond1 AND cond2.&lt;/P&gt;&lt;P&gt;counter = counter + 1.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at itab reference into dref where cond1 AND cond2.&lt;/P&gt;&lt;P&gt;counter = counter + 1.&lt;/P&gt;&lt;P&gt;endloop.&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;Joris.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 08:46:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892394#M53648</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-05-26T08:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892395#M53649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Judith,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure that is correct. SY-INDEX will hold the index of the last record that was looped at, but this may not necessarily be equal to the number of records matching the condition. (By the way, possibly you mean SY-TABIX).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the following example. After looping through the table, SY-TABIX = 3. There are, however, only 2 records matching the condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;        val1 type c,&lt;/P&gt;&lt;P&gt;        val2 type c,&lt;/P&gt;&lt;P&gt;      end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val1 = 'A'.&lt;/P&gt;&lt;P&gt;itab-val2 = 'C'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val1 = 'A'.&lt;/P&gt;&lt;P&gt;itab-val2 = 'B'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab-val1 = 'A'.&lt;/P&gt;&lt;P&gt;itab-val2 = 'C'.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab where val2 = 'C'.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write: sy-tabix.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 12:05:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892395#M53649</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-05-26T12:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count in internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892396#M53650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data: v_line type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Describe table itab lines v_line. (for all records)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Write: v_line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;if (condition)&lt;/P&gt;&lt;P&gt;add 1 to v_line.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2005 17:06:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/count-in-internal-table/m-p/892396#M53650</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-05-26T17:06:40Z</dc:date>
    </item>
  </channel>
</rss>

