<?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 MAX( ) function in 2 columns... Wrong Data in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495403#M1257287</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have A DDIC Table with &lt;/P&gt;&lt;P&gt;mandt, Destination, Date, Time, KUNNR and some other columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I want to determine the LATEST entry for a KUNNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I did:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;       mandt desti kunnr MAX( erdat )&lt;/P&gt;&lt;P&gt;       MAX( ertim ) [..other nonkey fields.]&lt;/P&gt;&lt;P&gt;       FROM MYTABLE INTO wa&lt;/P&gt;&lt;P&gt;       WHERE desti = '10010'&lt;/P&gt;&lt;P&gt;       AND   kunnr = '0000000005'&lt;/P&gt;&lt;P&gt;       AND   not_checked = 'X'&lt;/P&gt;&lt;P&gt;       GROUP BY mandt desti kunnr [..other nonkey fields.].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WRITE [ALL FIELDS]&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I get 5(!) results:&lt;/P&gt;&lt;P&gt;001 RE3_001  5          11.03.2009 12:59:55&lt;/P&gt;&lt;P&gt;001 RE3_001  5          12.03.2009 15:29:01&lt;/P&gt;&lt;P&gt;001 RE3_001  5          11.03.2009 19:27:50&lt;/P&gt;&lt;P&gt;001 RE3_001  5          11.03.2009 13:23:30&lt;/P&gt;&lt;P&gt;001 RE3_001  5          30.06.2008 16:45:26&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is that?&lt;/P&gt;&lt;P&gt;I only needed the 12.03.2009 at 15:29:01 .....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what do I do wrong?&lt;/P&gt;&lt;P&gt;what about the MAX() ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Apr 2009 07:14:39 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-04-22T07:14:39Z</dc:date>
    <item>
      <title>MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495403#M1257287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have A DDIC Table with &lt;/P&gt;&lt;P&gt;mandt, Destination, Date, Time, KUNNR and some other columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I want to determine the LATEST entry for a KUNNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I did:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;       mandt desti kunnr MAX( erdat )&lt;/P&gt;&lt;P&gt;       MAX( ertim ) [..other nonkey fields.]&lt;/P&gt;&lt;P&gt;       FROM MYTABLE INTO wa&lt;/P&gt;&lt;P&gt;       WHERE desti = '10010'&lt;/P&gt;&lt;P&gt;       AND   kunnr = '0000000005'&lt;/P&gt;&lt;P&gt;       AND   not_checked = 'X'&lt;/P&gt;&lt;P&gt;       GROUP BY mandt desti kunnr [..other nonkey fields.].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WRITE [ALL FIELDS]&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I get 5(!) results:&lt;/P&gt;&lt;P&gt;001 RE3_001  5          11.03.2009 12:59:55&lt;/P&gt;&lt;P&gt;001 RE3_001  5          12.03.2009 15:29:01&lt;/P&gt;&lt;P&gt;001 RE3_001  5          11.03.2009 19:27:50&lt;/P&gt;&lt;P&gt;001 RE3_001  5          11.03.2009 13:23:30&lt;/P&gt;&lt;P&gt;001 RE3_001  5          30.06.2008 16:45:26&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is that?&lt;/P&gt;&lt;P&gt;I only needed the 12.03.2009 at 15:29:01 .....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what do I do wrong?&lt;/P&gt;&lt;P&gt;what about the MAX() ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 07:14:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495403#M1257287</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T07:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495404#M1257288</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;&lt;/P&gt;&lt;P&gt;Fetch all the data from the MYTABLE with where conditions.&lt;/P&gt;&lt;P&gt;Then sort the table with Date and time key with descending order after sorting read the MyTable with index 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will get it..............&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 07:17:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495404#M1257288</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T07:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495405#M1257289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;k.. thx...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but WHY do I get the 11.03 at all?&lt;/P&gt;&lt;P&gt;or the 30.08? there is no MAX at all in this column ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought the MAX means 1 line ... ONLY if I have 2 equal lines, Ill get 2 ... but 5lines, which are not equal at date and time? that sounds weird...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 07:22:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495405#M1257289</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T07:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495406#M1257290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Markus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a alternate you can select all &amp;amp; sort it and delete it by keeping the first record.. this is the simplest way as both has the same effect on the database,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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 &amp;amp; regards,&lt;/P&gt;&lt;P&gt;Dileep .C&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 07:31:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495406#M1257290</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T07:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495407#M1257291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE level="1"&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; SELECT&lt;/P&gt;&lt;P&gt;&amp;gt;        mandt desti kunnr MAX( erdat )&lt;/P&gt;&lt;P&gt;&amp;gt;        MAX( ertim ) &lt;A href="..other nonkey fields."&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;        FROM MYTABLE INTO wa&lt;/P&gt;&lt;P&gt;&amp;gt;        WHERE desti = '10010'&lt;/P&gt;&lt;P&gt;&amp;gt;        AND   kunnr = '0000000005'&lt;/P&gt;&lt;P&gt;&amp;gt;        AND   not_checked = 'X'&lt;/P&gt;&lt;P&gt;&amp;gt;        GROUP BY mandt desti kunnr &lt;A href="..other nonkey fields."&gt;&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; ENDSELECT.&lt;/P&gt;&lt;P&gt;&amp;gt; THX&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT
  desti kunnr
