Hi all,
SAP HANA is no more a new name or new Technology Jargon now. Most of us would be either have already started using it, are in mid of a transition to SAP HANA, have attended training or workshops or read blogs about the same.
SAP HANA (High-performance Analytic Appliance) is a multi-model database that stores data in its memory instead of keeping it on a disk. When we use SAP HANA with
4th Generation SAP Business Suite it's called
SAP S/4 HANA. Now, there is a lot of theoretical documentation, facts, information about what is HANA & S/4 HANA, how it works, what are pros & cons etc. There are lot blogs you can refer to get that information, if you are new or you want to know more about them.
In this blog we will majorly focus on getting our hands dirty quickly, avoiding theory as much as possible. And as the Title says, we will Create our very First Simple
CDS View on an
SAP S/4HANA On-Premise System. We will quickly do required setup, create a table, add some data, create a CDS View & finally preview the same.
Prerequisites
- I am assuming you already have an SAP S/4HANA On-Premise system.
- You have all the required access in the same.
IDE Setup
1. Installation
We will be using Eclipse as IDE for our development. SAP has a well-maintained Page to help you with the Setup, they call it :
SAP Development Tools: https://tools.eu1.hana.ondemand.com
But we are interested into
ABAP Side of things so we will Go for the
ADT Setup with
Eclipse
Here:
https://tools.eu1.hana.ondemand.com/#abap
So, you will be able to see the Prerequisites for the ADT Setup
Let's quickly download eclipse from
Here:
https://www.eclipse.org/downloads/packages/release/2022-12/r
We will download
Eclipse IDE for Java Developers from the page.
This will basically give a universal installer file for you (Assuming you are on Windows). You can either go by yourself or follow the
5 Steps Installation Guide by Eclipse.
Eclipse official Quick Installation Guide: https://www.eclipse.org/downloads/packages/installer
It will take some time & will finally show the JAVA VM & Installation folder.
2. Configuration
Click on Launch button & choose a desired
workplace, it's basically a location where your all projects will reside.
Note: Workplace location is different than installation location, but you can reuse same location, it's your choice.
Once selected, it will finally open the landing page.
We will navigate to Install new Software via Help.
Now, Enter the URL
https://tools.hana.ondemand.com/latest in Works with, choose
ABAP Development Tools & click on
Next.
https://tools.hana.ondemand.com/latest
It will ask to review installation, just click on
Next.
It will finally ask to review licenses,
Accept & click on
Finish.
This will start installation, can be tracked at bottom right corner.
It will finally ask to restart to apply all the changes, click to restart & you are good to go. Once restarted it will show the workspace click on
Launch & it will open
ADT (ABAP Development Toolkit) Overview Screen.
Note: Somehow if you don't land here
(ABAP Perspective), you can click Open Perspective Icon (Top Right Corner, shown below with red arrow), select
ABAP & click
Open.
And finally, you will be in
ABAP Perspective.
You are all set now to connect S/4 System & start Development.
Connect to S/4 System
Perquisites:
- Again, I am assuming you have the access to S/4 System with required accesses.
- You have SAP Logon on your system.
- You already have the system connection on your SAP Logon.
Click on
File -> New -> ABAP Project as shown below.
This will show all your existing
connection list, select your S/4 System from the List & click on
Next.
You will get the below screen, click on
Next.
Enter Client ID, your Credentials & click on Finish.
Congratulations, you will get the below screen, you are all set for the development now.
Development
We will go through 4 Steps to develop our CDS View from Scratch:
- Create an ABAP Package
- Create a Custom/Z Table
- Add Data to our Table
- Create a CDS View
Create an ABAP Package
Click on your
Project -> New -> ABAP package.
Choose a Package name starting with $Z* as it will be our Temporary package. Check to add it as your favorite package & click Next. Package type will be left as Development.
Now, click on finish without doing anything in the screen as we don't want
Transport Request.
Create a Table
Now let's create a Table, as existing table may or may not have data. So, we will create a new Table & use it for tutorial.
Right Click on your
Package -> New -> Other ABAP Repository Object.
Now type
Table then Select
Database table and choose
Next.
Choose a table name starting with
Z*, write description, click on
Next & then
Finish.
The Table will be created, it can be seen Under
Package->Dictionary->Database Tables.
Now let's add some
Fields, you can copy from below.
define table ztest_table {
key client : abap.clnt not null;
key emp_id : abap.numc(4) not null;
location_code : abap.char(1);
first_name : abap.char(15);
last_name : abap.char(15);
}
Finally, code should look like this.
Now
Save it using
Ctrl+S and
Activate it using
Ctrl+F3.
Congratulations, you have Successfully created your Table.
Add Data to your Table
There are different ways to do it but first we need to enable
Data Maintanence option.
By Default, Data maintenance would be set to
#RESTRICTED
We will need to change it to
#ALLOWED to enable Create Entries.
@AbapCatalog.dataMaintenance : #ALLOWED
Now you are all set to add some test Entries. There are multiple ways to do the same. But as we need few entries & want to do it quickly without any extra line of code, so we will use the
classic way to do it.
We will go to SAP Logon, login to our System, go to
SE11 transaction
, put our Table name
ZTEST_TABLE ( in my case ) & click on
Display.
Now, click on
Utilities-> Table Contents -> Create Entries
Fill up the fields & click on Save Icon to save.
We will add 4 Entries like this with 2 Employees of Same Location Code.
01 A Kapil Verma
02 A Rob Struas
03 B Isac Thaw
04 C Stan Lee
Now come back to Eclipse, right click on your
Table then click on
Open With -> Data Preview.
You will be able to see the created data like this in preview.
Create CDS View
Right Click on your
Package -> New -> Other ABAP Repository Object.
Start typing
Data Definition, choose
Data Definition below & click
Next.
Enter the
Name &
Description of the View, I am naming it as
ZEMPLOYEE_LOCATION_A as I will fetch employees who are from Location A. Click
Next and
Finish in next screen.
You will get the default code/output like below.
It will show
Error as its Default template & we will need to fill the required details.
We will add the
sqlViewName and the
data_source_name as shown below.
I'll use
ZEMP_LOC_A as
sqlviewname & our table created above for the
data_source_name. You can use
Ctrl+Space to AutoFill or get suggestions.
Finally, would look like below.
Now we will add required Fields to our CDS View. Syntax will be
data_source.field_name, again you can use
Ctrl+Space to get suggestions to add source & fields.
Syntax : data_source.field_name
We will be displaying EMP_ID, First name & Last name. Final code should look like below.
@AbapCatalog.sqlViewName: 'ZEMP_LOC_A'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Employees of Location Code A'
define view ZEMPLOYEE_LOCATION_A as select from ztest_table{
ztest_table.emp_id,
ztest_table.first_name,
ztest_table.last_name
}
Let's Save (Ctrl+S) & Activate (Ctrl+F3) our View to see if things are working correctly. Right Click on View, select Open With -> Data Preview.
You should get an output like below.
Right now, it is showing all the records, but we want the records only from
Location Code A, so let's put the
WHERE clause to do the same at the bottom like this.
where location_code = 'A'
Let's Save (Ctrl+S) & Activate (Ctrl+F3) our View and test these final changes. Right Click on View, select Open With -> Data Preview.
You should get an output like below.
You can see its only showing the Employees that belong to Location Code A.
Congratulations, we have successfully created a fully functional condition based CDS View.
( All the Records of the Table for your Reference )
Conclusion
Thanks for reading my blog. We started from scratch, did installations, configurations, created a table, inserted records & finally created a CDS View using our table. Hope, it will help anyone who want to code His/Her's very first kind of a Hello World CDS View with very basic pre-requisite that you have a system with required access. If you have any doubt, question or face any blocker while following the steps, you can leave a comment below, I will be happy to help you out. If you like my blog or found it helpful, please like & share it with those who will be interested in the same & do share your comments & suggestions to improve the same.
About me