Skip to main content
S/4HANA

How to Create CDS Views Using HANA Studio (Eclipse)

AR Abhishek Rai, Abhishek Kumar Rai is a SAP UI5/FIORI Developer at Mindset Consulting, India 4 min read

In my first blog today, I will take you through the process of creating CDS views using HANA Studio (Eclipse) on S/4 HANA System, step by step. This will be the first in a series of blogs where I will discuss how to consume CDS views in Odata Services and Fiori Apps.

CDS View Overview:

Core Data Services (CDS) views are virtual data models used to define and consume semantic data on standard tables or dictionary views. Although the SE11 dictionary view and CDS views both create database views at the backend, CDS views supersede the dictionary view in many ways like annotations, association, expression, aggregation, grouping, etc.

There are two types of CDS views:

  1. HANA CDS views
  2. ABAP CDS views

Diagram: CDS views feed OData via SAP Gateway on S/4HANA, then HANA Cloud Connector to the SAP Fiori Launchpad

Steps to create a CDS view:

Prerequisite– We are an ADT (ABAP Development Toolkit) in the Eclipse. Therefore, we need an integrated development environment (IDE) for creating ABAP applications on SAP S/4 HANA systems. The ABAP Development Tools provides powerful tools for creating ABAP applications. You can use the below links to install HANA studio.

After a successful installation and integration of HANA Studio, you will need to follow the below steps:

Create an ABAP Project by clicking on File > New > ABAP Project-

  • In the pop-up screen, choose your SAP system from the list. I will be going with the selected screen below S/4 HANA2020).

Eclipse New ABAP Project dialog, System Connection step, with S/4 HANA2020 listed

  • Click ‘Next’-

New ABAP Project Connection Settings dialog with System ID S4H and server details redacted

  • Again, click ‘Next’-

New ABAP Project Logon to System dialog with client, user ARAI, password and language EN fields

  • Enter your credentials and click ‘Finish’-

Eclipse Project Explorer showing the new ABAP project S4H_100_arai_en_1 highlighted

  • We can now see, that a project is created with my user ID.

Creating a CDS View within the above project-

  • To create a CDS view, right-click on the newly created package($TMP) -> New -> Other ABAP Repository Object -> Search for Data Definition -> Click on “Next”.

New ABAP Repository Object dialog with Data Definition highlighted under Core Data Services

Fill “Name” and “Description” of the CDS view ->. Click on “Next.”

New Data Definition dialog in package $TMP, name ZXC_CUST_SD, description Customer Sales Data

  • We are creating our Local Package only. So, we are not going to assign our Object to any TRs (Transport Requests) -> Click on “Next.”

After clicking next, you will need to go through “validating package.” This validation process can take up to a few seconds to complete.

Select Transport Request step showing no change recording enabled for package $TMP

  • Select “Define View” -> After that ->Click on “Finish”.

Data definition templates list with Define View selected and its template code shown

  • As is evident from the screen below, our new CDS view is created.

Eclipse editor showing the new ZXC_CUST_SD CDS view with an empty sqlViewName

  • Firstly, let’s modify the “sql_view_name” name and redefine a specific term (ZX_VW_CUST_SD) for our development, and we will fetch data from table ‘KNVV’ (Customer Master sales data).
  • Go to the coding area and hit  “CTRL + SPACEBAR” (suggestion) -> Here, we get “Insert all elements- template” and a range of fields. We need to select the fields as per our requirements. In this instance, we have chosen the fields, as is evident from the screen below.

ZXC_CUST_SD CDS view code with sqlViewName ZX_VW_CUST_SD selecting key and other fields from KNVV

  • Save( CTRL + S)  the changes and activate(CTRL + F3 ) the CDS view.
  • Let us create another similar CDS view for “Customer Details” -> Right click on the “Local Object ($TMP)” -> Other ABAP Repository Object -> Search for “Data Definition” -> Click on “Next”.

New ABAP Repository Object dialog with Data Definition highlighted, opened for a second CDS view

  • Provide the CDS view “Name” and “Description” -> Click on “Finish.”

New Data Definition dialog with name ZXC_CUSTOMER and description Customer Master Details

  • Click on ‘Define View with Association’ and then click on ‘Finish.’

Data definition templates list with Define View with Association selected and its template code

  • Redefine the ‘sql_View_name’ as ‘ZX_VW_CUST’ and use the table  ‘KNA1’ table to fetch data in this CDS view. Now, join this CDS view with the previous CDS view (ZX_VW_CUST_SD) using association as shown in the screen below;

ZXC_CUSTOMER CDS view code selecting from KNA1 with an association to ZXC_CUST_SD as _CUSTSD

  • Save( CTRL + S)  the changes and activate(CTRL + F3 ) the CDS view.
  • Right click on the CDS view (ZXC_CUSTOMER) -> Open With -> Data Preview.

Data Preview of ZXC_CUSTOMER showing 100 customer rows with columns like Kunnr, Land1 and Name1

Finally, we can now see the data of both the CDS views we created by using HANA Studio (Eclipse)! Since, by now, you probably understand that these views are not just single items but are combinations of Data Domain Models running on the Database level and SQL views created with the same domain model at a single application level. I hope this blog helps you to create an essential CDS view and associate one CD view with another. Happy learning!

To view our resources page with similar content, click here. 

Share