<?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: Need help with sql stmt in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383853#M187056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure an aggregate function will give the same name as the field... meaning, MAX( f2 ) does not produce a field called f2.  I could be wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are there only two fields in &amp;lt;itab&amp;gt;?  If yes, remove "corresponding fields".&lt;/P&gt;&lt;P&gt;You could do us an alias like "MAX( f2 ) as f2".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Jul 2006 17:21:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-07-20T17:21:01Z</dc:date>
    <item>
      <title>Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383849#M187052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have select stmt like this, but this is not returning the max value of the field f2. Just gives me 0 even though there are 2 entries in the table.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; select f1 MAX( f2 ) from &amp;lt;table&amp;gt;&lt;/P&gt;&lt;P&gt;         into corresponding fields of table &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;         where f1 in r_f1&lt;/P&gt;&lt;P&gt;         group by f1.&lt;/P&gt;&lt;P&gt;What am I  missing? I appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Anu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:01:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383849#M187052</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383850#M187053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;did you declare f2 like &amp;lt;table&amp;gt;-f2 in your &amp;lt;itab&amp;gt; struct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below statement is working perfectly all right for me.&lt;/P&gt;&lt;P&gt;SELECT MAX( saptdid ) INTO wa_header-saptdid FROM zfi_ephdr.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:06:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383850#M187053</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383851#M187054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes I did Amit . But  I need the key field(f1) and its max value for f2, not the max of f2 from the whole table. &lt;/P&gt;&lt;P&gt;Each f1 starts from 1 and gets incremented like internal number concept. &lt;/P&gt;&lt;P&gt;Whatever you said works good. But that is not what  I need. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Anu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:10:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383851#M187054</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383852#M187055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Anupama,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use some variables like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: f1 type table-field_name,&lt;/P&gt;&lt;P&gt;      maximum type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select f1 MAX( f2 ) into (variable_name1, maximum) from &amp;lt;table&amp;gt; group by field_name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here key field can be f1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:17:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383852#M187055</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383853#M187056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure an aggregate function will give the same name as the field... meaning, MAX( f2 ) does not produce a field called f2.  I could be wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are there only two fields in &amp;lt;itab&amp;gt;?  If yes, remove "corresponding fields".&lt;/P&gt;&lt;P&gt;You could do us an alias like "MAX( f2 ) as f2".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:21:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383853#M187056</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383854#M187057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi anupama,&lt;/P&gt;&lt;P&gt;give like this....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select f1 MAX( f2 ) from &amp;lt;table&amp;gt;&lt;/P&gt;&lt;P&gt;into corresponding fields of table &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;where f1 in r_f1&lt;/P&gt;&lt;P&gt;group by f1 f2&lt;/P&gt;&lt;P&gt;order by f1.&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and check this also ....its from help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MAX( [DISTINCT] fdescriptor ) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition: &lt;/P&gt;&lt;P&gt;... AS alias &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;Returns the largest value for the selected lines in thecolumn identified by the Field descriptor fdescriptor.The DISTINCT specification does not alter theresult. NULL values are ignored in the calculation, except whenall of the values in a column are NULL. In this case, the resultis NULL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Output a list of all customers on Lufthansa flight 0400in 1995, along with the highest price paid, sorted by customer name: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TABLES: SCUSTOM, SBOOK. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SCUSTOM&lt;SUB&gt;NAME SCUSTOM&lt;/SUB&gt;POSTCODE SCUSTOM~CITY &lt;/P&gt;&lt;P&gt;         MAX( SBOOK~LOCCURAM ) &lt;/P&gt;&lt;P&gt;       INTO (SCUSTOM-NAME, SCUSTOM-POSTCODE, SCUSTOM-CITY, &lt;/P&gt;&lt;P&gt;             SBOOK-LOCCURAM) &lt;/P&gt;&lt;P&gt;       FROM SCUSTOM INNER JOIN SBOOK &lt;/P&gt;&lt;P&gt;         ON SCUSTOM&lt;SUB&gt;ID = SBOOK&lt;/SUB&gt;CUSTOMID &lt;/P&gt;&lt;P&gt;       WHERE SBOOK~FLDATE BETWEEN '19950101' AND '19951231' AND &lt;/P&gt;&lt;P&gt;             SBOOK~CARRID   = 'LH '                         AND &lt;/P&gt;&lt;P&gt;             SBOOK~CONNID   = '0400' &lt;/P&gt;&lt;P&gt;       GROUP BY SCUSTOM&lt;SUB&gt;NAME SCUSTOM&lt;/SUB&gt;POSTCODE SCUSTOM~CITY &lt;/P&gt;&lt;P&gt;       ORDER BY SCUSTOM~NAME. &lt;/P&gt;&lt;P&gt;  WRITE: / SCUSTOM-NAME, SCUSTOM-POSTCODE, SCUSTOM-CITY, &lt;/P&gt;&lt;P&gt;           SBOOK-LOCCURAM. &lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:21:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383854#M187057</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383855#M187058</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;A small correction. I think this would work fine...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data: var1 type table-f1,&lt;/P&gt;&lt;P&gt;      maxi type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select f1 MAX( f2 )into (var1, maxi)  from &amp;lt;table&amp;gt; group by f1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Key field is f1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:23:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383855#M187058</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383856#M187059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about using below logic instead of your logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select f1 MAX( f2 ) from &amp;lt;table&amp;gt;&lt;/P&gt;&lt;P&gt;into corresponding fields of table &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;where f1 in r_f1. &lt;/P&gt;&lt;P&gt;I am not sure about group by here&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How about using below logic instead of your logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select f1  f2  from &amp;lt;table&amp;gt;&lt;/P&gt;&lt;P&gt;into corresponding fields of table &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;where f1 in r_f1. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then sort  &amp;lt;itab&amp;gt; descending.&lt;/P&gt;&lt;P&gt;then Read the record from the internal table passing the appropriate key.&lt;/P&gt;&lt;P&gt;Hope this will work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:27:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383856#M187059</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383857#M187060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I appreciate all your prompt responses. I wanted to get in a single select hit for a range of keyfields. If it was one, then I wouldn't have a problem. But anyway&lt;/P&gt;&lt;P&gt;I have &lt;/P&gt;&lt;P&gt;       select f1 max( f2 ) as f2&lt;/P&gt;&lt;P&gt;              from &amp;lt;table&amp;gt;&lt;/P&gt;&lt;P&gt;              into corresponding fields of &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;              where f1 in r_f1&lt;/P&gt;&lt;P&gt;              group by f1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works perfect. Rewarded points.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Anu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:39:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383857#M187060</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with sql stmt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383858#M187061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Small correction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select f1 max( &amp;lt;b&amp;gt;Distinct&amp;lt;/b&amp;gt; f2 ) as f2&lt;/P&gt;&lt;P&gt;from &amp;lt;table&amp;gt;&lt;/P&gt;&lt;P&gt;into corresponding fields of &amp;lt;itab&amp;gt;&lt;/P&gt;&lt;P&gt;where f1 in r_f1&lt;/P&gt;&lt;P&gt;group by f1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Anu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2006 17:41:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/need-help-with-sql-stmt/m-p/1383858#M187061</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-20T17:41:21Z</dc:date>
    </item>
  </channel>
</rss>

