2022 Oct 27 5:50 PM
Hey there!
I wanted to create a CDS-View where the Flight price of /DMO/BOOKING is grouped by Airline and year and month of flight date.
I tried this but it does not work because the group by clause only referrs to FLIGHT_DATE and not the created fields:
@AbapCatalog.sqlViewName: 'ZDOJOTOTALFLP'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Dojo total flight price by airline'
define view zdojo_total_flp as select from /dmo/booking {
key carrier_id as CarrierId,
key substring(flight_date, 1, 4) as FlightYear,
key substring(flight_date, 5, 2) as FlightMonth,
sum(flight_price) as TotalFlightPrice
}
group by
flight_date, carrier_id
GROUP BY only accepts origin Fields of the data source but not the created fields FlightYear and FlightMonth.
Is this requirement possible in CDS-Views?
Thanks
Enno
2022 Oct 27 8:15 PM
AFAIK that's not possible. However as it is almost always the case when dealing with CDS the answer is stacked views. You can split your view in a base view, where you do the string processing and field renaming, and on top another view (Interface-View, Projection-View or Consumption-View or whatever currently the correct name for that is, I lost sight regarding that) where you do the aggregation. That should work.
BR Christian
2022 Oct 27 8:15 PM
AFAIK that's not possible. However as it is almost always the case when dealing with CDS the answer is stacked views. You can split your view in a base view, where you do the string processing and field renaming, and on top another view (Interface-View, Projection-View or Consumption-View or whatever currently the correct name for that is, I lost sight regarding that) where you do the aggregation. That should work.
BR Christian
2022 Oct 27 8:38 PM
Thanks for your answer christian.guenter ! I already thought so... ☹️
2022 Nov 24 8:01 AM
enno.wulff
This is also my best solution.
There are then more CDS View in total, but the structure is clear and the grouping hides nowhere.
It's not the smartest solution, but the easiest to maintain.
2022 Nov 23 5:45 AM
You can prepare a CDS table function and write AMDP code behind it. You can achieve your goal within AMDP.
2022 Nov 23 10:28 AM
Thanks kerem.koseoglu for that hint. I just tried a quick attempt but was not successful. ☹️
I will keep in mind and try later.
2022 Nov 23 10:01 AM
Thanks for your suggestion!
Unfortunately the error is the same:
[...]
GROUP BY
FlightYear, carrier_id
The column FlightYear is unknown.
2022 Nov 23 1:24 PM
Hi,
CDS DDL - CDS View Entity, $projection
In CDS view entities, it is possible to reuse expressions defined in the SELECT list, as in you example above FlightYear and FlightMonth. These elements can be addressed with $projection.
Example: concat($projection.FlightYear, 'x') as reuse
But this works only in the SELECT list and in an association ON-clause. It does not work in GROUP BY.
2022 Nov 23 2:46 PM
Hi Andrea,
Thanks for answering. I am going to read more about that.
2022 Nov 23 2:51 PM
Thanks for this addition, aschlott ! I will also have an eye on it.
2022 Nov 23 3:16 PM
roberto4tisap12 minutes ago
"group by = The fields must be specified using the same names as the fields in the data source. The current CDS view cannot be specified using alternative element names, which are defined with "AS"."
define view zdojo_total_flp as select from /dmo/booking {
key carrier_id as CarrierId,
key flight_date,
cast( substring(flight_date, 1, 4) as abap.int4 ) as FlightYear,
cast( substring(flight_date, 5, 2) as abap.int2 ) as FlightMonth,
sum(flight_price) as TotalFlightPrice
}
group by
flight_date, carrier_id
2023 Aug 09 2:05 PM
Hi,
the problem is basically related to the fact the CDS is missing a proper (standard) time dimension.
With associating a CDS Standard Time Dimension with the view (view zdojo_total_flp) from above
with the flight_date there is no such work arround necessary.
You would than associate the CDS Standard Time Dimension with Your flight_date that is:
- Clean design
- more readable
-Standardized approcach
... and than the group by isnt a problem at all any more.
The lack of a proper CDS Time dimension seems to be more a SAP politcal / marketing thing 🙂
S4 CDS = Operative Reporting: wo. Time Dimension
BW = Tactical- / Strategic- Reporting: with Time Dimension
:)?
Thats why You best implement a basic Version of a Timedimension yourself
to solve at most Your problems for one, which pays the afford easely out:
Easiest and at first nothing more than a table with a generic
Calday, Calmonth, Calyear filled with an ABAP Report for a couple of Calyears.
A more simple simple workarround would be the use of a
CDS system entity SERIES_GENERATE_DATE.
@SAP:
The CDS Standard Time dimension should also be availabe in a variant to to have a / the factoty calandars to analyze on base of factory days....
Best Martin
2023 Aug 14 4:26 PM
2023 Aug 14 5:25 PM
Hi,
to solve this for one and any type of time and date ,
best You associate I_CalendarDate with /dmo/booking
try this:
/dmo/booking-flight_date = I_CalendarDate-CalendarDate
Than You can sun and grou by with whatever type of date or time You want.
Best Martin
2023 Aug 17 7:19 AM
Hi,
try this to get a full hold of any type of time You need:
Real usefull Date or Time CDS as a Calendar- or Time- dimensions: I_CalendarDate
2023 Aug 17 10:16 AM
This is a really odd solution... 😄
But solves my problem for dates until 31.12.2100. thanks!