Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 


Co-Authored: Ritesh K Kumaria, Shekhar Razdan

 

If you have ever looked for CDS views tutorials, guides etc. online, chances are, you would have come across the words “CDS View can be used to define and consume Semantically Rich Data Models”. While these words are used more too often and they are true in their most literal sense, but somehow they seem to escape the limelight they deserve. The purpose of this document is to elaborate what a “Semantically rich data model” means and hopefully, provide a glimpse of an elegant side of CDS Views using ABAP Based CDS Views as an example. Some topics have also been covered via Annexes at the end of the document.  The document does not talks about the performance advantages or other factors that instigate why CDS Views should be used in the first place nor does it claim to cover all the features of the CDS Views and other components used in the example.


Defining “The Semantically rich data model”:


One of the definitions on Wikipedia about the term “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.Link


 


On a simpler note and in the technical world, the word “Semantics” could be understood as attributes that help describe an underlying entity. For those of us who have worked on ABAP may remember how creating a Data Element is expressed as defining the “Semantics” of a field with its labels of varying lengths, search helps etc.  So in essence, it helps to create an impression about the meaning of the underlying information. A Domain on the other hand defines the “Technical” attributes like data type & length.


 


Data models provide a structure for the data by providing a specific definition and format. So attempting to decipher the famed words again; one could infer a ‘Semantically rich data models’ as data models that deliver contextually rich information, properly formatted, and targeted to provide a rich user experience.


So how are CDS Views positioned in the above picture?


If you think about the ABAP CDS Views, in some ways, they might seem a tad similar to ABAP PROJECTION or SELECTION Views. Of course, if you are trying to find differences you will end up with a huge list. But for argument sake, ABAP PROJECTION or SELECTION Views should qualify as a decent metaphor. If you think of some of the simple ABAP CDS Views they could be like a SELECTION View (collection of fields from different database tables) or PROJECTION View (containing only a few fields from EXACTLY one table). But that’s about as far as it goes with the similarities. Even if you ignore the performance advantages of ABAP CDS Views for the moment (as mentioned in the pretext), you still have a cool list of Operands, Expressions and Annotations at your disposal. Add on to this, a host of other available options like View-on-view, View with parameters, Associations, View extensions & Authorization control and you have all the elements you need to define the data models of your choice.


CDS Views can be marked as “Analytical” queries using relevant annotations. We will discuss the details later in the document but point to be stressed here is that all such analytical queries defined using CDS views act a Transient info-providers. There is no additional setup / configuration required to expose these queries so that they can be consumed via end clients. Also equally important is the use of word “Transient”, since the data from the views is not stored / persisted separately, it is directly retrieved from the underlying base table / tables and fed to the end clients proving a more real time experience.


 


The concept of Virtual Data Models (VDM):


 



Image from SAP HELP


 


The key principle of the Virtual Data Model (VDM) is to build a semantic layer on top of the existing hiding its technical details. The layers of VDM are nothing but different CDS Views linked to each other using View-on-view concept and/or Associations and Extensions. Each layer is defined keeping in mind a specific purpose or function. For e.g. the Interface View / layer at the bottom provides an abstraction to the underlying database table(s) and acts as a foundation view for other views on top like a single source of truth.  While those on top provide a foundation for consumption views to define requirement specific layouts and may also provide an anchor point for enhancements. The private views provide a more application specific logic which should not altered / extended. Consumption views help in defining end user layouts including selection screens, labels etc. The extension views can help provide an important enhancement point in case of standard SAP delivered reports while the DCL views deliver the authorization control.


 


The Virtual Data Model acts a conceptual data model and therefore does not mandate a specific number of views. However, it does provide a guideline on how to effectively organize different CDS entities in order to achieve a robust, efficient and a maintainable data model.


 


The Consumption Clients:


