S4 CDS Views and Enhancements

How to Create CDS View in SAP HANA Studio

ABAP programmers create SQL DDL source and activate to create CDS views in SAP HANA Studio running on Eclipse known as Core Data Services view. SAP HANA database provides great performance boosts for transactional and analytics processes on ERP systems. CDS views, user defined functions, stored procedures are created on HANA database using SAP ADT tools including SAP HANA Studio. ABAP developers can not create CDS view or change DDL sources of SAP HANA repository objects using SE11 transaction.

What does DDL stands for?

In database terminology, DDL stands for Data Definition Language which differs from DML, Data Manipulation Language.

As you can guess, SQL DDL or SQL Data Definition Language commands enables developers and database administrators to manage metadata operations like creating database objects including tables, views, function, stored procedures, etc. Using an appropriate SQL DDL command database professionals can alter existing database objects or delete them ,too.

Backup or restore operations, and many other SQL commands related with database tasks rather then tasks with manipulating data are SQL DDL statements.

On the other hand, DDL commands are directly related with data itself. The transactions taking place on a database table, like inserting a new row, or updating data in a table, deleting data from table, MERGE commands are Data Manipulation Language commands, aka DML statements.

SQL Server developers use Transact-SQL, Oracle developers use PL/SQL for DDL and DML tasks.
Now with SAP HANA, ABAP programmers can create DDL objects like SQL Views, Stored Procedures, User-Defined Functions (skalar functions or table valued functions) on database level.
To create database objects on SAP HANA database, ABAP developers will use SQL DDL afterwards.

What does CDS stands for?

CDS stands for Core Data Services in SAP HANA database terminology.
CDS documents are design-time source code files showing the definition and SQL DDL source of the database objects SAP HANA developers want to create.
When an ABAP programmer creates a CDS document, a SQL DDL source file with .hdbdd file extension.

When the SAP HANA developer activates CDS file (Core Data Services) a corresponding runtime object (a database catalog object) is created in the current database schema.

Create CDS View in SAP HANA Studio

First of all, launch SAP HANA Studio

CDS views are different than database views
In SE80 Object Navigator SAP transaction, ABAP programmers can create database view or using SE11 tcode classic views can be edited in ABAP Workbench tool.
On the other hand, to create a DDL source like creating a CDS view, SAP HANA Studio is the required IDE for developers.

After SAP HANA Studio started, you can connect to target SAP system where you want to create the CDS view.
Add the ABAP Package into the Project Explorer window of the Eclipse integrated development environment.
I want to create a local ABAP dictionary object, so I’m going to add the new CDS view into my local package.

As you can see in below SAP Hana Studio ABAP perpective screenshot, I’ve already imported local package $TMP into the project.

Right click on the package. Follow context menu selections: New > Other ABAP Repository Object
 

Choose DDL Source under Dictionary objects node. Then click Next for following screen in the wizard. We will create a Data Definition  document using this selection.
 

Enter the view name and a description for your new DDL SQL view.
Click Next if you want to transfer this ABAP dictionary to an other system with a transport request.
 

As expected since I’m creating my first CDS view in local ABAP package, $TMP no change recording is enabled for package $TMP.
If I was creating an object to distribute to other SAP systems like productive systems, I will be choosing an existing transport request number or create a new transport request here.
Click Next.
 

Last screen in the wizard enables ABAP programmers to choose a template to create DDL SQL View easily. There are a few numbers of templates with short explanations and code samples. Then Click on finish.
 

After you select your SAP HANA SQL DDL source template, click Finish button.
In Eclipse on a new window the starting source codes for the DDL SQL view is displayed.
 

You see the DDL source is listed among local package objects under node:
$TMP > Dictionary > ABAP DDL Sources nodes.

Until we activate the DDL Source document After we activate ABAP DDL source, corresponding DDL SQL view will be shown under Views node.

Note: It is important to notice that the DDL Source name of the view definition is “ZODATA_DEMO_PARAMS”.
We define the DDL Source name right after “define view” statement.

On the other hand, the CDS view name which will be generated as an ABAP repository object is different.
ABAP programmers define the CDS View name visible on SE11 transaction is set at the first line of the template.
@AbapCatalog.sqlViewName is used to define the SAP CDS View name.

Please use different names for DDL Source name and CDS View name in the code.
Otherwise, during activation ABAP programmers will get an exception preventing the CDS view creation and which is not very informative.

Note: I have named the CDS view as “ZODATA_DEMO_PARAMS” which is different than the DDL Source name ”ZV_ODATA_DEMO_P”.

  1. Add @AccessControl.authorizationCheck: #NOT_REQUIRED (line3)
  2. Add the annotation @OData.publish: true above the DEFINE VIEW statement (line5).

After adding the annotation to CDS View save and activate the view.
 

Now the view has generated objects but the service “ZODATA_DEMO_PARAMS_CDS “ is not active.

To active the CDS view log on to the back end system and use the transaction code – /n/IWFND/MAINT_SERVICE.

Enter the System Alias here it is “LOCAL_PGM” and Technical Service Name ”ZODATA_DEMO_PARAMS_CDS” .

Then click on Get Services.
 

Select the Service display below and click on ‘Add Selected Services’.
 
 

In the next window, At Creation Information give the Package Assignment “$TMP” and click on continue.
 

Hence the Service “ZODATA_DEMO_PARAMS_CDS” as been created.
 

To display CDS view data, right click on CDS View name, and choose Open Data Preview in context menu.
 

Enter the P_CARRID:
 

Here is sample data for CDS view displayed in Data Preview tool in SAP HANA Studio.

Need additional assistance? Contact us today!