Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

In a five part video series the SAP HANA Academy's tahirhussain.babar walks through how to set up and use Core Data Services in SAP S/4 HANA.


Introduction to CDS - Creating a CAL Instance and Creating an ERP User


In the first video of the series Bob details how to get a S/4 HANA instance and how to create the S/4 HANA user that's necessary for executing the tasks preformed in the series.

There are a few prerequisites before you can start this series. First, it's assumed that you already have a SAP Cloud Appliance Library account and that you have instantiated a solution with an image called S/4 HANA, on premise edition - Fully Activated. When you click on create instance you are creating a few machines: SAP BusinessObjects BI Platform 4.1 server, SAP ERP 607 server on SAP HANA SPS09, and SAP HANA Windows client. Essentially, you're building three separate servers.

Once you have created this instance, if you move your cursor over the solution title, there is a link to a Getting Started document. It's assumed that you've followed all of the steps detailed in the document in order to instantiate your own instance of S/4 HANA.


When you log into your Windows instance there will be a pair of tools that you will utilize. One is Eclipse, which is used for development and where you will build the CDSs. Please make sure you're using the latest version of Eclipse. You should have the HANA Development tools, including the ABAP perspective, updated on a regular basis. The other tool is the SAP Login which is used to access the SAP ERP system.


Open Eclipse and then click on Window > Perspective > Open Perspective > Other and choose ABAP to open a new ABAP perspective.


To create a new ERP user with all rights, first, open the SAP Logon and log into client 100, which is a preconfigured S4 client, with the default user and password. Next, run the command /nus01 to create a new user.

Bob names his user SHA and then clicks the create button. On the Maintain Users screen you must provide a last name in the Address tab and change the default password in the Logon Data tab. Also, in the Profiles tab, you must add SAP_ALL (have all SAP System authorizations) and SAP_New (have new authorizations checks). This essentially creates a copy of the default client 100 user so you will have enough roles and rights to preform the tasks carried out later on in the series. Click on the save icon to finish creating the new user.

Next, click on the orange log off button and log in as the new user. As it's the first time you're logging in as the new user you will be prompted to change your password.


How to Create an ABAP Project and Load Demo Data

Below in the second video of the series Bob details how to create a new ABAP project within Eclipse and how to load demo data.

In the ABAP perspective in Eclipse right click on the projects window and select New > Project > ABAP > ABAP Project and then click Next. Choose to define the system connection manually. Enter your System ID - Bob's is S4H. The Application Server is the IP address of your ERP system. Also, enter your Instance ID (Bob's is 00) before clicking Next. Enter your Client (100) user name, password and preferred language code (EN for English) before clicking on finish. Now you have created a ABAP project within your ERP system using your recently created user and connection.


Drilling down into Favorite Packages will show the temp package ($TMP-SHA) that has been created. S/4 HANA is installed, so there are already a ton of existing CDS views. Scroll down into the APL package and search for and open the ODATA_MM folder. Your CDSs are stored in a folder in the ODATA_MM_ANALYTICS package. Two sub folders exist. Access Controls, which deals with security, and Data Definitions, where you build CDSs.

The CDS highlighted above, C_OVERDUPO, is the CDS in the overdue purchased orders tiles used in the SAP Fiori launchpad.


Back in the SAP GUI log in as the new user you recently created. To load some demo data run the command /nse38. Next, choose SAPBC_DATA_GENERATOR. You will be using S-Flight, which creates a series of tables and BAPIs that enable you to test your ERP system using an airline's booking system's flight data. Next, hit the execute button and select the Standard Data Record option before hitting execute again.

To see the data run the command /nse16. Enter SCARR for the table name and then click on the object at the top left to see the data.

How to Create Interface Views

Bob shows how to create basic, aka interface, views in the series' third video. You will be building a CDS view on top of the data contained in the Demo Data table called SCARR. The table lists the various Airline carriers, the carrier ID and the currency code. You will be exposing this data via OData as a gentle introduction into the CDS concept.


CDSs aren't written in ABAP but the objects will exist in the ABAP repository. Essentially, it is a combination of both OpenSQL and a various list of annotations. The annotations further define the view as well as all of the data elements within that CDS.


In Eclipse right click on the empty package in the ABAP project and select New > Other ABAP Repository Object > Core Data Services. The two options available are DCL Source and DDL Source. DCL Source is used for security by enabling you to preform role-level security. Bob opts for the other option and selects DDL Source before clicking Next.