The consumer clients have also traveled their part of road in the last few years. Some of you may recall how a few years back SAP BW reports were being viewed using BEx Analyzer in MS Excel. The alternative now is the “Analysis for Office” an Excel Add on which is available as an end client to consume analytical queries (Including those defined using CDS Views). Of-course there are differences between the two mainly in terms of the overall user experience they deliver.


 


There is a host of other such clients capable of delivering a rich user experience for e.g. Crystal Reports, Lumira etc.  most of them have grown in features, capabilities over the years.


Features Glimpse:


As mentioned in the beginning of the document here is an example of a sample report created using ABAP based CDS Views. Some of the important features are highlighted here with detailed explanation on how to achieve those being mentioned in the subsequent sections.


Fully functional Selection Screen with Single and Range Inputs, Value (F4) help and variant save options among others.

 






Creating the report and consuming it via Analysis for Office in Excel:

This simple example demonstrates how easy it is to create Powerful, yet extremely user friendly reports using CDS views and how they can be consumed easily by an Analytical client. Following the VDM rules and guidelines one can create a solid foundation which can be the basis for several different reports. Standard SAP report stacks can be enhanced using CDS Views enhancement concepts allowing to add more fields/data to existing reports. Report access can be restricted via the Authorization concept. 


 


For the purpose of illustration ISDSALESDOC CDS view is used. This CDS View is a standard CDS View delivered by SAP in the ERP system and is defined as a Basic Interface view selecting data from various Sales Order tables.


 


To keep the example simple, only two more views have been created on top of the standard view. The first view ZCDS_COMP is analogous to the top level Interface View in VDM which acts as a foundation for consumption views on top. This view is marked as a composite view which means that it provides data derived and / or composed from Basic view. It is also defined as ‘#CUBE’ in the analytical query and it works as an encapsulation / folder for all the Consumption Views defined on top of it.


 


The Consumption view ZCDS_QUERY has code that uses various analytics annotations that help prepare a Predefined report format, create a selection screen for the user etc.



ISSALESDOC CDS View: This is a Standard View existing in the SAP ERP system.



 


ZCDS_COMP View: Reference code in Attachment: Source_Code_ZCDS_COMP.txt



 


ZCDS_QUERY View: Reference code in Attachment: Source_Code_ZCDS_QUERY.txt



Use the code from Source Code files to create the two views. Once the views have been created and activated, please refer the below steps to display the report output.


 


Incase needed, please refer to Annexure sections on how to create a CDS View using Eclipse with ABAP Development Toolkit Add-on.


 


Following steps describe how to consume this query using Analysis for Office an Excel Add-On:


Analysis for Office is one of the most popular analytics client. The example tries to demonstrate how easy it is to consume a CDS Views based analytics query in Excel with this Add-on.


Analysis for Office is an Add-on which needs to be installed separately. Please install the latest version of Analysis for Office on your machine.

 



 

For e.g. if you look at the below Menu bar from Microsoft Office 2013 edition you will notice it does not have a tab called ‘Analysis’.

 



Once the Analysis for Office is installed the ‘Analysis’ tab should be visible.

 

In order to view the data, navigate to the ‘Analysis’ tab in Excel and click on ‘Insert data source’ -> ‘Select data Source’.

 

Skip the first screen by clicking the ‘Skip’ button.

 

The subsequent screen displays a list of connections from SAP Logon pad of your system. Logon to the correct system by providing the required credentials.

 



 

The next screen displays a Search Box. Give the SQL View for exact results or you can find the Views via text as well. Text labels are specified using annotation @EndUserText.label in CDS Views. 

 




 

Select a report and Click ‘OK’ and the query will be processed in the background and results will be displayed.

 

In case, the view definition consists of fields which are marked to be displayed via a Selection screen, an appropriate selection screen is displayed which acts as a filter criteria for the results. Some of the relevant Annotations are listed below. Please note, in case of views with parameters, all view parameters act as mandatory parameters on the selection screen. Also, some features like, Variant save etc. are added automatically by the Analysis add-on. 


 


@AnalyticsDetails.query.variableSequence:


{Sequence the fields on Selection Screen}


 


