Before you start with PART 2, I am sharing the link for part 1 for reference:
ABAP Core Data Service Views also known as ABAP CDS Views. There are so many limitations in SE11 views but we can come out of all the limitations and create a powerful views with the help of ABAP CDS Views.
In general SE11 views and ABAP CDS Views both will create a database views at the backend. When we try to access these views as a table in the ABAP code, this code will be executed at the database level.
Hence, SE11 views and ABAP CDS Views both will implement code push-down, In-spite of this, CDS views has many advantages in CDS views.
Below are the comparison between SE11 views and ABAP CDS Views:
|SE11 Views||CDS Views|
|1. It can be created from SAPGUI or Eclipse.
2. Calculated column are not possible.
3. Input Parameters are not possible.
4. Only Join is possible.
5. Grouping and aggregation are not possible.
6. Annotations are not possible.
|1. It can only be created from Eclipse platform only.
2. Calculated columns are possible.
B. CDS Function
C. CASE Expression D. Aggregated Functions
3. Input parameter are allowed.
A. In calculated Columns
B. For filtering data
4. Join and Union both are possible.
5. Grouping and aggregation are possible.
6. Annotation can be used to provide more metadata information to individual fields and Views.
ABAP CDS View creation:
We have seen basic ABAP CDS View creation in PART 1. Now we will see how to consume particular columns from a table, how to create the calculated column, how to use the parameters and how to use the CASE Expression in side the ABAP CDS View’s definition.
Below is the logic for CDS views:
I have divided above CDS logic into 6 block (A to F). Below is the explanation of these blocks:
These are the annotations automatically generated when you select the Defile View template during CDS views definition. As shown in below snap shot:
Key word to define parameter is With Parameters and parameter name. Along with it we have to define the parameter’s data type with the prefix ABAP.
Way to Select the individual columns from SPFLI table.
We can use Functions inside the CDS View and we can provide the alias as well.
We can use the case expression to provide the conditional logic while defining a column.
I have used the example : If Flight time is less then 100 Mins then Flight duration is Short and If Flight time is less then 300 Mins then Flight duration is medium else Flight duration is Long.
We can use the parameters which we have created in the B Block in a where clause to get the user input during execution of the CDS View.
There are 2 ways to use the parameter in the Where Clause:
- By prefixing colon : to the parameter.
- By using a structured variable $Parameter.
Running/Executing a CDS View:
There are 2 ways to execute the CDS View:
- From Development Perspective
- From ABAP Code
- From Development Perspective
You can simply press F8 to click on the highlighted button in the below snapshot:
and provide the value for the for the parameters.
Output of CDS Views:
2. From ABAP Code
Create a ABAP program by using below Open ABAP Code:
Output of ABAP Code:
With this example, we have completed the Second part of ABAP CDS VIEWS simplified.
Suggestions and questions are welcomed !!