<?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: Select with aggregate expression SUM in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894033#M1143249</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Resulting set for inner join &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line &lt;STRONG&gt;on the right-hand side. The content of the column on the left-hand side may be duplicated in this case.&lt;/STRONG&gt; If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Dec 2008 13:47:22 GMT</pubDate>
    <dc:creator>rainer_hbenthal</dc:creator>
    <dc:date>2008-12-16T13:47:22Z</dc:date>
    <item>
      <title>Select with aggregate expression SUM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894031#M1143247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a select with the expression SUM shown below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;SELECT a&lt;SUB&gt;spmon a&lt;/SUB&gt;werks a&lt;SUB&gt;mdv01 a&lt;/SUB&gt;matnr b~prodh&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;    &lt;STRONG&gt;SUM( a~m_pagados )        AS m_pagados&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;        &lt;STRONG&gt;into table lt_zmmfb&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    &lt;STRONG&gt;FROM zmmfb01 AS a INNER JOIN mvke AS b ON a&lt;SUB&gt;matnr = b&lt;/SUB&gt;matnr&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;                      &lt;STRONG&gt;INNER JOIN mara AS c ON a&lt;SUB&gt;matnr = c&lt;/SUB&gt;matnr&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;    &lt;STRONG&gt;CLIENT SPECIFIED&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;    &lt;STRONG&gt;WHERE a~mandt = '010'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;      &lt;STRONG&gt;AND a~bukrs = 'COBE'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;      &lt;STRONG&gt;AND a~spmon &amp;gt;= '200601'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;      &lt;STRONG&gt;AND a~mdv01 NOT IN ('LMA', 'LTR')&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;      &lt;STRONG&gt;AND c~mtart = 'ZPAC'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;        &lt;STRONG&gt;GROUP BY a&lt;SUB&gt;spmon a&lt;/SUB&gt;werks a&lt;SUB&gt;mdv01 a&lt;/SUB&gt;matnr b~prodh&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;    &lt;STRONG&gt;ORDER BY a&lt;SUB&gt;spmon a&lt;/SUB&gt;werks.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am currently testing the code with only 3 entries in the custom db table which are below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;MANDT SPMON   BUKRS WERKS MDV01    MATNR                         M_PAGADOS&lt;/STRONG&gt;          &lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;010       200601    COBE    0101      L05         000000000000000032        1,000.00000&lt;/STRONG&gt;          &lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;010       200603    COBE    0104      L05         000000000000002173              2.25000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;  &lt;STRONG&gt;010       200603    COBE    0104      L05         000000000000002193              3.00000&lt;/STRONG&gt;         &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now comes the problem.  When I execute the program my resulting internal table looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SPMON    WERKS   MDV01      MATNR                      PRODH                     M_PAGADOS&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;200601	0101	L05	000000000000000032	 __________________   2000.000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;200601	0101	L05	000000000000000032	 000001001001030032 14000.000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;200603	0104	L05	000000000000002173	 000001001001030031      15.750&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;200603	0104	L05	000000000000002193	 000001001001030031      21.000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;None of the materiales have the Hierarchy code (PRODH) assigned in the table MVKE but for some reason the values above appear (except for the first entry) .  Also if you haven't noticed there are 4 entries ( should only be three) in the table.  What's more it has doubled the first value of M_PAGADOS, the second value is 7x the 1st and the others are both the origional value x7.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any clues anyone?  It's been doing my head in for a while and I have no idea why it's doing this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simon Kerr&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2008 16:40:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894031#M1143247</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-15T16:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Select with aggregate expression SUM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894032#M1143248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;These 3 entries are in your custom table, but what happens when you remove all the sum and group by from your SQL and run it with just the joins?  How many rows are returned then.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If joining to another table causes more than three rows to be returned, you'll multiply your aggregated values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2008 13:12:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894032#M1143248</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-16T13:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select with aggregate expression SUM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894033#M1143249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Resulting set for inner join &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line &lt;STRONG&gt;on the right-hand side. The content of the column on the left-hand side may be duplicated in this case.&lt;/STRONG&gt; If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2008 13:47:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894033#M1143249</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2008-12-16T13:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Select with aggregate expression SUM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894034#M1143250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Simon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The unique key of table mvke contains two more fields except matnr. Probably there are more then one entry for material 000000000000000032.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to include the other fields  ( VKORG, VTWEG) in your select statement as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Kameliya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2008 14:06:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894034#M1143250</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-16T14:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Select with aggregate expression SUM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894035#M1143251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;Probably there are more then one entry for material 000000000000000032.&lt;/P&gt;&lt;P&gt;&amp;gt; Kameliya&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two of them &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2008 14:10:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894035#M1143251</guid>
      <dc:creator>rainer_hbenthal</dc:creator>
      <dc:date>2008-12-16T14:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select with aggregate expression SUM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894036#M1143252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I solved the problem by taking out the CLIENT SPECIFIED statement.  I understood that to do a select using the mandate field you had to use the client specified statement (true for some dbtables) but is seems it is not required here.  I'm not really sure what it was doing but it's solved now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Dec 2008 15:34:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-with-aggregate-expression-sum/m-p/4894036#M1143252</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-16T15:34:44Z</dc:date>
    </item>
  </channel>
</rss>

