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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |