<?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: Problem with SQL Group by and having in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367796#M8077</link>
    <description>&lt;P&gt;I am afraid where and Having in the same statement is not possible ( ? ) &lt;/P&gt;&lt;P&gt;When theres a Group by there can only follow a "having" and never a "where" ( ? )&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2017 10:44:32 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2017-02-10T10:44:32Z</dc:date>
    <item>
      <title>Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367794#M8075</link>
      <description>&lt;P&gt;I Have a Problem with the Following SQL Command:&lt;/P&gt;&lt;P&gt;The following SQL-Command throws a Runtime-Error&lt;/P&gt;&lt;P&gt;"The expression that contains MSPR~PSPNR is not a GROUP-BY expression."!&lt;/P&gt;&lt;P&gt;The Problem is, wehn I put PSPNR into the Group-by Expression, I dont get the sum I needed. I want the sum of prlab obber all PSRNR group by watnr, werks, lgort, charg.&lt;/P&gt;&lt;P&gt;What am I doing wrong? Or is this kind of statement not possible in ABAP?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    SELECT DISTINCT mspr~matnr AS matnr , mspr~werks AS werks,
                    mspr~lgort AS lgort,  mspr~charg AS charg,
             SUM( mspr~prlab ) AS prlab",
      INTO TABLE @et_avail_proj_stock
        FROM mspr
      GROUP BY matnr, werks, lgort, charg

      HAVING mspr~pspnr IN ( SELECT  pspnr 
                              FROM  prps
                              WHERE psphi  = ( SELECT psphi
                                                FROM  prps
                                                WHERE pspnr = @iv_wbs_element ) )
      AND  mspr~sobkz  = @zif_pp_po=&amp;gt;mc_special_stock_project
      AND  prlab       &amp;lt;&amp;gt; @lv_initial_prlab.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:21:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367794#M8075</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-02-10T10:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367795#M8076</link>
      <description>&lt;P&gt;The &lt;A href="http://help.sap.com/abapdocu_751/en/abaphaving_clause.htm"&gt;HAVING clause&lt;/A&gt; apply to the aggregated or group fields, so move other fields in a &lt;A href="http://help.sap.com/abapdocu_751/en/abapwhere.htm"&gt;WHERE clause&lt;/A&gt;. Only aggregated field PRLAB  should be in the HAVING clause?&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Raymond&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:37:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367795#M8076</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2017-02-10T10:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367796#M8077</link>
      <description>&lt;P&gt;I am afraid where and Having in the same statement is not possible ( ? ) &lt;/P&gt;&lt;P&gt;When theres a Group by there can only follow a "having" and never a "where" ( ? )&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:44:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367796#M8077</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-02-10T10:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367797#M8078</link>
      <description>&lt;P&gt;&lt;A href="http://help.sap.com/abapdocu_751/en/index.htm?file=abaphaving_clause.htm"&gt;"If no GROUP BY grouping is applied to columns specified after HAVING outside of aggregate functions, a syntax error occurs in the strict modes of the syntax check from Release 7.40, SP08. Outside of these strict modes, a syntax check warning is produced and a non-catchable exception is raised. The same applies to columns specified directly in the  SELECT list when a HAVING clause is specified, but that are not specified after GROUP BY. "&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:48:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367797#M8078</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2017-02-10T10:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367798#M8079</link>
      <description>&lt;P&gt;No, that's not the case.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:49:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367798#M8079</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2017-02-10T10:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367799#M8080</link>
      <description>&lt;P&gt;I have got it !&lt;/P&gt;&lt;P&gt;You have helped me indeed.&lt;/P&gt;&lt;P&gt;This is the correct statement:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; SELECT mspr~matnr AS matnr, mspr~werks AS werks,
           mspr~lgort AS lgort, mspr~charg AS charg,
           SUM( mspr~prlab ) AS prlab
      INTO TABLE @et_avail_proj_stock
        FROM mspr
      WHERE mspr~pspnr IN ( SELECT  pspnr " ALL WBS Elements of the Project
                              FROM  prps
                              WHERE psphi  = ( SELECT psphi         
                                                FROM  prps
                                                WHERE pspnr = @iv_wbs_element ) )
      AND  mspr~sobkz  = @zif_pp_po=&amp;gt;mc_special_stock_project
      AND  prlab       &amp;lt;&amp;gt; @lv_initial_prlab
      GROUP BY matnr, werks, lgort, charg.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:53:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367799#M8080</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-02-10T10:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with SQL Group by and having</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367800#M8081</link>
      <description>&lt;P&gt;This give the correct result, actually the checked prlab is mspr~prlab for each record before aggregation, and correct only because mspr~prlab (some stock qty) is always positive, IMHO you could have written:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT mspr~matnr AS matnr, mspr~werks AS werks,
           mspr~lgort AS lgort, mspr~charg AS charg,
           SUM( mspr~prlab ) AS prlab
      INTO TABLE @et_avail_proj_stock
        FROM mspr
      WHERE mspr~pspnr IN ( SELECT  pspnr " ALL WBS Elements of the Project
                              FROM  prps
                              WHERE psphi  = ( SELECT psphi         
                                                FROM  prps
                                                WHERE pspnr = @iv_wbs_element ) )
      AND  mspr~sobkz  = @zif_pp_po=&amp;gt;mc_special_stock_project
      GROUP BY matnr, werks, lgort, charg
      HAVING  prlab &amp;lt;&amp;gt; @lv_initial_prlab.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;BR /&gt;Raymond&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 14:52:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-sql-group-by-and-having/m-p/367800#M8081</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2017-02-13T14:52:49Z</dc:date>
    </item>
  </channel>
</rss>

