You are on page 1of 16

SAP S/4 HANA- HANA CLOUD PLATFORM

Create CDS View


30 min
Manju Venkatesha, Milton Chandradas

Description
In this exercise you’ll learn how to create CDS view using ADT and expose as an OData Service using
S/4 HANA system.

System prerequisites
 An account on the SAP S/4 System

Target group Target group requirements


 ABAP developers  Understanding of the OData interface
 People interested in the CDS view  Basic of programming skills
Create Create CDS View in SAP S/4 HANA
Prerequisite: ABAP Development Tools

Introduction
This exercise introduces the ABAP Development Tools (ADT) for SAP NetWeaver also known as
"ABAP in Eclipse". It is the recommended integrated development environment (IDE) for
developing ABAP applications for SAP HANA. This toolset is not mandatory for standard ABAP
development such as creation or maintenance of ABAP reports or ABAP classes. However, it
becomes mandatory for ABAP for SAP HANA development, e.g. for the creation of CDS views or
ABAP managed database procedures as you will see in the corresponding exercises later on. In
such development scenarios, the necessary features are only provided in ADT and not in the
ABAP Workbench (SE80).

The ABAP Development Tools provide a set of powerful tools for developing ABAP applications.
The tools (Eclipse editors and Eclipse views) are ideally positioned in the IDE to facilitate your
tasks.

Explanation Screenshot

1. Install latest Eclipse version Get an installation of Eclipse Neon (e.g. Eclipse IDE for Java
Developers)

2. Install ABAP Development Follow this link to install required tools.


Tools for SAP NetWeaver https://tools.hana.ondemand.com/neon
plugin for the Eclipse

2
Create Create CDS View in SAP S/4 HANA
Part 1: Create S/4 HANA System Connection

Explanation Screenshot

1. Open SAP Logon Pad.


Create an entry for S/4
HANA system connection

Description: S/4 HANA CAL


Application server :
vhcals4hci.dummy.nodomain
Instance :00
System id: S4H

Do not close the SAP Logon Pad.


Once we edit the hosts file, we will
verify the connection

2. Before starting the


Development Environment
ensure that your hosts file
is updated with the IP
address entry on the
handout.
You have to start notepad
as Administrator in order to
change the file. For doing
so, select the notepad
icon, press the right mouse
button, and select Run as
administrator.
3. Go to directory
C:\Windows\System32\driv
ers\etc, choose All Files,
and open the file hosts.

3
Create Create CDS View in SAP S/4 HANA

4. Add the following lines to #Power Week


the hosts file #S/4 HANA
35.157.157.252 vhcals4hci.dummy.nodomain vhcals4hci
vhcals4hcs.dummy.nodomain vhcals4hcs vhcalhdbdb
Your hosts file should now
vhcaldhbdb.dummy.nodomain
look like this…
35.157.34.9 vhcalj2eci.dummy.nodomain vhcalj2eci
vhcalj2ecs.dummy.nodomain vhcalj2ecs vhcalj2edb
Don’t forget to save the file! vhcalj2edb.dummy.nodomain

Note: If you have trouble


saving the file, then make
sure you opened Notepad
as Administrator
5. Now let us verify if we can
login to SAP GUI

Client: 100
User: developerXX
Password: Welcome1

Where XX is your student


number

You should be able to login


successfully. Do not
proceed if you are not able
to login successfully

6. Now, start Eclipse, your


Integrated Development
Environment (IDE).

7. Let’s start with the first step


– create an ABAP Project,
the central interface
between the IDE and the
ABAP backend system.

4
Create Create CDS View in SAP S/4 HANA

8. In the New ABAP Project


dialog, select your SAP
System from the list

Click Next

9. S/4 HANA system


connection details are
shown

Click Next

10. You are asked to provide your


logon information for system
S4H:
 Client: 100
 User: DEVELOPERXX
 Password: Welcome1
In principle, your project is
ready to use and you could
finalize the project creation.
However, it is helpful to
define a favorite package,
therefore, please press
Next instead of Finish.

5
Create Create CDS View in SAP S/4 HANA

11. Default Project is created


with your user id.

12. The ABAP Project is


created and you can see it
as a new (well, the only)
entry in the Project
Explorer view.

6
Create Create CDS View in SAP S/4 HANA
Part 2: Create a CDS view

