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.
Go To New ABAP Package
@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
}