Bob enters Airline, private view, VDM interface view as his description. However, when you build CDS views they will share a namespace and therefore should not interfere with productive or delivered views. Basically, you must utilize a naming convention.


So Bob names his CDS view ZXSHI_AIRLINE. ZX means it's a development workspace. SH is the first two letters of his user name. I means that it's a basic view. A basic view hits the raw data in your tables. In-between there will be a series of other views with consumption views at the top. Analytics or OData are exposed to consumption views. 

After clicking on Next, Bob will select his Transport Requests. Transport Requests enable you to move content from system to system and can be used for productive CDS views. However, as these are local CDS views, you won't need any Transport Requests. Clicking Next brings you to the list of Templates. These cover the most common use cases such as joins between different tables or associations. Click Finish to create the CDS view.


Several default annotations are created with the CDS. First, change the define view name in line 5 to match ZXSHI_ARILINE. Next, hitting control+space next to as select from will bring up code completion so you can find the scarr data source. The bottom left hand side shows an outline for the query that Bob is building up.

On line 6 you will need to select the column. Press control+space and choose scarr.carrid and then add as Airline. Also, add scarr.currcode as AirlineLocalCurrency and scarr.url as AirlineURL.

The first annotation is @AbabCatalog.sqlViewName and will, essentially, be the same name as the view but without any underscores. So enter ZXSHIAIRLINE. To check the view click on the save button and then drill into the view located in the Data Definitions folder in the CDS folder. Activate the package and then open a data preview on the ZXSHI_AIRLINE CDS to see the list of airlines, currencies and URLs.

Another annotation that must be changed is @EndUserText.label on line 4. You should replace the existing technical term with just Airline as it is more readable. This text label is exposed on objects within your OData services. Next, add an annotation to signal that this is a basic/interface view by typing @VDM.viewType: #BASIC on a new line.

Basic views are private as the end user never accesses the system directly. Another type of view is a Composite, which is a basis underlying view for Analytics. It is used to combine different views via associations. The Consumption view is an end user view, which is accessible through an analytical front-end or is used for publication to OData.


Bob adds an additional annotation, @Analytics.dataCatagory: #DIMENSION, in another line so analytics can be used with these views. This indicates that it will be a dimension type table.

There is also a different set of annotations that you will see inside a select statement. For example, the annotation @semantics won't appear when you try to enter it with all of the other annotations at the top. However, it will appear and can be entered when you type it within the select statement at the bottom of the CDS. Bob adds the annotation @Semantics.CurrencyCode: true above his carr.currcode line to imply that it is a currency code. Bob also adds @Semantics.url to infer that the line below is a url.

You must define a key if you want to expose the CDS as OData. The carrier ID will be the primary key, so Bob types key in front of the scarr.carrid as Airline.


When you first created this DDL, there was the other option of creating a DCL instead. A DCL involves access controls as you can define which user will have access to which data in a specific table. Currently there are no DCLs, so the annotation @AccessControl.authorizationsCheck: #CHECK needs to be changed to @AccessControl.authorizationsCheck: #NOT_REQUIRED. Therefore, in this example there will be no role level security.

Full Syntax - Interface View

-----------------------------------------------------------------------------------------------------------------------------------------

@AbapCatalog.sqlViewName: 'ZXSHIAIRLINE'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationsCheck: #NOT_REQUIRED

@EndUserText.label: 'Airline'

@VDM.viewType: #BASIC

@Analytics.dataCategory: #DIMENSION

define view ZxshI_Airline as select from scarr {

key scarr.carrid as Airline,

@Semantics.currencyCode: ture

scarr.currcode as AirlineLocalCurrency,

@Semantics.url: true

scarr.url as AirlineURL

}

-----------------------------------------------------------------------------------------------------------------------------------------

Once the CDS looks like the syntax above click on the save button. Activate the CDS and then open a data preview on it to verify there is data in it.


How to Create a Consumption View

In the fourth video in the series Bob walks through how to create a consumption view. Normally there would be many interface views so there would be a full breadth of dimensions and facts available for the analytics tools. You can use associations to join data from multiple basic views together in a composite view. In this simple demo Bob skips building a composite view and chooses to build an consumption view which he will expose to OData.