@Consumption.filter.multipleSelections:


{Input Range}


 


@Consumption.defaultValue:


{Give Default Value to a Selection Screen field}


 


@Consumption.hidden:


{Hide a field}


 


@Environment.systemField:


{Use system variables like System Date etc.}


 


Please refer the source code of ZCDS_QUERY view for complete Syntax and details.


 



 


Default Report Layout includes specifying which fields from the field list would appear as Columns and those which would appear as Rows. Please note the report change options on the right side of the screen shot are added automatically via Analysis Add-on.

Relevant Annotations in this case include:

@AnalyticsDetails.query.axis: #ROWS

@AnalyticsDetails.query.axis: #COLUMNS

@AnalyticsDetails.query.totals: #SHOW

@DefaultAggregation: #SUM

@Semantics.unitOfMeasure: TRUE

@Semantics.quantity.unitOfMeasure:

Please refer the source code of ZCDS_QUERY view for complete Syntax and details.

 



 

 

 

Annexure 1: How to create a CDS View using Eclipse and ABAP development Toolkit Add-on

ABAP based CDS views can be created and managed via Eclipse using ABAP development Toolkit Add-on. They cannot be managed via SE11 like traditional views. In order to create CDS views, you need to be in the ABAP perspective.

Configure a connection to a system by choosing File -> New -> ABAP Project.



 

The next screen shows a list of Connection from your SAP local Logon Pad. Choose the system on which you want to develop and click Next.

 

 



 

Provide Logon Credentials and click Finish.

 



 

Following is a screen shot of ABAP perspective.



To being with, you can create ABAP CDS Views in $tmp package. By default, the $tmp package is already added under the “Favorite Packages”. Expand the Project Explorer node and Right Click on the $tmp Package, then select “Other ABAP Repository Object” and in the search bar start by typing in DDL.





Provide CDS view name and Description and click “Next”.



Since the view is being created in $tmp package hence there is no need to select a transport request. Proceed by clicking “Next”.



Proceed without selecting a template. Click “Finish”.



Write the relevant code and Press Ctrl + F3 to Create and Activate the CDS View. You could also Copy and Paste the Source Code from the files in Attachment. Follow the same process to create both the views ZCDS_COMP and ZCDS_QUERY.



Annexure 2: How to perform Authorization checks on data selected from CDS Views

Acronyms: -
DDL: Data Definition Language < Defining for View and Extension of the View >
DCL: Data control language       < Defining Authority Checks >


 

In order to perform authorization checks in CDS view a DCL entity needs to be created. The steps to create a DCL file are similar to how DDL entities (CDS Views are created). Please refer to Annexure 1 for details.

 

Instead of DDL, please mention “DCL” in the New ABAP Repository Object screen



And create a CDS entity using the below sample code for reference. Note, “S_CARRID” is the authorization object which is being used to perform the check and “demo_cds_auth_pfcg2’ is the name of the view on which the authorization check will be performed.



In order to perform the authorization check, annotation @AccessControl.authorizationCheck: #CHECK needs to be added in the view on which the check needs to be performed. Please refer the code in the screenshot below.



View the records from view “demo_cds_auth_pfcg2” by Pressing F8 or run in the Eclipse. The selected data is filtered based on the Authorization check (DCL).

Annotation : AccessControl.authorizationCheck values

 

#NOT_REQUIRED.

During the authorization runtime, an authorization check is executed if a DCL role exists for the entity. If no role exists there is no check and no protection. This is the same behavior at runtime as for value #CHECK.

However in this case it is intended by the developer that no role exists.

During development, no warning occurs when activating the entity. This is the default value.

 

#NOT_ALLOWED

During the authorization runtime, no authorization check is executed.

During development, a warning occurs if a developer activates a role for an entity, which has this annotation value.

 

#CHECK

If Open SQL is used to access the view, an authorization check is made implicitly if a CDS role is assigned to the view. If there is no role for the view, a syntax check warning occurs.

5 Comments