In the previous article on SAP HANA, we studied the fundamentals of SAP HANA. Since SAP HANA is in great demand, every professional must adopt this database in order to take advantage of market demands.
With my second blog series, I am trying to put together the most crucial term, called the CDS Views, followed by some examples to get a clear picture of the CDS (Core Data Services) concept.
With my second blog series, I am trying to put together the most crucial term, called the CDS Views, followed by some examples to get a clear picture of the CDS (Core Data Services) concept.
Prerequisite: SAP ABAP basics
From this blog, you'll learn:
- What is CDS in SAP HANA
- How to create a basic CDS View
- Define SAP CDS view with join
- Define Association in SAP CDS View
- Define SAP CDS view with parameters
- Extending CDS view
So let's dive deep into Core Data Services (CDS).
Coming to a very basic question, what is a view?
- A view is a virtual table, which does not have any physical existence
- It is created by combining the data of one or more tables
- A view does not occupy any storage space
Core Data Service (CDS) is an enhancement of SE11 views, having extra features.
CDS views ensure code to data approach or code push down approach. It is a reusable tool that ABAP developers can utilize according to the requirement.
NOTE: We can create CDS views in SAP HANA studio or in eclipse only.
Creating a basic CDS view
When a CDS view is created, by default 2 actions take place.
- DDIC SQL view - This can be seen in the SE11 t-code.
- HANA view - This gets created in HANA DB.
So now let's start creating our first CDS view from scratch.
When you open your eclipse, navigate towards the right side of the screen. You will get the icon of an open perspective. Click on the icon and select the option called 'ABAP'.
Further, in the context menu of your package choose New and then choose Other ABAP Repository Object.
NOTE: If you are unable to find your package, you need to navigate to SAP LOGON and create a new package under SE80.
Next, select Core Data Service->Data Definition and choose Next. Enter the CDS name and give an appropriate description. Select Next.

