CDS TUTORIAL 1: SAP HANA ABAP MADE EASY

Share

CDS

CDS stands for core data service. CDS is one of the code pushdown mechanism to shift the load to dB layer in s4 Hana.

  • CDS is semantically rich data model
  • Semantic Data Model” describes it as “A conceptual data model that includes the capability to express information that enables parties to the information exchange to interpret meaning (semantics) from the instances, without the need to know the meta-model.
  • CDS is an enhancement of SQL
  • Annotation, path expression and Association fuels up the power of CDS

Annotation 

Annotations are code snippets used to enable certain functions or it adds up component specific metadata to a CDS View.

Creating a CDS view

When we create a CDS view we must use HANA studio or Eclipse tool with ADT (ABAP development toolkit).

Steps to create a CDS View

  1. Right click go to🡪 New and select🡪 Other ABAP Repository Object
  1. Expand the Core Data Service node and select Data Definition and click on Next
  1. In Name and Description give the CDS name and its description on clicking on Browse package can be select on it can be store in temp click on Next for further steps.
  1. In the below pop-up TR can be select and click on Next for selecting the CDS templates
  1. As per the requirement templates could be selected [Templates are predefined format or code snippets for CDS view] click on Finish to complete the Steps.
  1. After completing the steps below code will be autogenerated 
  1. Let’s Understand the code line by line
  • Line starts with @ indicate it’s an annotation
  • Annotation🡪 @AbapCatalog.sqlViewName: ‘sql_view_name’ This annotation is used to give a name to your SQl View, it should not exceed more than 16 char and starts with Z or Y
  • SQL View and CDS View🡪As soon as CDS view is activated it will create two entity one is SQL View which can be open from SE11.Another one is CDS view or DDIC view or HANA view that can be open in Eclipse or HANA studio only and same can be used in Select query.
  • Annotation🡪@AbapCatalog.compiler.compareFilter: true This annotation is useful when we are creating a CDS with parameter it has two open :true and :false 
  • :true🡪It will filter the data at DB level itself
  • :false🡪It will first get the data and then filter it
  • When ever there is a parameterized CDS view it is recommended to use @AbapCatalog.compiler.compareFilter: as :true
  • Annotation🡪@AbapCatalog.preserveKey: true This annotation is used to define the key field in the CDS View if it is set as :true it will take the key defined in the CDS View, if it is :false it will take the key automatically from the source table which is used in the select query
True and no key define in CDSResult
True and Key is defined in CDSResults
False and no key define in CDSResult
False and key define in CDSResults
False and no key defined in CDS and field selected in query not in right sequenceResult
  • Annotation🡪 @AccessControl.authorizationCheck: #CHECK if it is #CHECK and in top of the CDS view there is access control then the user must have the authorization to see the result

@AccessControl.authorizationCheck: #NOT_ALLOWED if it is #NOT_ALLOWED then it will bypass the access control check

  • Annotation🡪 @EndUserText.label: ‘CDS Demo 1’ it will set the SQL view short description
  • In the data_source_name table name has to give
  • Field selected in the CDS View know as CDS Element
  1. To execute the CDS press f8 and you can see the results
  1. System Field in CDS🡪There are 4 system field in CDS View
  2. $session.client 🡪 gives the client detail
  3. $session.system_date               🡪 gives the system date
  4. $session.system_language  🡪 gives the system language
  5.  $session.user 🡪 gives the user detail

These system field can be used in a where clause or can be used as a default field in a CDS

Eg.