- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1
 
CDS Views
The Fleet Management System leverages ABAP CDS Views as its semantic data layer.
These views provide calculated fields, compositions, and interface definitions that power RAP business objects and expose data to Fiori/UI services.
| CDS Type | Purpose | 
|---|---|
| Composite CDS View | Adds calculated fields (e.g., total trip cost) on top of base tables | 
| Root Interface View | Entry point for the RAP BO, representing Vehicle as the root entity | 
| Child Interface Views | Provide dependent entities (Trips, Maintenance) associated with Vehicle | 
This view extends the Trip Table with a calculated field total_trip_cost, based on vehicle fuel type and distance traveled.
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Composite (Calc) CDS View : TRIP'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
    serviceQuality: #X,
    sizeCategory: #S,
    dataClass: #MIXED
}
define view entity ZAKS_CMP_CDS_TRIP
  as select from zaks_trip
  association [1] to zaks_vehicle as _Vehicle 
    on $projection.VehicleId = _Vehicle.vehicle_id
{
  key trip_uuid    as TripUUID,
  key trip_id      as TripId,
      vehicle_uuid as VehicleUUID,
      vehicle_id   as VehicleId,
      driver_id    as DriverId,
      origin       as Origin,
      destination  as Destination,
      start_date   as StartDate,
      end_date     as EndDate,
      distance_km  as DistanceKm,
  @Semantics.amount.currencyCode: 'Currency'
  cast(
      distance_km * 
      case _Vehicle.fuel_type
        when 'P' then cast(100 as abap.dec(5,2))
        when 'D' then cast( 90 as abap.dec(5,2))
        when 'C' then cast( 70 as abap.dec(5,2))
        when 'E' then cast( 10 as abap.dec(5,2))
        else cast(  0 as abap.dec(5,2))
      end 
      as abap.curr(15,2)
  ) as total_trip_cost,
  _Vehicle.currency as Currency,
  cargo_type        as CargoType,
  created_by        as CreatedBy,
  created_on        as CreatedOn,
  _Vehicle
}- Calculates trip cost dynamically based on fuel type multipliers.
 - Uses association to vehicle for fetching currency and fuel type.
 - Forms the foundation for interface and consumption views.
 
Defines the root entity in the RAP BO.
Composes Trips and Maintenance entities, enabling a hierarchical structure.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Interface Root View : Vehicle'
@Metadata.ignorePropagatedAnnotations: true
define root view entity ZAKS_I_ROOT_VEHICLE 
  as select from zaks_vehicle
  composition [0..*] of ZAKS_I_CDS_TRIP        as _Trip
  composition [0..*] of ZAKS_I_CDS_MAINTENANCE as _Maintenance
{
  key vehicle_uuid as VehicleUUID,
  key vehicle_id   as VehicleId,
  regd_no          as RegdNo,
  vehicle_type     as VehicleType,
  brand            as Brand,
  model            as Model,
  purchase_date    as PurchaseDate,
  @Semantics.amount.currencyCode: 'Currency'
  cost_price       as CostPrice,
  currency         as Currency,
  fuel_type        as FuelType,
  capacity         as Capacity,
  capacity_unit    as CapacityUnit,
  status           as Status,
  plant            as Plant,
  created_by       as CreatedBy,
  created_on       as CreatedOn,
  _Trip,
  _Maintenance
}Wraps the Composite Trip View (ZAKS_CMP_CDS_TRIP) as a child entity in the RAP BO.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Interface CDS View : Trip'
@Metadata.ignorePropagatedAnnotations: true
define view entity ZAKS_I_CDS_TRIP 
  as select from ZAKS_CMP_CDS_TRIP
  association to parent ZAKS_I_ROOT_VEHICLE as _Vehicle
    on $projection.VehicleId = _Vehicle.VehicleId 
   and $projection.VehicleUUID = _Vehicle.VehicleUUID
{
  key TripUUID,
  key TripId,
  VehicleUUID,
  VehicleId,
  DriverId,
  Origin,
  Destination,
  StartDate,
  EndDate,
  DistanceKm,
  @Semantics.amount.currencyCode: 'Currency'
  total_trip_cost,
  Currency,
  CargoType,
  CreatedBy,
  CreatedOn,
  _Vehicle
}Provides maintenance details as a child entity linked to Vehicle.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Interface CDS View : Maintenance'
@Metadata.ignorePropagatedAnnotations: true
define view entity ZAKS_I_CDS_MAINTENANCE 
  as select from zaks_maintenance
  association to parent ZAKS_I_ROOT_VEHICLE as _Vehicle
    on $projection.VehicleId = _Vehicle.VehicleId 
   and $projection.VehicleUUID = _Vehicle.VehicleUUID
{
  key maint_uuid     as MaintUUID,
  key maint_id       as MaintId,
  vehicle_uuid       as VehicleUUID,
  vehicle_id         as VehicleId,
  service_date       as ServiceDate,
  service_type       as ServiceType,
  workshop_name      as WorkshopName,
  @Semantics.amount.currencyCode: 'Currency'
  service_cost       as ServiceCost,
  currency           as Currency,
  odometer_reading   as OdometerReading,
  parts_changed      as PartsChanged,
  warranty_claim     as WarrantyClaim,
  next_service_date  as NextServiceDate,
  material_number    as MaterialNumber,
  vendor_number      as VendorNumber,
  created_by         as CreatedBy,
  created_on         as CreatedOn,
  _Vehicle
}- Composite Calculation View enriches trip data with 
total_trip_cost. - Root Interface View (Vehicle) acts as the RAP BO entry point.
 - Child Interface Views (Trip & Maintenance) provide hierarchical composition.
 - Currency Semantics annotations ensure consistent representation in Fiori/UI.
 - Associations establish strong relationships between vehicle, trip, and maintenance.
 
The CDS layer in the Fleet Management System provides:
- Calculated insights (trip cost, service cost)
 - Business object hierarchy (Vehicle → Trip & Maintenance)
 - RAP-ready interface views for seamless integration with application services
 
This structured approach enables clean data modeling, extensibility, and direct exposure for Fiori/UI consumption.
👉 Next: 📐 Projection Layer