This exercise introduces the CDS view definition capabilities of the AS ABAP 7.5.
In particular, you will learn about the features provided by ABAP CDS like aggregation functions
in the SELECT list, JOINs, UNIONs, the view-on-view capabilities, etc. The exercise is not
designed to give you a complete list, but only an initial peek into the long list of available
features in ABAP CDS.
To learn more about ABAP Core Data Services, see the ABAP language documentation.
As you will see in what follows, we will use the ABAP Development Tools (ADT) to create CDS
views, or more precisely Data Definition Language sources (DDLS). These units of code can
only be created and maintained using ADT, which is one of the reasons why we introduced the
ABAP Development Tools in detail in the previous exercise.
This exercise will show you several useful tips and tricks for working with the CDS editor.
In this exercise, you’ll:
 enhance an existing CDS view
 create a CDS view
o as a “view-on-view”. That is, a CDS view based on an existing CDS view
o that provides a customer classification based on sales order invoice information
 use the Data Preview on CDS views

Explanation Screenshot

1. To create CDS view, Right


click on the newly created
package.

7
Create Create CDS View in SAP S/4 HANA

2. Select ABAP -> Core Data


Services -> Data Definition
and click Next

3. On this page of the wizard


you s p e c i f y n a m e f or
C D S v i ew a n d
description

Package: $TMP
Name: ZXC_SOITEMS_XX
Description: Sales Order Items

Note: Replace XX with your


student number
.

Click on Next

We will use the following naming


convention…

ZX – to indicate it’s an SAP


development object
C – to indicate it’s a Consumption
View

8
Create Create CDS View in SAP S/4 HANA

4. We are not going to assign our


Object to any transport
request.

Click on Next

After clicking on next, the step


"Validating package" might
take a little while to complete

5. In the wizard select the default


template “Define View” and
click finish.

6. Default CDS view is created


with template.

7. Our CDS Consumption View @AbapCatalog.sqlViewName: 'ZX_VW_SOITEMS_XX'


@AccessControl.authorizationCheck: #NOT_REQUIRED
is going to be based on the
@EndUserText.label: 'Sales Order Items'
sepm_isoi view. Replace the @VDM.viewType: #CONSUMPTION
contents of the file with the
code snippet on the right pane
define view ZXC_SOITEMS_XX as
select from sepm_isoi as SOItems {
As you can clearly see, we
are now selecting from }
sepm_isoi

9
Create Create CDS View in SAP S/4 HANA

8. Let’s make some changes in


the source code of CDS.

Replace XX with your student


number. Note that there are 2
locations where you need to
replace your student number.

Note: In all subsequent


steps, if you notice XX,
replace it with your student
number

9. Press Ctrl + space for


intellisense

Select Insert all elements –


template and click Enter

This inserts all the columns in


our CDS Consumption View

10. Since we are all using Client


100, we can remove the line
SOItems.mandt

Your CDS view should now


look like this

11. We will mark @AbapCatalog.sqlViewName: 'ZX_VW_SOITEMS_XX'


