ABAP CDS Views

Scope

This documentation describes the behavior and step-by-step process of using Core Data Services (CDS) in ABAP development for SAP HANA scenarios. Moreover, it focuses on procedure for creating, editing, testing, and analyzing ABAP CDS entities using the Eclipse-based IDE.

Target Users

ABAP developers / consultants who are involved in creating and defining data models including code push-downs.

Data Definitions

A CDS (Core Data Service) is an ABAP repository object that is created using data definition language (DDL) source code.

Data definitions define CDS entities that can be accessed via ABAP programs and as a source of data in reading ABAP SQL statements.

You can create and define data definitions for the following CDS entities:

CDS View Entities

CDS Projection View

CDS DDIC-Based Views

CDS Table Functions

CDS Hierarchies

CDS Custom Entities  

CDS Abstract Entities

Here we are focusing on CDS View Entities

CDS Views

For understanding CDS views we have to understand CDS – Core Data Service first. We can define CDS as

“It is a foundation that can be used by database modelers to create the persistent data model which the application services expose to UI Clients”.

A CDS view is a CDS entity defined in a CDS data definition that implements a view.

Use

Using CDS views, you can rearrange and rename the table fields according to application-specific needs from the ABAP source code of your implementation.

Defining CDS Views

A CDS view is defined for existing database tables and views, or for other CDS views in the ABAP Dictionary, starting with the DEFINE VIEW … DDL statement. A CDS view represents a projection onto one or several database tables or database views in the ABAP Dictionary.

Example

@AbapCatalog.sqlViewName: MATERIAL

DEFINE VIEW ENTITY material_cds_view AS SELECT FROM mara

JOIN makt

ON mara.matnr = makt.matnr

     {

           mara.matnr,

           makt.maktx,

           makt.maktg

     }

The material_cds_view CDS entity view defines a combined single structure onto the database tables mara and makt by joining both tables. The generated CDS-managed DDIC view (MATERIAL) comprises the material number, material description information.

Accessing CDS Views in ABAP

CDS views used to fetch the desired data selection via ABAP SQL. The following method lists the material’s data that is stored in the mara and makt database tables. As confirmed in the listing below, the CDS entity (in this case: material_cds_view) is used for data selection in the ABAP source code.

Example

CLASS cl_material_access_cds_entity IMPLEMENTATION.

METHOD get_material.

    .

SELECT matnr maktx maktg

FROM material_cds_view

INTO TABLE @DATA(itab_data)

WHERE   .

.

ENDMETHOD.

ENDCLASS.

.

In order to create a CDS View we have to perform following Steps.

1.Go to the WINDOW Open Perspective Other menu

.

.

2.Do Select ABAP option.

.

.

.

.

.

.

.

.

.

.

.

.

.

3.Go to File New ABAP Project

.

.

.

4.Select System that have the database you want to connect and then Click on NEXT.

.

.

.

.

.

.

.

5.The information of the system will show automatically.

.

.

.

.

.

6.Enter the credentials.

.

.

.

.

.

7.The new window will show with the details of Project Explorer.

.

8.In ABAP Development Tool ADT we have to create ABAP Package to manage the same objects in a particular Package. It’s just like a folder in Windows. Use below link

.

Go To New ABAP Package

.

.

.

.

.

.

9.Here we provide Name and Description of the Package.

.

.

.

.

  .

.

.

.

.

10. Click on the Check Box “Add to Favorite packages” and then Click on Next button.

.

.

.

.

.

.

.

.

11.Now in the next step we have to give Software Component, here we give “SAP_ABA” which is ABAP Software component.

.

.

.

.

.

.

.

.

12.For onward process we have to select “Create a new request” and then give appropriate Request Description.

.

.

.

.

.

.

.

.

13. Now the next screen will show that the package has been created.

.

.

.

14.Now Go to New Other ABAP Repository Object.

.

.

.

.

.

.

.

.

.

15. In the search field do write “core” , the below section will show “Core Data Services” option automatically.

.

.

.

.

.

.

.

  .

.

.

.

.

.

16.Now select “Data Definition” and then Next button.

.

.

.

  .

.

.

.

.

.

.

.

.

.

17.Do give the Name and Description of the Data Definition.

.

.

.

18.The next window will show the data definition of new CDS view with default definition structure.

.

.

.

.

19.For example if we want to create a CDS view for our Billing MIS app, we have to give the definition details in the form of SQL Select statement which has database tables ( here vbrk, vbrp) with joining information (primary key column i.e vbeln) and the list of columns we need for our CDS view.

.

@AbapCatalog.sqlViewName: ‘ZDEMO_SALES’

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: ‘Sales Order for All Users’

.

define view ZDEMO_CDS_SalesOrderItem

    as  select distinct from vbrk as bill

      left outer join vbrp as dtl on bill.vbeln = dtl.vbeln       //First detail invoice table Join

         left outer join mara as matr on dtl.matnr = matr.matnr   // Second Material Table Join

                {

                 key bill.vbeln as Invoice_no,             //Key field of Manin Table

                 bill.bukrs      as CompanyID,             //Master Invoice table Column

                 dtl.posnr      as Item_no,                //Detail Invoice table Column

                 dtl.matnr      as material,               //Detail Invoice table Column

                 matr.matkl     as material_group,        //Material Table Column

                 dtl.netwr      as GrossAmount            //Detail Invoice table Column

                 }   

             

.

.

.

.

.

20. Finally, for the testing of our CDS View we have to select “Data Preview” option.

.