Preface – This post is part of the SAP ABAP RAP series.
SAP ABAP CDS View is used for defining and consuming semantic data models on standard tables or dictionary views. The abbreviation for CDS is Core Data Services. Although SE11 dictionary view and CDS views both create database views at the backend, the ABAP CDS view supersedes the dictionary view in so many ways.
Difference between dictionary view and CDS View
|Dictionary View||CDS View|
|Can be created from SAP GUI or Eclipse.||Can only be created from Eclipse or SAP HANA Studio.|
|Cannot define Annotations.||Annotations are provided to enrich metadata.|
|Aggregation is not possible.||Can provide Aggregation function.|
|Grouping is not possible.||Grouping can be provided.|
|Join can be used.||Join and Union both can be used|
|Case Expressions can be used.|
|Input parameters can be allowed for filtering data and column calculations|
|Operators can be used.|
CDS view Types
There are three different VDM view types:
- Basic view
- Composite view
- Consumption view
Figure 1: CDS view types
1. Basic View
VDM Basic views are created on the top of DDIC tables or views. It is the only view that interacts directly with the database.
Annotation: @VDM.Viewtype : #BASIC
Properties for Basic View:
- Basic views can directly access the database tables and other basic views.
- They have an association with other basic views.
- Free of redundancies.
- They expose all business data.
2. Composite view
The composite view is created on top of the VDM Basic view. It interacts with Basic views for the result set and does not interact with the database directly.
Annotation: @VDM.Viewtype : #COMPOSITE
Properties of Composite View:
- They can access other Composite views but not database tables.
- They can have an association with other composite views and basic views.
- Redundancies might be possible.
- They should be reusable.
3. Consumption view
The consumption views are built on top of Interface views. By the name Consumption, we can assume that this view is meant to be consumed by SAP UI5 through OData, Analytical queries, Transactional service models.
Annotation: @VDM.Viewtype : #CONSUMPTION
How to create CDS views in ADT?
To create a CDS view follow the below steps:
- Navigate to New ABAP Repository.
- Select Data Definition.
- Provide Package, Name, Description of CDS view.
- Now from the given options, select Define View.
- Define data source name, SQL view name, required annotations and other properties.
- Define data selection Query.
- Save and activate.
How to view the data from CDS Views?
- In the DDL source object, navigate to your CDS view.
- Right-click and select OPEN DATA PREVIEW. Also, you can open the CDS view and press F8 to view the data.
- The output will show you the retrieved data from CDS View.