SAP HANA Academy – SAP S/4HANA: Core Data Services – 03 Creating Basic Views

SAP HANA Academy – SAP S/4HANA: Core Data Services – 03 Creating Basic Views

Welcome to the SAP HANA Academy my name is Bob and in this series of videos we’ll be looking at SAP S/4HANA. In this series of videos we’ll be looking at how to use Core Data Services. In this video of the series we’re going to look at creating basic also known as interface views. So we’ve already looked in previous videos at creating users and creating an empty ABAP project within the SAP HANA Studio and what we’re going to do in this series of two videos is build a CDS view on top of the data contained in this demo data table called SCARR. So you can see it simply lists a list of carriers it’s in a demo database called sFlight and it lists the various carriers, the ID and the currency code. We’re just going to expose this for your ODATA as a gentle introduction into the concept of CDSs. So what we need to do is go back to our ABAP perspective and we create our CDSs here. Now think about CDS’s it’s not written in ABAP but it’s objects will exist in the ABAP repository. Essentially it’s a combination of both open SQL and a various list of annotations. The annotations then further define the view as well as all the data elements within that CDS. So again we’re going to build ourselves one of these basic views on top of that table here. So the first thing we need to do is we built our empty package. I’m going to now go right click and I’ll select new and if I go to other ABAP repository object and go down we’ve got core data services and essentially you’ve got two various options. You’ve got a DCL and a DDL. So at a very high level the DCLs are used for security. So they enable you to do things like role level security. We’re going to cover those in another series of videos and instead we’re going to focus on these things called DDLs. So I’ll select DDL source and I’ll click next. Now this is going to go in the temp package so there’s nothing we need to change here but we might need to add a description and a name. Now what we’re essentially doing is creating a view on that carrier table in sFlight. This is the description I’m going to give so it’s to do with Airlines it’s a private view and it’s a VDM interface view. But when you build the CDS views they share a namespace and therefore should not interfere with productive or delivered views. So basically it means that you must have a naming convention. So for example I’m going to create myself a view with the following name. So the syntax is normally Z X which means it’s a development workspace then you need to give a name. So this is normally the two letters from your user. So I’m going to do SH for the user then I’m going to do I because it’s what’s called a basic view. Now you’re going to see there are differences between basic views and consumption views. A basic view would essentially hit the raw data in your tables in between you’ve got a series of views and at the top you’ve got what’s called a consumption view. This is what your analytics or your Data would then be exposed to. So what we’re doing is building one of these basic views or interface views and that’s what I’m putting an I. But essentially it’s what we call a basic view. Then I’m going to give the name of the view which is underscore airline like so. So if we give it this name we’re adhering to a naming convention. So then I’ll select next. Now the next screen will give us our selection of transport requests. Now transport requests enable you to move content from system to system and these can be used for productive CDS views but because these are local CDS views we’re using they’re not really necessary. We’re going to cover this option of course in other videos. So I’ll select next and then you’ve got your list of templates. Now these cover the most common use cases such as doing joins between different tables or associations and so we’ll just now need to click on finish. Now what you’ll notice is when the CDS is created several default annotations are automatically added and we’ll have a look at what those mean later on. So firstly it’s a good idea to change this view name because we had it an underscore. So all I’m going to do is add an underscore here and I’ll change this to a I. So that syntax now we’ll go. Of course the from statement here is not going to be data source name we need to specify the table. So if I press control space you’ll get some code completion. So as you can see here it’s listing all the objects I’ve got available to me but we know we’re going to use that SCARR table. So if I go back to my data browser this is the table we’re going to use which is the carrier table from sFlight. So I’m going to type here in my code completion. Oops if I type s and then control space. If I continue to type of course we’re going to get that SCARR data source. There we go. And of course what you’ll see on the left hand side within our outline is actually we’re building up that query. So of course now we need to select our column so we do this on line six. So again to do this all I need to do is press control space and then we’ve got the option to insert all our various elements. So I’m going to select here car ID which is just the ID it gives you data type information and we’ll give it an alias. So I’m going to just put as airline just like a normal SQL alias. Now to add more columns of course you just add these below. So I’m going to also add control space. I’ll add another column which is currency code. Our aliases as airline local currency. There we go and then we’ll add another column so I’ll just press space here and then we’re going to add another column which is the airline URL which is essentially URL here. So it’s this column here and again you’ve got the data type information on the right hand side this is the airline URL and I’m going to give this an alias as airline URL. There we go of course because we’re building up this view you can see the objects in the Select list of the view the source table. So you can see how this outline is actually quite useful to check syntax. Now the next part is to deal with these annotations. So we’ll have a look at them. So the first one is the ABAP catalog SQL view name. Essentially it’s going to be the same as the view but it’s going to have no underscores. So it’s going to be Z X SH I airline. So I can just replace that syntax here and again it’s just the name without any underscores. Now even though we’ve not looked at the other annotations this view can now be checked. If we go and if I save and we expand our list of CDSs and go to our data definitions you’ve got that Z X SH I underscore airline. If I activate. We can see activated okay and of course to test if I right-click and go to data preview like a normal view. We’re testing the view now. So again of course we’ve got the airline aliased the airline local currency and of course lastly that airline URL. So to deal with the other annotations and there’s lots of lots of these annotations and we’re only going to cover the the principle ones in this video. So another one that you might want to change is this end-user text label. So I’m going to take out private view VDM. And that’s kind of more of a technical name and I’m just going to put this as airline. Basically I’m changing this to something that is more end-user readable or translatable and this text label is exposed on objects within your OData services. So I’ve changed that again to airline just to make it more readable. So as I inferred at the beginning of the video there are different types of views. This is what we call a basic view. So to indicate whether it’s a basic a composite which is kind of like in between a basic and or a consumption view we need to specify that here with a special annotation. So this is going to be good to show you how your add annotations you can imagine it’s very easy I do the ampersand the annotation I want to have it include is VDM and then you’ve got obviously the drop-down. So I’m going to add VDM dot view type. Now if I’m not sure what the options are again if I press the control space these are the different types you’ve got a basic view which again is used to directly access your database tables and these are actually private in that the end user never accesses them directly. You’ve also got the option of a composite view now this is the basis underline view for analytics and it’s used to combine different views with what are called associations we’re going to have a look at that in a later video. And lastly you’ve got these consumption views. So this is the end-user view which is accessible through an analytic front-end or is used to publish to OData for example. So for us this is our basic view we’re hitting the raw table. So I’ll select basic and you can see here that we’ve got no errors. So later because we want to do some analytics using these views we’re going to add another annotation and that annotation essentially indicates that this is a dimension type of table. So to do this I’m going to do an ampersand and type analytics we’ve got that analytics data category. So if I select data category and I press a control space again you’ve got different levels. You’ve got whether it’s an aggregate, whether it’s a cube, a fact. This is a dimension. It’s a very very simple example. Now some of the annotations you only see at the top of your CDS and there’s a different set of annotations you’ll see if you’re within a select statement. So to give you a simple example. If I go to the top and I type a ampersand S and type semantics nothing comes up and nothing is coming up because this annotation only works within the Select statement. So if I basically go here to my local currency and I go above the column and type ampersand. If I type seman you’ll see that some of these annotations appear. So to add a semantic which is basically a way of describing the data what I’m going to do is I’m gonna do for the currency code I’m going to say semantics and then dot currency code equals true. So I’m inferring of course that this is a currency code. And we can of course apply this as well to a URL. So if I type @ and then type semantics. All I’m going to do is I’m going to infer that this is a URL. So if I type semantics and then I type dot URL like before I can add a colon and indicate that this is a URL like so. You can see this also indicated on the left hand side. So just a few things one thing is that because we want to expose this as OData we need to define a key. So of course our carrier ID is our primary key. Again going back to the table this is going to be our unique identifier so what I’m going to do here is I’m simply going to say that the CARR ID I’m going to type the word key which indicates it’s a key. And then lastly the thing one thing we haven’t been through is this access control authorization check. Now if you remember when we actually first created the DDL there was an option to create a DCL. DCLs are to do with access controls so kind of like row-level security. You can define which user has access to which data in a specific table. We don’t have any details in this simple example. So at the moment it’s going to check for a DCL. But we don’t have one so it’s not going to work. So if I do a control space I’m actually going to say that it’s not required we don’t need any form of DCL. So that in this simple example there’s no security or there’s no row level security. So when you’ve done that that’s it of course what we’ll do now is we’ll save and lastly what you’ll need to do is you’ll see here that although it’s saved it’s not been activated. So to activate you click here. And now we can see it’s activated. So a couple of things you should know of course. On the bottom left hand side you can see the object which is selected. You can see that airline is a key. You can see that these have included semantics and of course lastly the ultimate test is to right-click and to test this basic view. So I’m going to do a data preview and we should get some data. So that’s where we should be now. So now that we’ve done this what we’re going to do in the next video is look at building in a simple example a consumption view. So we’re not going to build any of these composite views which are kind of like in the middle we’re going to build these end user consumption views which will be accessed by analytics or if you want to expose this data as Data.