@AccessControl.authorizationCheck: #NOT_REQUIRED
salesorderitemuuid as the key
@EndUserText.label: 'Sales Order Items'
field and also add some alias @VDM.viewType: #CONSUMPTION
to the column names.
Replace the CDS View with define view ZXC_SOITEMS_XX as
the code snippet on the right select from sepm_isoi as SOItems {
pane key SOItems.salesorderitemuuid,
SOItems.salesorderuuid as SalesOrderID,
Replace XX with your student SOItems.salesorderitem as ItemPosition,
number. Note that there are 2 SOItems.productuuid as ProductID,
SOItems.shorttextgroupuuid as NoteID,
locations where you need to SOItems.transactioncurrency as CurrencyCode,
replace your student number. SOItems.grossamountintransaccurrency as GrossAmount,
SOItems.netamountintransactioncurrency as NetAmount,
SOItems.taxamountintransactioncurrency as TaxAmount,

10
Create Create CDS View in SAP S/4 HANA

SOItems.productavailabilitystatus as StatusAvailability,
SOItems.opportunityitem as OpportunityItem

12. Save the changes (Ctrl + s)


and activate the CDS view
(Ctrl + F3).

Activation will take few


seconds. You should not see
any errors.

13. Right click on CDS view and


do the Data Preview.

14. You should see output as


shown.

15. Let us now create another


similar CDS view for Sales
Orders

To create another CDS view,


right click on the package and
select New -> Other

11
Create Create CDS View in SAP S/4 HANA

16. Select ABAP -> Core Data


Services -> Data Definition
and click Next

17. On this page of the wizard


you s p e c i f y n a m e f or
C D S v i ew a n d
description

Package: $TMP
Name: ZXC_SO_XX
Description: Sales Orders

Note: Replace XX with your


student number
.

Click Finish

We will use the following naming


convention…
ZX – to indicate it’s an SAP
development object
C – to indicate it’s a Consumption
View

18. Our CDS Consumption View @AbapCatalog.sqlViewName: 'ZX_VW_SO_XX'


is going to be based on the @AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Sales Orders'
sepm_iso view. Replace the @VDM.viewType: #CONSUMPTION
CDS View with code snippet
on the right pane define view ZXC_SO_XX as select from sepm_iso as SO {

}
As you can clearly see, we
are now selecting from
sepm_iso

12
Create Create CDS View in SAP S/4 HANA

19. Let’s make some changes in


the source code of CDS.

Replace XX with your student


number. Note that there are 2
locations where you need to
replace your student number.

Note: In all subsequent


steps, if you notice XX,
replace it with your student
number

@AbapCatalog.sqlViewName: 'ZX_VW_SO_XX'
20. Let’s add some columns to @AccessControl.authorizationCheck: #NOT_REQUIRED
the view with aliases and @EndUserText.label: 'Sales Orders'
also mark one of the @VDM.viewType: #CONSUMPTION
columns as the key. This is
define view ZXC_SO_XX as
similar to what we did with select from sepm_iso as SO {
the Sales Order Items CDS
view. key SO.salesorderuuid,
SO.salesorder as SalesOrderID,
SO.creationdatetime as DateCreated,
SO.shorttextgroupuuid as NoteID,
Replace CDS View with SO.customeruuid as CustomerID,
code snippet on the right SO.transactioncurrency as TransactionCurrency,
pane SO.grossamountintransaccurrency as GrossAmount,
SO.netamountintransactioncurrency as NetAmount,
SO.taxamountintransactioncurrency as TaxAmount
Replace XX with your }
student number.

21. Save the changes (Ctrl + s)


and activate the CDS view
(Ctrl + F3).

Activation will take few


seconds. You should not
see any errors.

22. Right click on CDS view and


do the Data Preview.

13
Create Create CDS View in SAP S/4 HANA

23. You should see output as


shown.

24. The only problem with our @AbapCatalog.sqlViewName: 'ZX_VW_SO_XX'


@AccessControl.authorizationCheck: #NOT_REQUIRED
Sales Order CDS view is that
@EndUserText.label: 'Sales Orders'
it knows nothing about either @VDM.viewType: #CONSUMPTION
the Business Partner (to whom
we have sold these goods) or define view ZXC_SO_XX as
the line items of the respective select from sepm_iso as SO
association [1..1] to sepm_ibupa as _BP on $projection.CustomerID
Sales Orders. = _BP.businesspartneruuid
Therefore, it would be a lot association [1..*] to ZXC_SOITEMS_XX as _SOITEMS on
$projection.salesorderuuid = _SOITEMS.SalesOrderID
more useful if we could join
this CDS view to the related {
data from both the Business
Partner table and our Sales key SO.salesorderuuid,
SO.salesorder as SalesOrderID,
Order Item CDS view.
SO.creationdatetime as DateCreated,
SO.shorttextgroupuuid as NoteID,
Replace CDS View with SO.customeruuid as CustomerID,
_BP.businesspartner as BusinessPartner,
code snippet on the right _BP.companyname as CompanyName,
pane SO.transactioncurrency as TransactionCurrency,
SO.grossamountintransaccurrency as GrossAmount,
SO.netamountintransactioncurrency as NetAmount,
Replace XX with your student SO.taxamountintransactioncurrency as TaxAmount,
number. Note that there are 3 _SOITEMS
locations where you need to
}
replace your student number.
Notice what has changed here:
1. Two new joins (associations) have been created
Your CDS view should now called _BP and _SOITEMS. These allow us to use the
look like this data in the Sales Order view to read related data from
the business partner table sepm_bupa and our
existing sales order item CDS view zxc_soi_DXX
respectively.
2. Various fields from the joins are then included in the
CDS view (business partner, company name and all
the sales order items)

14
Create Create CDS View in SAP S/4 HANA

25. Save the changes (Ctrl + s)


and activate the CDS view
(Ctrl + F3).

Activation will take few


seconds. You should not see
any errors.

26. Right click on CDS view and


do the Data Preview.

27. You should see output as


shown.

28. We have now successfully We created 2 CDS views:


created 2 CDS views  ZXC_SOITEMS
(ZXC_SOITEMS, ZXC_SO)  ZXC_SO
We also created two joins:
Congratulations !!  A one-to-many join called _SOITEMS between the Sales
Order CDS View (ZXC_SO) and the Sales Order Items CDS
View (ZXC_SOITEMS)
 A one-to-one join called _BP between the Sales Order CDS
View (ZXC_SO) and the business partner table (sepm_ibupa)

15
Create Create CDS View in SAP S/4 HANA

© 2014 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP
affiliate company. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries.
Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.

16

You might also like