<?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: Max Count in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488796#M1420059</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Select  the data to your internal table and then manipulate it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Jan 2010 18:20:14 GMT</pubDate>
    <dc:creator>kesavadas_thekkillath</dc:creator>
    <dc:date>2010-01-18T18:20:14Z</dc:date>
    <item>
      <title>Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488790#M1420053</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'm a newbie in Abap-Development but I Have developed in some other languages. &lt;/P&gt;&lt;P&gt;My Problem is, that I have to select the max count of a table like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select tab1-field1 max( Count( tab2-field1 ) ) from tab1 inner join tab2 on tab1-field1 = tab2-field2 group by tab1-field1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In single steps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to see, is the maximum count of tab2-field1 in relation to tab1-field1. How can I do this? In Abap I can not write this sql, because ofter the max is an field expected, am i right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 16:12:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488790#M1420053</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-18T16:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488791#M1420054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot use MAX and COUNT together i think so.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select tab2&lt;SUB&gt;field2 max( tab2&lt;/SUB&gt;field1 )  &lt;/P&gt;&lt;P&gt;from tab2 inner join tab1&lt;/P&gt;&lt;P&gt;on tab2&lt;SUB&gt;field2 = tab1&lt;/SUB&gt;field1 &lt;/P&gt;&lt;P&gt;group by tab2~field2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 16:23:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488791#M1420054</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-01-18T16:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488792#M1420055</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;this sql will not solve my problem. In this case I have the maximum value of the field, but not the maximum count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tab1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field1               Field2&lt;/P&gt;&lt;P&gt;1                         2&lt;/P&gt;&lt;P&gt;2                         3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tab2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field1               Field2&lt;/P&gt;&lt;P&gt;1                           1&lt;/P&gt;&lt;P&gt;2                           1&lt;/P&gt;&lt;P&gt;3                           1&lt;/P&gt;&lt;P&gt;4                           2&lt;/P&gt;&lt;P&gt;5                           2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result I will have&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1                           3&lt;/P&gt;&lt;P&gt;2                           2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a simple example. in reality I must join over more than 3 tables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 16:30:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488792#M1420055</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-18T16:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488793#M1420056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter, your requirement is not clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to see both the rows&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then why are you using max(count())?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Shouldn't you be using Keshav's suggestion, but replace max with count?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or, do you just want to see one row (1 3) in your results?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the results to be one row, then you can accomplish that using two SQL statements. I don't know if there is a way to do that in one statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select field2 count(field2)&lt;/P&gt;&lt;P&gt;into (l_field2, l_field2_count)&lt;/P&gt;&lt;P&gt;from tab2&lt;/P&gt;&lt;P&gt;up to 1 rows&lt;/P&gt;&lt;P&gt;group by field2&lt;/P&gt;&lt;P&gt;order by fiel2 descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select field1 field2&lt;/P&gt;&lt;P&gt;into (l_tab1_field1, l_tab1_field2)&lt;/P&gt;&lt;P&gt;from tab1&lt;/P&gt;&lt;P&gt;where field1 = l_field2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 16:48:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488793#M1420056</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-18T16:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488794#M1420057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you can do this in the SQL of the database, tyhen you should be able to do it in ABAP native rather than open SQL.You can learn about native SQL by pressing F1 on EXEC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 17:09:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488794#M1420057</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-18T17:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488795#M1420058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay... i will explain again:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in table1 i have some vendors and in table2 are some vouchers to different vendors with different dates.&lt;/P&gt;&lt;P&gt;If I select the count of vouchers differentiated by month and vendor, i want the maximum of this result differentiated by the vendor. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I will have the maximum count of voucher in a month per vendor. For this I must first select the count of vouchers per month and then select the maximum of this result for each vendor. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, I don't know how to explain better.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 17:09:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488795#M1420058</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-18T17:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488796#M1420059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Select  the data to your internal table and then manipulate it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jan 2010 18:20:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488796#M1420059</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-01-18T18:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488797#M1420060</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;it's not right, that I con do the same SQL-Statement in Open-SQL than in "normal"-SQL. In Open-SQL I can not do something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select a&lt;SUB&gt;field1 b&lt;/SUB&gt;field2 From tab1 as a (Select * from tab2) as b&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This SQL-Statement I can procced direct on all databases but not in Open-SQL. Or?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greets,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 08:23:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488797#M1420060</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T08:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Max Count</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488798#M1420061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can understand your concern. for all these kind of logic eg. Max, Min, second maximum etc, - These are ok if we directly in sql in database.(non-sap) eg. Oracle, MS SQL etc, in legacy systems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; But in SAP, in abap, such complicated queries are not feasible. For such things, it is better to manipulate internal tables and use abap syntax to find out the desire result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case, we can use COLLECT syntax (please see F1 help) to get the SUMMARY of records, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vendor wise + Month wise to get the COUNT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can sort this  itab DESCENDING to get the max.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...... this kind of some logic, instead of TWISTING the SQL.&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;regards,&lt;/P&gt;&lt;P&gt;amit m.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2010 08:40:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-count/m-p/6488798#M1420061</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-19T08:40:09Z</dc:date>
    </item>
  </channel>
</rss>

