I explained what Smart Business Service is and how to subscribe and use Smart Business to create analytic content. In this article I will focus on ABAP CDS view and OData.
One of the common use case for Smart Business Service is consuming ABAP CDS view from S/4HANA system and create analytic content.
Importance of SAP Annotations for OData (OData4SAP)
When you implement your CDS view and OData service in ABAP, make sure that your service supports auto aggregation and provides OData4SAP annotations.
In CDS View we can use “@OData.publish: true” to include annotations. With the annotation, we can find multiple information in $metadata. For example,
- if an entity type is an aggregate or not
- If a property is a dimension or measure
- What is the label and other information of a property
Create a CDS View and OData Service with SAP Annotations
Let us see step by step process of creating a CDS view and OData service which provide SAP annotations.
Here we will use SFLIGHT table. SFLIGHT is a standard SAP Table which is used to store Flight information. You can use transaction code SE54 and SE16 to see the table details as below.
You have installed Eclipse IDE and installed ABAP Development Tools in Eclipse IDE.
Step 1: Create a CDS View
Create a CDS view using SFLIGHT table. For detail steps on creating CDS view
Use the below code snippet to create CDS view.
@EndUserText.label: ‘sflight table as view’
define view SBS_SFLIGHT_VIEW
as select from sflight
// KEY Fields
key sflight.carrid as AirlineCode,
key sflight.connid as FlightConnectionNumber,
key sflight.fldate as FlightDate,
sflight.planetype as AircraftType,
sflight.mandt as Client,
sflight.price as Airfare,
sflight.paymentsum as TotalBookings
Make sure you insert following OData annotation to the CDS view:
Step 2: Activate OData Service in the SAP Gateway Hub
Now you need to activate the OData service in the SAP Gateway hub.
Test the Activated OData Service and use $metadata parameter to check metadata and annotation information. The output should looks like below.