Subject: SAP-Fiori-Elements
Core Data Services (CDS) views have become a cornerstone of modern SAP application development, especially when building SAP Fiori Elements apps. CDS views provide a powerful way to define semantic layers on top of database tables, incorporating business logic and metadata annotations that drive UI generation. This article explains how to work effectively with CDS views when developing SAP Fiori Elements applications.
CDS views are SQL-based, reusable data models created at the database layer. They extend the traditional database view concept by embedding rich semantics, annotations, and business logic. CDS views serve as the backend data source for SAP Fiori Elements apps, enabling metadata-driven UI generation.
Use ABAP Development Tools (ADT) in Eclipse or SAP Business Application Studio to create a CDS view. For example:
@AbapCatalog.sqlViewName: 'ZFLIGHTLIST'
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Flight List for SAP Fiori Elements'
define view Z_FlightList as select from sflight {
key carrid,
key connid,
fldate,
price,
currency,
seatsmax,
seatsocc
}
Enhance the CDS view with Fiori Elements-specific annotations to control UI behavior:
@UI.lineItem – Defines columns shown in lists@UI.selectionField – Marks fields as filter criteria@UI.identification – Identifies fields shown on object pages@UI.hidden – Hides fields from UIExample with annotations:
@UI.lineItem: [{ position: 10 }, { position: 20 }]
@UI.selectionField: [{ position: 10 }, { position: 20 }]
@UI.identification: [{ position: 10 }]
define view Z_FlightList as select from sflight {
@UI.lineItem: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
key carrid,
@UI.lineItem: [{ position: 20 }]
@UI.selectionField: [{ position: 20 }]
key connid,
@UI.lineItem: [{ position: 30 }]
fldate,
price,
currency,
seatsmax,
seatsocc
}
Use associations to link related entities. This enables navigation and drill-down capabilities in SAP Fiori Elements apps.
association [0..*] to Z_Airport as _DepartureAirport on $projection.departure = _DepartureAirport.airportCode;
Publish the CDS view as an OData service by creating a Service Definition and Service Binding in the SAP Gateway. This step exposes the annotated CDS view to SAP Fiori Elements.
Using SAP Business Application Studio or SAP Web IDE, create a Fiori Elements app (e.g., List Report or Object Page) pointing to the published OData service. The annotations embedded in the CDS view will dictate UI elements and behavior.
CDS views are essential for building SAP Fiori Elements applications that are scalable, performant, and easy to maintain. By embedding UI annotations and exposing CDS views via OData services, developers can harness the power of metadata-driven UI generation, greatly simplifying the app development process. Mastery of CDS views is a key skill for delivering high-quality SAP Fiori Elements applications aligned with SAP’s UX design standards.