<?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 Using aggregate function in arithmetic expression in CDS view not supported? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-aggregate-function-in-arithmetic-expression-in-cds-view-not-supported/m-p/12209883#M1982698</link>
    <description>&lt;P&gt;I am trying to use an aggregate function in an arithmetic expression in a CDS view, but it says that the expression is not supported at this point. Is this a limitation in CDS? It seems like this should work.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;define view ZTMP_PO_ITEM as select from ekpo as p
left outer join ekko as k
    on p.ebeln = k.ebeln
left outer join lfa1 as l
    on l.lifnr = k.lifnr
left outer join ekbe as b
      on b.ebeln = p.ebeln and b.ebelp = p.ebelp and b.vgabe = '1'    
{
    p.ebeln as ebeln,
    p.ebelp as ebelp,
    p.matnr as matnr,
    p.txz01 as txz01,
    p.werks as werks,
    p.lgort as lgort,
    p.menge as menge,
    p.meins as meins,
    p.netpr as netpr,
    p.netwr as netwr,
    k.waers as waers,
    k.lifnr as lifnr,
    l.name1 as name1,
    sum(b.menge) as lmeng,
    p.menge - sum(b.menge) as umeng
}
group by p.ebeln, p.ebelp, p.matnr, p.txz01, p.werks, p.lgort, p.menge, p.meins, p.netpr, p.netwr, k.waers, k.lifnr, l.name1
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1790491-eclipse-cy7emjei9p.png" /&gt;&lt;/P&gt;
  &lt;P&gt;Turning this into a native SELECT and passing it to the database works:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;SELECT 
    P.EBELN AS EBELN,
    P.EBELP AS EBELP,
    P.MATNR AS MATNR,
    P.TXZ01 AS TXZ01,
    P.WERKS AS WERKS,
    P.LGORT AS LGORT,
    P.MENGE AS MENGE,
    P.MEINS AS MEINS,
    P.NETPR AS NETPR,
    P.NETWR AS NETWR,
    K.WAERS AS WAERS,
    K.LIFNR AS LIFNR,
    L.NAME1 AS NAME1,
    SUM(B.MENGE) AS LMENG,
    P.MENGE - SUM(B.MENGE) AS UMENG
FROM EKPO AS P
LEFT OUTER JOIN EKKO AS K
    ON P.EBELN = K.EBELN
LEFT OUTER JOIN LFA1 AS L
    ON L.LIFNR = K.LIFNR
LEFT OUTER JOIN EKBE AS B
      ON B.EBELN = P.EBELN AND B.EBELP = P.EBELP AND B.VGABE = '1'    


GROUP BY P.EBELN, P.EBELP, P.MATNR, P.TXZ01, P.WERKS, P.LGORT, P.MENGE, P.MEINS, P.NETPR, P.NETWR, K.WAERS, K.LIFNR, L.NAME1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 13 Mar 2020 07:36:38 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2020-03-13T07:36:38Z</dc:date>
    <item>
      <title>Using aggregate function in arithmetic expression in CDS view not supported?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-aggregate-function-in-arithmetic-expression-in-cds-view-not-supported/m-p/12209883#M1982698</link>
      <description>&lt;P&gt;I am trying to use an aggregate function in an arithmetic expression in a CDS view, but it says that the expression is not supported at this point. Is this a limitation in CDS? It seems like this should work.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;define view ZTMP_PO_ITEM as select from ekpo as p
left outer join ekko as k
    on p.ebeln = k.ebeln
left outer join lfa1 as l
    on l.lifnr = k.lifnr
left outer join ekbe as b
      on b.ebeln = p.ebeln and b.ebelp = p.ebelp and b.vgabe = '1'    
{
    p.ebeln as ebeln,
    p.ebelp as ebelp,
    p.matnr as matnr,
    p.txz01 as txz01,
    p.werks as werks,
    p.lgort as lgort,
    p.menge as menge,
    p.meins as meins,
    p.netpr as netpr,
    p.netwr as netwr,
    k.waers as waers,
    k.lifnr as lifnr,
    l.name1 as name1,
    sum(b.menge) as lmeng,
    p.menge - sum(b.menge) as umeng
}
group by p.ebeln, p.ebelp, p.matnr, p.txz01, p.werks, p.lgort, p.menge, p.meins, p.netpr, p.netwr, k.waers, k.lifnr, l.name1
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1790491-eclipse-cy7emjei9p.png" /&gt;&lt;/P&gt;
  &lt;P&gt;Turning this into a native SELECT and passing it to the database works:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;SELECT 
    P.EBELN AS EBELN,
    P.EBELP AS EBELP,
    P.MATNR AS MATNR,
    P.TXZ01 AS TXZ01,
    P.WERKS AS WERKS,
    P.LGORT AS LGORT,
    P.MENGE AS MENGE,
    P.MEINS AS MEINS,
    P.NETPR AS NETPR,
    P.NETWR AS NETWR,
    K.WAERS AS WAERS,
    K.LIFNR AS LIFNR,
    L.NAME1 AS NAME1,
    SUM(B.MENGE) AS LMENG,
    P.MENGE - SUM(B.MENGE) AS UMENG
FROM EKPO AS P
LEFT OUTER JOIN EKKO AS K
    ON P.EBELN = K.EBELN
LEFT OUTER JOIN LFA1 AS L
    ON L.LIFNR = K.LIFNR
LEFT OUTER JOIN EKBE AS B
      ON B.EBELN = P.EBELN AND B.EBELP = P.EBELP AND B.VGABE = '1'    


GROUP BY P.EBELN, P.EBELP, P.MATNR, P.TXZ01, P.WERKS, P.LGORT, P.MENGE, P.MEINS, P.NETPR, P.NETWR, K.WAERS, K.LIFNR, L.NAME1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Mar 2020 07:36:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-aggregate-function-in-arithmetic-expression-in-cds-view-not-supported/m-p/12209883#M1982698</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-03-13T07:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using aggregate function in arithmetic expression in CDS view not supported?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-aggregate-function-in-arithmetic-expression-in-cds-view-not-supported/m-p/12209884#M1982699</link>
      <description>&lt;P&gt;I think the limitations is the difference wich uses an aggregate as input (umeng). &lt;/P&gt;&lt;P&gt;You could stack another view on top that calculates that difference. &lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 18:05:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-aggregate-function-in-arithmetic-expression-in-cds-view-not-supported/m-p/12209884#M1982699</guid>
      <dc:creator>BiberM</dc:creator>
      <dc:date>2020-03-13T18:05:33Z</dc:date>
    </item>
  </channel>
</rss>

