In this blog, we will cover some use cases and OData exposure of CDS Views created with Key column. You can find our other blogs on CDS here.

Code Push Down in ABAP applications is enabled by CDS Views, which are an extension of the ABAP Dictionary. ABAP CDS provides a framework for defining and consuming semantically rich data models on the central database of the application server, AS ABAP. ABAP Dictionary manages the Data Definition Language (DDL) and the Data Control Language (DCL) based on which the data models are defined. CDS Views can be created with or without a key column. Let’s look at some use cases for views created with a key column.

Use Cases for Creating View with Key

There are various scenarios where a view needs to be created with Key columns.

1. Master Data

Aggregating the results across multiple dimensions requires an Analytical Model. A basic view is created on the Master data from the DDIC Tables/Views. As it is fetching the data from database table there should be no data redundancies as the view is created with the Key Column specified.

@ObjectModel.dataCategory: #DIMENSION is the annotation that is used to represent the Master data.

2. Foreign Key Association

Relationships between entities are defined by Associations. The Source and Target entities relate to each other with the help of the Foreign Key. The Primary Key of the Source entity (Representative Key) acts as the Foreign Key for the Target entity.

3. Value Help

Value Help provides the possible correct values of an input field to the user. This Value Help can be established with the Foreign Key Association in CDS.

4. Hierarchy

Hierarchy in CDS can be created on the view with dataCategoryas DIMENSION. The ‘Key’ field is mandatory for specifying the Hierarchy.

OData Exposure of View with Key

OData (Open Data Protocol) is the best way of consuming RESTful APIs. ABAP CDS view can be exposed as OData Service in different ways. In our scenario, OData Exposure is done using the Annotation @OData.publish: true.

CDS views can be exposed as OData regardless of whether a key column is present in the view or not. In this blog, we will cover the different methods of accessing the exposed data for a CDS view with a key column.

  1. Accessing the entire data using the Navigation Property, and
  2. Accessing Individual Records

Creating the CDS View with Key Column and its OData Exposure

For this Illustration, the CDS view is created by consuming BSEG Table with three input parameters. The Key is set and OData service is enabled.


Input Parameters : P_CurDate , P_ACC, P_Cur

CDS Views with Key Column

OData is generated and the metadata contains two EntityTypes that are created, one for the Key and Parameters and the other EntityTypefor the other columns.


CDS Views with Key Column

The first EntityTypecreated contains the Key column BELNR and the three Input Parameters.

CDS Views with Key Column

Accessing the Exposed Data

As seen in the image below, Setis the Name of the NavigationProperty for the CDS View.

CDS Views with Key Column

Hence the entire dataset can be accessed using the OData Service given below


Accessing individual records

Individual records can be accessed by passing values for the Input Parameters & the Key as shown below:

CDS Views with Key Column


CDS Views with Key Column

We have now seen two distinct methods of accessing data exposed through OData when the view contains a Key column.

Learn more about Visual BI’s SAP HANA offerings here.

Corporate HQ:
5920 Windhaven Pkwy, Plano, TX 75093

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

Copyright © Visual BI Solutions Inc.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This!

Share this with your friends and colleagues!