abap cds, sap analytics

How to create ABAP CDS view and OData with SAP Annotations

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.

abap cds, sap analytics

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

abap cds, sap analytics

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.

abap cds, sap analytics


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.

@AbapCatalog.sqlViewName: ‘SBS_FLIGHT_SVIEW’
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘sflight table as view’
@OData.publish: true

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,

@DefaultAggregation: #SUM
sflight.paymentsum as TotalBookings

abap cds, sap analytics

Make sure you insert following OData annotation to the CDS view:

@OData.publish: true

Step 2: Activate OData Service in the SAP Gateway Hub

Now you need to activate the OData service in the SAP Gateway hub.

abap cds, sap analytics

Test the Activated OData Service and use $metadata parameter to check metadata and annotation information. The output should looks like below.

abap cds, sap analytics

Leave a Reply

Your email address will not be published.