13 thoughts to “SAP HANA Academy – SAP S/4HANA: Core Data Services – 03 Creating Basic Views”

  1. How do we create Proxy views (objects) for tables, avoiding GFN issues?Please share wiki link if you have any.Thnx

  2. hi Sathish Reddy, the basic or interface views are the initial views created mostly at the table level with no or little redundancy in the fields. they can be thought of the building blocks to create the views further up your virtual data model 'pyramid'. the cube views are higher up in the vdm and could consist of many dimensional views.

    if you're following along with this whole vdm course in the academy, you'll later build a cube view. this cube is part of the composite type of views as opposed to the basic views that they're built off of.

    after the cube view, you'll build a final consumption layer on top of the cube. the end user would point their analytics to this consumption type view. when you're at this consumption level, you'll use another annotation which would create the actual cube. @Analytics.query: true

    later in the series we show how to connect tools like Analysis for Office to the consumption layer.

  3. Hi Bob,
    Nice video. Have small question when i am trying to get quantity value from table to CDS view that particular quantity field value is showing 0. May i know the reason or for quantity fields is there any special syntax.

    Appreciate your help and thank you very much for the great stuff.

  4. Whats make the difference between Semantics.currencyCode and @Semantics.url without using these semantics you executed and after that u used these semantics both gave the same output.
    Then whats the use of using these semantics.


  5. I would like to express my utmost gratitude to you for sharing this detailed tutorial! Keep up the great work! I love your videos ☺️😁

Leave a Reply

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