This is the second blog post on the CDS detailed explanations after the Introduction post. Refer to the Introduction and blog post indexes here:
https://blogs.sap.com/2019/10/21/part1.-sap-cds-views-demystification/
Whenver a CDS view is created and activated, these 2 objects gets generated. As I mentioned in the introduction, this enables Code-to-Data paradigm shift.
- DDIC SQL view - It is a Design Time Object and can be seen in tcode- SE11
- HANA View - It is a run time object and gets created in HANA DB
BASIC CDS VIEW:
For all the view I create, I will use FLIGHT demo tables and data to showcase the CDS technology.
- Create an ABAP project within Eclipse by logging in to S4 HANA system.
- Right click on your username under Local Objects and choose New->Other ABAP Repository Objects. Core Data Services->Data Definition.
A simple view will be created. All the statements starting with ‘@’ at the start of the view are called ‘ANNOTATIONS’ and they play a very important role in design and development of the CDS view. They are the ‘Building Blocks’ behind the CDS views configuration. They also define how the CDS view will behave in different scenarios. I will talk about different kind and mostly used annotations.
Now let’s talk about the default annotations while creating the Basic view
- @AbapCatalog.sqlViewName: 'sql_view_name'.
Within first annotation, provide the SQL view name. This is the DDIC SQL view which gets generated once the CDS view is activated and can be seen in tcode SE11. This name
must be of less than or equal to 16 characters as per DDIC SE11 view name limitations. Also, the CDS view name and the SQL view name can NOT be same. So choose a logical name, probably something similar to the CDS view name to keep it consistent.
- @AbapCatalog.compiler.compareFilter: true:
This annotation defines the behavior of the filtering the data i.e. this first compare the filter conditions and if they match then only the data is fetched. If the CDS view has join conditions, they are executed only after the filter conditions are matched. In DDIC views data if first fetched and then filtered.
- @AbapCatalog.preserveKey: true
Another important annotation of CDS views. As you know all the DB tables in SAP do have Keys defined and the CDS Views are always created on top of those DB tables. Now any DB table can have multiple keys defined and you might not want those keys to be the key fields of your view. So if you set this annotation as true, the only fields you define as Key Fields within your CDS view by adding word ‘Key’ in front of those fields will be the Key fields for the CDS view and the DDIC SQL view which gets generated.
If you set this as ‘False’ the DB table key fields will be defined as Key fields for the views as well, regardless of you adding word ‘Key’ in front of fewer fields.
- @AccessControl.authorizationCheck: #NOT_REQUIRED
This annotation is used to add ‘Security’ piece to the CDS view. When CDS view is ready to be rolled out to a bigger audience within or outside the organization, it is very important to restrict the data based on the authority. We will look into creation of authorization objects in the later part. For now let’s keep it #NOT_REQUIRED
- @EndUserText.label: 'CDS View type #BASIC'
This annotation is used to apply business labels other than labels attached in the DB tables, to the fields within the CDS view. This annotation will override the DB table business label and provides what you specify with this annotation.
Let’s add the fields to the CDS view by right click. You can either choose to insert all fields or one by one;
Add the below fields to the CDS view;
I made the field ‘Client’ or ‘MANDT’ disabled due to the reason that this CDS view is created in the ABAP system and the client is handled by the system itself. Now activate the CDS view.
As mentioned before, 2 more objects get created when the CDS view is activated? A DDIC SQL view is created and a HANA view is created;
-Goto Tcode SE11 and check the DDIC SQL view;
-Check the HANA view in Eclipse or HANA Studio platform as below;
You can also check the ‘CREATE’ statement generated by the system.
To summarize, we created a basic CDS view and looked at the default annotations which are already configured when a CDS view is created. Also, we saw the different run time and design time objects which gets created with the view activation.
Part# 3. CDS view with Expressions and Session Variable: Find how to configure mathematical expressions and session variables to fetch system parameters.
Follow me for upcoming blog posts:
kumarsanjeev
Keep learning..
SK.