Select the transport request which you must have made earlier.
NOTE: In case you don't find your own transport request, select 'Create a new request' radio button and click on Next.
You will get a list of all CDS templates. Since this a basic one, we will select the Define view.
Here, I have created a basic CDS view of the table KNA1 (Customer master).
Make sure that the DDIC SQL name and CDS View name are different. From the below example,
ZRDS_CUSTOM view will be created in SE11. Further, complete the select query be entering the fields of the 'KNA1' table.
Now activate the CDS view (Ctrl+ F3). Check your output by clicking on Run as an icon (F8).
Define CDS view with join
In the last section, we created a basic CDS view. In the same way, we will create a CDS view that uses join to display data from multiple tables.
Enter the CDS name and give an appropriate description. Select Next.
Select the transport request which you made earlier and proceed by clicking Next. Select the option as define view with join this time.
The following template will appear.
We can use different types of join within the CDS view.
- Inner join
- Left outer join
- Right outer join
Here, I am using KNA1 (customer master) and KNVV (customer master sales) tables to perform the inner join. Below is the code where I have done inner join on field kunnr.
NOTE: Here is the shortcut to get fields automatic in the select query. Ctrl+space to get the list of fields of the particular table (here KNA1 and KNVV) and shift+enter to select the particular field from the list.
In the above example, ZRDS_CDSJOIN is a DDIC SQL view that will be created in SE11.
The blue part in the above code are the annotations that I will cover in further posts.
NOTE: You can check the ZRDS_CDSJOIN view by going to SE11.
Check the output.
In the above example, ZRDS_CDSJOIN is a DDIC SQL view that will be created in SE11.
The blue part in the above code are the annotations that I will cover in further posts.
NOTE: You can check the ZRDS_CDSJOIN view by going to SE11.
Check the output.
Define CDS view with association
CDS view with association came into the picture since there was a drawback with joins. Let's look at an example. If you have created a CDS view with joins on 3 different tables, then this join condition gets triggered whenever the CDS view gets called. Here arises the problem. Even if the end-user wants to see the data only for 2 tables, he has to by default see the output for the entire 3 tables. By using joins, the performance gets delayed since it fetches all the data from 3 tables. And so, SAP came with an enhancement of joins called association. Associations are 'JOINS ON DEMAND'.
The data will be fetched only when the user wants to see it.
The syntax of Association is association [min....max].
Where min and max are the instances of the target association.
Further, there are two types of associations.
- Exposed association
- Ad-hoc association
Let's create a CDS view with an association.
Start by selecting a template as define with association.
I have demonstrated VBAK and VBAP tables for defining association.
- EXPOSED ASSOCIATION.
Below is the code snippet.
NOTE: If you get a warning of no access control for an entity, change @AccessControl.authorizationCheck: #NOT_ALLOWED.
NOTE: When we create a table in SE11, we get an option to mark the field as the primary key. But here, in the CDS view we don't have any option as such. Hence we manually have to write the word 'key' whichever field we want to make as a primary key.
Save the above snippet, activate the same ( Ctrl + F3), and run the code. You will get the following execution.
You will notice that only the fields which we have mentioned for table VBAK will be displayed. There is no join performed (i.e no fields of table VBAP). To see further information for vbeln '000000007' from table VBAP, right-click and choose 'Follow Association'. Another pop-up window will open. Click the Association type.
Check the output. You will be able the see the data of vbeln '00000007' from the table 'VBAP'. This is called as 'JOIN ON-DEMAND'.
2. AD-HOC ASSOCIATION.
You can see the SQL statement. Right-click on the above code snippet->Show SQL create a statement.
The following image will appear.
Now to check the output, save, activate, and click on the run icon.
Here you will be able to see all the fields of the select query including table VBAP. This is called as AD-HOC Association.
2. AD-HOC ASSOCIATION.
You can see the SQL statement. Right-click on the above code snippet->Show SQL create a statement.
The following image will appear.
Now to check the output, save, activate, and click on the run icon.
Here you will be able to see all the fields of the select query including table VBAP. This is called as AD-HOC Association.
Define CDS view with parameters
We were unable to add input parameters in SE11 views. But in the CDS view, we have the option to add parameters that can take user input and filter the data accordingly.
Let's take an example and implement the same.
Now add the DDIC SQL name. Provide the input parameters and complete the select query.
- There are two ways of writing parameters. If the parameter type is ABAP data type, we need to specify it as abap.<data type>(<len>). And if the parameter type is not the ABAP one, then we need to mention it normally.
- In the 'where' clause, use the parameter with $parameter keyword i.e $Parameter.<parameter name>. Or you can also just write the parameter name prefixed with a colon in the where clause i.e. :<parameter name>
Save, activate (Ctrl +F3), and hit F8 to execute. Enter the city to get relevant, filtered data.
Extending CDS view
Sometimes, there can be a need for re-using the CDS views in some other projects. Suppose we created a CDS view consisting of 4 fields on table KNA1. If there is a need for the same CDS view but this time with 10 fields of table KNA1, so instead of creating a new one, SAP provides the option of extending the CDS view up to the requirement.
Let's look with the help of an example.
We will take here the CDS view which was created in UNIT 4.2. The name of the DDIC SQL view was ZRDS_CUSTOM. This view initially had 5 fields.
Now, when the requirement changes in the number of fields, we can do an extension. For this, create a new CDS view which has the template name 'Extend view'.
Now add the DDIC SQL name. Complete the select query by mentioning the extra fields. ( You can also hit ctrl +space to get the list of fields which are already present in the previous CDS view, which we are going to extend.)
Once you save and activate the above code snippet, navigate to your old CDS view. You will be able the see the spiral symbol indicating that the extension is successful. Now hit the run icon of the old CDS view.

In our example, we added 2 fields to ZRDS_CUSTOMER_DETAILS.
Further, we can also consume this CDS view in our ABAP report. Navigate to New-> Other ABAP Repository Object->ABAP Program. Or you can also go to SAP LOGON->SE38.
Below is the code snippet along with the output.
In the upcoming third tutorial, we will demonstrate the term HANA Modelling.
Previous blog: Introduction to SAP HANA
Next blog: Introduction to HANA Modelling
2 Comments
Great work!
ReplyDeleteGreat content 🔥
ReplyDelete