<Nico💻/>

Technology, HelloWorld() and much++✌

How to create your first CDS View

After some time ago working with SAP R/3 and BW 7.3, developing solutions based in ABAP code, it’s time finally to get finally new possibilities, many of them available due to the capabilities of the SAP HANA in-memory database. The plan of that post, as the blog in general, is not really go deeper in these topic details, for it I would recommend the official SAP Developer Guide, but show you how to create a simple Hello World CDS View.

What are CDS View?

According to SAP, “Core Data Services (CDS) is an infrastructure that developers can use to create semantically rich (persistent) data models. It enhances SQL to allow defining and consuming these data models in applications, thereby improving productivity, consumability, performance, and interoperability.” [Source: https://help.sap.com]

Hands on

We will use it as a simple example of joins of tables, very common, useful, and simple. So, open your Eclipse, connect your system and let’s do it! First, we will create the CDS Definition, the one responsible to define all the view behavior. Do a right-click over the System Library and click in Other ABAP Repository Object:

Look for the CDS View folder, select Data Definition and click in Next:

Fill the basic information and click in Finish to (if you want to transport it, don’t forgot to define a Package):

Now you will be able to do some coding and to start with it you can use that block bellow as a base for it. Of course, you should use your system tables according your need, for example, /BIC/ tables for BW developers that want to expose data:

@AbapCatalog.sqlViewName: 'Z_VIEW_NAME' 
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'My View Description'
define view Z_VIEW_DEFINITION as select from TABLE_A as TB_A
                                        join TABLE_B as TB_B on  TB_A.KEY_1 = TB_B.KEY_1
                                        join TABLE_C as TB_C on  TB_C.KEY_1 = TB_A.KEY_1
{
    key TB_A.KEY_1   as K_1,
        TB_B.FIELD_1 as F_1,
        TB_C.FIELD_1 as F_2,
        TB_C.FIELD_1 as F_3
}

Regarding this code, keep in mind that:

  • Z_VIEW_NAME is the name of the virtual view that will be created based on your definition, for a better understanding, it’s the name you would be able to found in the SE16 transaction on SAP GUI side.
  • My View Description: its a free name visible for end-user depending on your application.
  • Z_VIEW_DEFINITION: it’s the name you used when you were creating the Definition.
  • TABLE_*, TB_*;FIELD_*;F_* are only fake names used for coding examples. In your scenario you for sure will use different names for Tables and Fields.

Now, in a real-world case, you would need to implement the logic needs, and for it there is a very useful page from SAP that offers us a lot of short examples of SQL commands. Check this out by clicking here.

In general, for the ones that are used to work with SQL development, the sky is the limit. That is only the start, but keep in mind that is possible to work with parameters, conversions, conditionals, and even if it looks stranger, ABAP. In one of the next posts, I plan to bring you a simple example of how to implement a CDS View that has a “background” ABAP coding. Of course, it should not be an “always solution” basis due to the performance restrictions, but many times it can be useful for hard and complex scenarios.

SAP Tutorial: Create a Simple ABAP CDS View in ADT

If you want to get it in more detail with a better step-by-step explained, I strongly suggest you check this SAP tutorial: https://developers.sap.com/tutorials/abap-dev-adt-create-cds-view.html

Enjoy your travel! 😉

Author

Avatar
Nícolas Estevan Padovani MartinsBI System Analyst, Computer Engineer & Developer
“Networking it’s not about how many connections you have, but the much you are really connected to them. - Let’s learn, let’s share.”

Leave a Reply

Your email address will not be published. Required fields are marked *