FROM MYTABLE as o INTO wa
WHERE desti = '10010'
AND   kunnr = '0000000005'
AND   not_checked = 'X'
AND ertim = ( select max(ertim)
                     from mytable as i
                     where o~desti = i~desti
                       and o~kunnr = i~kunnr )
ENDSELECT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe you have to adopt the select statement above to fit your needs a little bit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 08:05:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495407#M1257291</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2009-04-22T08:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495408#M1257292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I cant use any subquery. its a table with over 1.000.000 entries....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And: my Problem is NOT how I get the Data, I want to know WHY the MAX() doesnt work as expected...&lt;/P&gt;&lt;P&gt;If I delete all other fields except ERDAT and ERTIM &lt;/P&gt;&lt;P&gt;I get the  maximum Date (15.03) and the maximum time (19:XX) ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;why???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Markus Völker on Apr 22, 2009 10:43 AM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 08:39:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495408#M1257292</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T08:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495409#M1257293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A group by clause used for a big table is even more worth as a subselect with an index an the join condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The group by is just not working as it is expected by you. you can make it working using the having clause but at least this will lead to a subquery again. The problem is not the max clause, its the group by clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW: if you want to know why your select statement does not work, why are you asking in a forum where the topic is abap?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 08:55:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495409#M1257293</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2009-04-22T08:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495410#M1257294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Markus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MAX field will select the Maximum no. &lt;/P&gt;&lt;P&gt;where as it doesnt recognise date fields ithink so. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the todays date is stored as 22042009 and lets say last year 22122008... now it picks the december value as the MAX value..&lt;/P&gt;&lt;P&gt;and its doesnt take the combination... you cannot use 2 MAX for one select Query,, &lt;/P&gt;&lt;P&gt;if you use there will be same type of miss match as it doest compare the Time for the particular day instead it looks for all the data...&lt;/P&gt;&lt;P&gt;I think so this is the problem,,,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;&lt;P&gt;Dileep .C&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 09:00:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495410#M1257294</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T09:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: MAX( ) function in 2 columns... Wrong Data</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495411#M1257295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thx..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I asked here, because it is ABAP.&lt;/P&gt;&lt;P&gt;Where else should I have asked?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Markus Völker on Apr 22, 2009 11:01 AM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 09:01:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/max-function-in-2-columns-wrong-data/m-p/5495411#M1257295</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-22T09:01:04Z</dc:date>
    </item>
  </channel>
</rss>

