Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Aggregation on CDS with Virtual Element

wilbertsison
Active Participant
0 Likes
6,625

A simple CDS view with a virtual element is created like below in S4 1809. I'm trying to use this as a basis for a consumption view for a ListReport.

I noticed that the Aggregation annotation on the Quantity field does not work with this. ADT comes up with an error "Calculated view not allowed in analytical ... ".

Creating the @Aggregation at a higher level consumption CDS gets a similar error.

Am I missing the intention of virtual elements? Why are they not allowed in consumption views that allow aggregation?

@AbapCatalog.sqlViewName: 'YWSSALESORDITEM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order Item'
@OData.publish: true
@VDM.viewType: #BASIC
define view YWS_SalesOrderItem
  as select from vbap
{


  key vbeln                       as SalesOrder,
  key posnr                       as SalesOrderItem,
      @Semantics.unitOfMeasure
      vrkme                       as Unit,
//      @Aggregation.default: #SUM
      @Semantics.quantity.unitOfMeasure: 'Unit'
      kwmeng                      as Quantity,
      matnr                       as Material,
      arktx                       as MaterialDescription,
      @Aggregation.default: #NONE
      @ObjectModel.readOnly: true
      @ObjectModel.virtualElement:true
      @ObjectModel.virtualElementCalculatedBy:    'ABAP:YCL_WS_SALESORD_ITEM_VIRTUAL'
      cast( '' as abap.char(45) ) as Status
}


1 ACCEPTED SOLUTION
Read only

maheshpalavalli
Active Contributor
0 Likes
5,673

It seems that they cannot be used together, check the documentation below:

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.52.5/en-US/4b5e56ec6f28453f81ac370bd9...

-Mahesh

It seems that they cannot be used together, check the documentation below:

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.52.5/en-US/4b5e56ec6f28453f81ac370bd9...

-Mahesh

7 REPLIES 7
Read only

maheshpalavalli
Active Contributor
0 Likes
5,674

It seems that they cannot be used together, check the documentation below:

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.52.5/en-US/4b5e56ec6f28453f81ac370bd9...

-Mahesh

Read only

5,673

When it said "Calculated fields cannot be used together with the grouping or the aggregation function.' I kinda understand why that's the case when code tries to apply aggregation on the calculated field. But in the example above, the calculated view is "Status", the Aggregation field is Quantity. It sounds like it cannot be used together at all in the same CDS hierarchy.

That kinda limits the utility of the virtual element in reporting.

Read only

0 Likes
5,673
wilbert.sison2, agree, it could have been done better, I've even debugged and checked it, they are checkcing if the whole cds view is analytical and then they raise error if it has any virtual elements.
Read only

AbhijeetK
Active Participant
0 Likes
5,673

Hi Wilbert,

I also worked on similar kind of requirement and get to know that we cant use analytical annotations while using virtual element(even in 1909).

Regards

Abhijeet kankani

Read only

0 Likes
5,673

Hi Abhijeet,

What solution you applied then ? I have same requirement where need to ready long text in CDS with aggregation to generate Odata to consume it in Analytical KPI reports

Read only

AbhijeetK
Active Participant
0 Likes
5,673

kamakshij As we cant use both concept together, for our case there was no KPI based on long text so we just created new CDS view for long text and associate it to parent cds view and exposed in parent CDS. So using navigation one can retrieve the long text.

Hope it will help.

Read only

szelbi
Participant
0 Likes
5,456

Were you able to solve this problem somehow? I have a case where a value of a field can be retrieved only using ABAP and I need to use this CDS in KPI. I've checked the solution that suggests associations. The field is displayed in the result CDS but it's empty - class is not called at all.