CDS View in SAP ABAP – CDS is called as Core Data service, which is nothing but a semantic rich Data model consisting of the following languages

  1. DDL – Data Defination Language
  2. DQL – Data Query Language
  3. DCL – Data Control Language

I hope, you understood these languages during your early graduation days🤪

In general, CDS is nothing but a Dictionary view in ABAP with some additional features.

ABAP View vs CDS view in SAP ABAP
ABAP View VS CDS view

CDS view is one of the core pillars in the “ABAP on HANA” concept of SAP. These are few facts regarding the CDS view

  • CDS view only support Read/Query operation in other term no Update/Delete/Insert operation
  • CDS view is also integrated with ABAP irrespctive of Database
  • CDS view is client dependent by dafult but you change it by using annotation
  • CDS view follows the concept of Code Push Down that means it will push all the calculation to database layer to give you better performance in comparision to SQL Query and Dictionary view

Let’s create a CDS view in the system. In order to create a CDS view, you have to use the Eclipse or HANA studio Tool having ADT plugin installed on your machine. you can not create a CDS view in the SAP GUI application.

Please check out the blog to get installation details – ADT in Eclipse/HANA Studio

Once you are ready with the installation part, Let’s check out step by step to create a CDS view

ADT Tool for CDS view
Steps to add ABAP system/project in ADT (Step 1 to select ABAP Perspective(1) if don’t find the Icon then go to Window-> Perspective -> Open Perspective )
Creating ABAP Project
Click on Next and so on to add system credential details -> Finish
Project explore
Add your favorite package(right-click add package) or use $TMP for creating CDS
Creating CDS view inside package
To create a CDS view choose Other ABAP Repository Object
Data definition
CDS view name and description
Provide the CDS view name and description
CDS view Template
Choose a template, for now – select the default one
Code editor for CDS view

In the above screenshot of the code editor, if you check the statement which begins with @ called annotation, these are special statements/syntax which will enrich the CDS view. We will learn various annotations in due course.

The mandatory annotation for CDS view is sqlViewName , this will create a SE11 view for the corresponding CDS view which helps in transporting the object.

while defining the view, you need to provide the source data(either a database table or CDS view name), in the above example, we took VBAK (Sales order header table). The list of fields goes in the { }

@AbapCatalog.sqlViewName: 'ZCDS_VBAK_V'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS view for VBAK'
define view ZCDS_VBAK as select from vbak {
    key vbeln,
        auart,
        vkorg,
        ernam,
        erdat
}

To activate the CDS view, click on the activate button or Ctrl + F3. To check out the result or data preview press F8 button

Data preview of CDS view
Data Preview

Once the CDS view is activated, a dictionary view will be created with sqlViewName

Dictionary View for CDS view

Point to be noted that CDS view is not directly executed by end-user. So to consume the same in ABAP code, we need to use it as SQL Query. (Note: you can use both CDS view name and SQL View name inside select query but SAP suggest to use CDS view name) like below report program

REPORT ztest_cds_execution.

"Fetch the data from CDS view
SELECT * FROM zcds_vbak
    INTO TABLE @DATA(lt_data)
    WHERE ernam = 'TEMP'.
IF sy-subrc EQ 0.
  cl_demo_output=>display_data(
    EXPORTING
      value = lt_data
      name  = 'CDS view Output'
  ).
ENDIF.

Note: Sorting inside the CDS view is not possible as of now, but while consuming the CDS view inside the Select query you can user ORDER BY statement.

Report output for CDS view

Additionally: There is another way to write the CDS view, as the above CDS view can be written as below as well. The only difference is that if you write fields inside the {…} then you can not use the Select * Operation

@AbapCatalog.sqlViewName: 'ZCDS_VBAK_V'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS view for VBAK'
// Commented statement
//define view ZCDS_VBAK as select from vbak {
//    key vbeln,
//        auart,
//        vkorg,
//        ernam,
//        erdat
// }
define view ZCDS_VBAK as select
    key vbeln,
        auart,
        vkorg,
        ernam,
        erdat
from vbak

Stay tuned for other parts of the CDS view.

Check out our OData series OData – ABAP Skill

Check out ABAP Blogs ABAP – ABAP Skill


1 Comment

What is Join & Association in CDS View SAP ABAP-Part 2 · August 21, 2021 at 7:29 am

[…] CDS view with examples. Hope you have understood the basic of CDS view, if not, please check out the Part 1 in this part, Let’s check out Join in CDS view […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *