Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
aparnami
Participant
Before you start with PART 2, I am sharing the link for part 1 for reference:

https://blogs.sap.com/2020/02/17/abap-cds-views-simplified-part-1/

INTRODUCTION:


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.
A. Operator
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:

A block:

These are the annotations automatically generated when you select the Defile View template during CDS views definition. As shown in below snap shot:



 

B block:

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.

C block:

Way to Select the individual columns from SPFLI table.

D Block:

We can use Functions inside the CDS View and we can provide the alias as well.

E Block:

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.

F Block:

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:

  1. By prefixing colon : to the parameter.

  2. By using a structured variable $Parameter.


 

Running/Executing a CDS View:


There are 2 ways to execute the CDS View:

  1. From Development Perspective

  2. From ABAP Code


 

  1. 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 !!
5 Comments
ascm
Explorer
A simple Report to View a CDS with SALV IDA.

 
report z_table_view.

*------------------------------------------------------------------------------------------------------
*
data g_table type dd02t-tabname.
data g_ddl type ddldependency-ddlname.

*------------------------------------------------------------------------------------------------------
*
selection-screen begin of block s with frame title text-001.
select-options s_table for g_table no intervals.
select-options s_ddl for g_ddl no intervals.
selection-screen end of block s.

*------------------------------------------------------------------------------------------------------
* TEXTS
* text-001 = Selection
* s_table = Tablename
* s_ddl = CDS Name

*------------------------------------------------------------------------------------------------------
*
start-of-selection.

if s_ddl[ 1 ]-low is not initial.
data(tablename) = conv dbtabl( s_ddl[ 1 ]-low ).
select single objectname
from ddldependency
where ddlname = @tablename
and objecttype = 'VIEW'
into @tablename.
if sy-subrc <> 0.
clear tablename.
endif.
elseif s_table[ 1 ]-low is not initial.
tablename = s_table[ 1 ]-low.
endif.

if tablename is not initial.
try.
data(salvida) = cl_salv_gui_table_ida=>create( iv_table_name = tablename ).

salvida->fullscreen( )->display( ).
catch cx_salv_db_connection cx_salv_db_table_not_supported cx_salv_ida_contract_violation cx_root into data(exception).

message exception type 'I'.

endtry.

endif.
aparnami
Participant
0 Kudos

Many thanks for providing this pseudo code.

Not only ALV WITH IDA reporting but we can consume CDS views in basic ABAP as well.

 

rcarlos89_
Explorer
Thank you very much Arpan for providing this useful and nicely formatted guide for those of use who are eager to learn about CDS views.
former_member744698
Discoverer
great blog... thanks for all the efforts that you put into this
user4sap
Participant
0 Kudos

Perfect Arpan thank you. This is better than to watch videos hours time.

Nice, simple and well structured cds view basiscs guide.

 

But I have a question. Can we now if we want consume this cds view in our html/javascript file? Or is it only consumeable with ui5 apps?

Labels in this area