Bob right clicks on his data definitions folders and chooses to build a new DDL Source. Bob names his view ZXSHC_AIRLINEQUERY. ZX is for development view, SH are the initials for Bob's user and C is for consumption view. For the description Bob enters Airline query, public view, VDM consumption view and then clicks next. Bob leaves the default for Transport Request and chooses a basic view without any associations or joins before clicking finish to create his consumption view.

First, Bob changes line 6 to define view zxshc_Airlinequery as select from zxshI_Airline {. Next, Bob modifies his sqlViewName in line 1 to 'ZXSHCAIRLINEQ'. Keep in mind that this view name can only be 16 characters long. Then, Bob modifies the annotation in line 4 to read @EndUserText.label: 'Airline'. After, Bob marks that it's a consumption view by adding a new annotation, @VDM.viewType: #CONSUMPTION, underneath.


Next, Bob selects the columns (Airline, AirlineLocalCurrency and AirlineURL) by pressing control+space on line 7 and chooses Insert all elements - Template. Finally, you must add an annotation beneath the consumption view annotation to expose the view as OData. Bob enters @OData.publish: ture.

Save and then activate the consumption view CDS. After activation, you will see that an error has occurred. Hovering the cursor over the caution marker will inform you that there is a missing key element in the ZXSHCAIRLINEQ view.

To fix it, add key at the beginning of line 8 before ZxshI_Airline.Airline. Then save and activate.


Now if you hover the cursor over the OData line it will inform you that the activation needs to be done manually through the /IWFND/MAINT_SERVICE command in ERP. Finally, Bob changes the annotation for the authorizationCheck to #NOT_REQUIRED.


Full Syntax - Consumption View

-----------------------------------------------------------------------------------------------------------------------------------------

@AbapCatalog.sqlViewName: 'ZXSHCAIRLINEQ'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Airline'

@VDM.viewType: #CONSUMPTION

@OData.publish: true

define view zxshc_Airlinequery as select from ZxshI_Airline {

key ZxshI_Airline.Airline,

ZxshI_Airline.AirlineLocalCurrency,

ZxshI_Airline.AirlineURL

}

-----------------------------------------------------------------------------------------------------------------------------------------


Creating OData Services

In the fifth and final video in the series Bob shows how to create OData services from the interface and consumption views he recently created based on CDSs from S/4 HANA.


Bob will now have to execute the command /IWFND/MAINT_SERVICE within his ERP system to register the OData service. In the SAP GUI, go to the top level of the ERP and enter the command /IWFND/MAINT_SERVICE. If you get an error informing you to log in but you are already logged in as your user, then place a n in front of the command. So it will display /nIWFND/MAINT_SERVICE before you press enter.


You will register the CDS consumption view you built in the ABAP repository and expose it as OData on the Activate and Maintain Services page. The service that you must add is listed in Eclipse when you click on the maker next to the OData annotation in your consumption view. The service is called ZXSHC_AIRLINEQUERY_CDS. Please copy it.

Back on the Activate and Maintain Services page, click on the Add Service button. For the System Alias choose LOCAL_PGW as it's the S/4 HANA trusted service. Paste in your copied service as the Technical Service Name. Then, hit the Get Services button on the top left hand side. Next, select ZXSHC_AIRLINEQUERY_CDS as the backend service and click on the Add Selected Services button.

The only item that needs to be addressed on the Add Service window that pops up is the Package Assignment under the Creation Information header. Clicking on Local Object will link the package name where which you created the CDS in Eclipse ($TMP) to the service in your ERP system. Then, click the execute button and you will get the message that the service was created and its metadata was loaded successfully.

To verify, go back into the ABAP perspective in Eclipse and click on the check ABAP development object button. It will now display a message that an OData service has been generate.

If you click on the ODATA-Service link it will open a new window in your default browser and request that you log in with the appropriate user. Even if the extension of the OData reads sap-ds-debug=true your service is correctly exposed if it looks like the one displayed below.

If you change the extension to $metadata than you can view the OData service's metadata. It shows the names of all of the columns and queries. If you append the query name at the end of the URL you can see the data for each of the 18 airlines.

If you want to learn more about OData syntax please visit the documentation page at odata.org.


For more tutorial videos about What's New with SAP HANA SPS 11 please check out this playlist.


SAP HANA Academy - Over 1,300 free tutorials videos on SAP HANA, SAP Analytics and the SAP HANA Cloud Platform.


Follow us on Twitter @saphanaacademy and connect with us on LinkedIn to stay abreast of our latest free tutorials.

2 Comments
Labels in this area