Anda di halaman 1dari 29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

SAP YARD

YOUR BACKYARD FOR SAP TECHNICAL TIPS AND SOLUTIONS


HOME

SEE ALL POSTS

TUTORIALS

CODE SNIPPETS

KNOW THY YARD MEN

HELP FORUM

BOOKS & JOBS

SAP QUIZ
68
Shares

ABAP on SAP HANA. Part V. Deep Dive


into CDS Views
TOPICS: CDS Views With Input Parameters

Create A View In CDS

Enteremail

Subscribe

We Respect Your Privacy !

SEARCH

How To Build Core Data Services Views In ABAP On SAP HANA


How To Call ABAP CDS Views In ABAP Report On HANA
SAP HANA Core Data Service - SAP HANA Tutorial

http://www.sapyard.com/abaponsaphanapartv/

SAP ABAP For HANA


Follow@sapyard

1/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

POSTED BY: SAP YARD

JULY 25, 2016

SAPYard

Deep Dive into CDS Views


In our previous post on ABAP on SAP HANA Part IV, we tried to
understand why SAP came up with CDS Views when database views and
other views were already there. We learned the need of Core Data Services
and its advantages and its possible usage.
68
Shares

656likes

Liked

Youand2otherfriendslikethis

In this article, we would dive a little deeper on CDS View from an ABAPers
perspective.
By now we know, there are two components of CDS Views in HANA.
DDL SQL View : It is read-only classical database view which is visible in
ABAP Dictionary (SE11). It cannot be edited in SE11.
CDS View Entity: It is the DDL Source File and the actual CDS View. It is a
Database Object which is visible in Eclipse/HANA Studio/ADT and we cannot
view CDS View Entity in SE11. It covers the CDS Database view and makes
other attributes possible, such as authorization checks de ned in CDS view.
Before I show, how CDS View is created in HANA ADT, let me start with, how
CDS View can be deleted.

SAP ABAP LINKS

Abapinho

7MostPopular&FeaturedArticles

Question: Do we need to delete both the Dictionary DDL SQL and CDS
View individually?
Answer: No.

SAP HANA from Space

Question: Can we delete DDL SQL to delete the CDS View?


Answer: No.

Lazy and Smart ABAPers

Check the below image, I am trying to delete the DDL SQL which is created
when CDS View is created.
http://www.sapyard.com/abaponsaphanapartv/

Level

DELETING rows of the internal


table within the LOOP. Is it a
2/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

Taboo? A big NO NO?

Fiori App - An
Introduction from an
ABAPer
SAP HANA at Ground

68

Zero

Shares

ABAP on SAP HANA.


Part I. First Program in
ABAP HANA
Get Latitude and
Longitude of any place
using Google Map API in
SAP

NetworkedBlogs

Blog:
SAPYard
Topics:
Abap,Sap,Hana

Followourblog

HANA does not allow me to delete this independently. Generated DDL SQL
views cannot be deleted.
http://www.sapyard.com/abaponsaphanapartv/

3/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

WEB DYNPRO ABAP TUTORIALS

DECEMBER 26, 2014

Lets Web Dynpro.


Part V

NOVEMBER 24, 2014

68

Lets Web Dynpro.


Part IV

Shares

NOVEMBER 11, 2014

So we are left with CDS View entity. And you guessed it right. Check the
below images, we can delete CDS View entity.
Question: What happens to DDL SQL View when CDS View (DDL
Source) is deleted?
Answer: They are twins. They cannot be separated even by death.

Lets Web Dynpro.


Part III

NOVEMBER 5, 2014

Lets Web Dynpro.


Part ZZ

NOVEMBER 3, 2014

Lets Web Dynpro.


Part II

http://www.sapyard.com/abaponsaphanapartv/

4/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

DDL SQL is automatically deleted when the CDS View is deleted. Check the
image below, both are deleted in one go.

Also Read: Create your rst program in SAP HANA Studio/ADT/Eclipse.


http://www.sapyard.com/abaponsaphanapartv/

5/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

Now, let us see how we can create a CDS View. There are ample tutorials
available on this topic. We would be short and would show what is new, in
the below image.

68
Shares

In all other tutorials, you would see that DDL Source is below Dictionary. In
our image above, check it is below Core Data Services folder. HANA and SAP
are evolving at great pace. We need to keep up with their pace.

http://www.sapyard.com/abaponsaphanapartv/

6/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

http://www.sapyard.com/abaponsaphanapartv/

7/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

http://www.sapyard.com/abaponsaphanapartv/

8/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

The above images are self-explanatory. Let us pause at the nal step of the
wizard. As of now, SAP is kind enough to provide six templates for creating
the CDS View as per our need. ABAPers feared they might not be able to
learn SQL and remember the syntaxes. Look, SAP already thought for us.
ABAPers are not going anywhere.
In most of the tutorials on CDS View in other blogs, you might have seen
only rst 5 templates. You would nd the sixth template De ne Table
Function with Parameters now. SAP and HANA innovation team are really
fast (like their in-memory system)
. When you actually get a chance to
make your hand dirty in HANA ADT, do not be surprised if you nd more
that 6 templates.
Let us select the rst template De ne View and hit Finish button.
http://www.sapyard.com/abaponsaphanapartv/

9/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

Here system expects us to christen our DDL SQL View Name. We also need
to provide the data_source_name (i.e the table or view from where data
would be selected). As pointed out in the previous article, it is a good idea to
separate SQL View Name and actual CDS View Name. For consistency, we
name SQL View Name with DDLS and CDS View with CDSV. You might
have a different naming convention in your project.

http://www.sapyard.com/abaponsaphanapartv/

10/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

For our example the SQL View Name is YDDLS_WO_STAT and CDS View is
YCDSV_WO_STATUS.
Food for thought for all ABAPers
What is the maximum length of the name which we can give to the
SQL View Name?

68
Shares

Look at the rst four auto-generated lines. They precede with @. They are
called Annotation.
Additional information and properties can be speci ed to the CDS Views
using Annotations.For example @ClientDependent annotation lets us set
whether the CDS View is Client Dependent or not. In the above example, it is
client dependent (by default). Annotations also can be used for specifying
the Buffer Status (switched on/off) and Buffer Type (single/generic/fully) of
the CDS View.
Annotations enrich the data models with additional (domain speci c)
metadata.
In laymans words, Annotations are extensions of CDS to SQL.
Annotation AbapCatalog.sqlViewName is mandatory for the de nition of a
Core Data Services (CDS) view.
Also, check the Outline window section in the left side corner. It shows the
CDS views breakups. source data table / view, CDS View key and eld list.
Now, let us try to open the CDS View entity in SE11.

http://www.sapyard.com/abaponsaphanapartv/

11/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

Oops, it is not meant for Data Dictionary.


Open the DDL SQL CDS View in SE11.

http://www.sapyard.com/abaponsaphanapartv/

12/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

No problem to view it. We can even display the data pulled by the view.

http://www.sapyard.com/abaponsaphanapartv/

13/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

Also Read: Know SAP HANA Studio/ADT/Eclipse icons/buttons.


Transports for CDS View
Ok, while creating the CDS View, it asked for the transport where we wanted
to save our generated objects. What do you think, did both DDL SQL View
and CDS View entity get saved in that transport? Or do you think
otherwise?
Let us check it for ourselves.

http://www.sapyard.com/abaponsaphanapartv/

14/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

You can see, only the CDS View entity is saved in the transport.
All change objects and transports are managed in the ABAP layer end to end.
We do not need to go to the lower underlying database (HDB) level to
manage the transport of CDS entities/artifacts.
Join in CDS View
While creating the new CDS View, let us select the De ne View with Join
template. As discussed, we need to type our ABAP Dictionary (DDL) SQL
View name. In addition, we need to replace the auto-generated
data_source_name and joined_data_source_name along with its element
names.
http://www.sapyard.com/abaponsaphanapartv/

15/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

http://www.sapyard.com/abaponsaphanapartv/

16/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

For our example, we have joined the Status table and Status text. Join is the
same as we have been doing in ABAP.
Check the output of the Joined CDS View.

http://www.sapyard.com/abaponsaphanapartv/

17/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

Parameters in CDS View


ABAPers are familiar with the term Parameter. Just like we can have
PARAMETERs in the selection screen of a report, similarly we can have
Parameters on CDS Views. Do not be too optimistic, we do not have SELECT
OPTION in CDS View till now.
We know, Parameter helps to lter the data and is useful in WHERE Clause.
CDS View with Parameters is normally created to lter the data during
selection process at database level itself (i.e additional ltration is done using
http://www.sapyard.com/abaponsaphanapartv/

18/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

CDS View with Parameters). So, there is no need to put additional ltering
(where condition) at ABAP Layer. Code to Data shift (one of the motivations
of Core Data Services).
Let us see how we can de ne a CDS View with Parameter.

68
Shares

Choose the template De ne View with Parameters and provide the DDL SQL
View name (data dictionary) and data source name as done in above
examples. In addition to that, provide the parameter name and parameter
type. We can have multiple parameters in a CDS View, separated by a
comma.

http://www.sapyard.com/abaponsaphanapartv/

19/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

Check the usage of parameters in the above image. If we de ne CDS View


with multiple parameters separated by a comma, we can have multiple
parameters in the WHERE Clause separated by AND/OR. Also, note that $
sign needs to be provided with parameters while using it in WHERE Clause.

with parameters p_stat: j_status,


p_lang: spras

WHERE jcds.stat = $parameters.p_stat and tj02t.spras = $parameters.p_lang;

Les us see the DDL SQL View (data dictionary) for this CDS View with
Parameter and try to display the content output for this CDS View.

http://www.sapyard.com/abaponsaphanapartv/

20/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

68
Shares

Opps. Data display for views with parameters is not yet supported.
Hopefully, SAP would come up with this option too in near future.
There are other templates like View with Association, Extend View and
Table Function with Parameters. We can cover them some other day. If you
cannot wait, please check this external link. This has the exhaustive
demonstration of different CDS Views and its capabilities.
You might also like to check Debugging in SAP HANA
Studio/ADT/Eclipse.
Usage of CDS View in ABAP Programs
The last thing we want to cover today is how to consume a CDS View in
ABAP Program.

http://www.sapyard.com/abaponsaphanapartv/

21/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

We can use the CDS View like any other table or data dictionary view in
ABAP. I found the usage of CDS View with Parameters little tricky. Please
check the below code snippet for usage of CDS View with Parameters. Let me
accept up front that the below program does not show the real power of CDS
View. It is only for demonstration.

SELECT * FROM ycds_wo_stat_txt_para( p_stat = @p_status ) INTO TABLE @i_wo

68
Shares

You would notice below that @ symbol is used for escaping of host variables.
They help to identify ABAP work areas/variables/constants in Open
SQL statement. Literals need not be escaped using @. If we decide to
escape one host variable, all host variables should be escaped.
Also, we can select from both DDL SQL View and CDS View. So, we need to
declare the internal tables/work areas according to the View you intend to
use. Although DDL SQL View and CDS View are mirror images still you cannot
use the TYPE statement interchangeably in the program.
Question: In our previous article, we suggested that SE11 Data
Dictionary DDL SQL View should not be normally used. Why?
Answer: If we consume DDL SQL View in ABAP SELECT statement, then, it
will act as any other normal view/table which is created in data dictionary
using SE11. We would not be taking real advantage of HANA. We would not
see the performance improvement. Theoretically, when the DDL SQL View is
used, a database connection from ABAP Layer to Database Layer is
established and this process would consume some resources for database
connection (even though your database in HANA).
Question: Why is it good practice to use CDS View Entity (DDL Source)
while using ABAP SELECT statement?
Answer: By now we have a fair idea that CDS View Entity (DDL Source) is a
database object which is known to ABAP Layer and does not exist in data

http://www.sapyard.com/abaponsaphanapartv/

22/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

dictionary (SE11). This database object contains SQL power and resides
at the database layer. Consumption of CDS View by DDL Source name
invokes Database Object which is residing at Database Layer i.e., SQL inside
the DDL Source Name at Database layer (DDL Source). This way, we can
execute an SQL without creating a database connection between ABAP Layer
and Database. Only results will be transferred back to ABAP layer. This will
save resources for creating a database connection from ABAP Layer to
Database Layer.
68
Shares

I would like to request HANA Experts to provide some more insight and
justi cation of using CDS View Entity (DDL Source) in SELECTs.
Finally, the program to show usage of CDS View with Parameter.

*&---------------------------------------------------------------------*
*& Report YCDS_WO_STATUS_REPORT
*&---------------------------------------------------------------------*
*& Description: Demo to fetch data from CDS View with Parameter
*& Note: This program is just to show how CDS View can be used.
*& This does not depict the true strength (Core to Data Paradigm) of CDS
*&---------------------------------------------------------------------*
REPORT YCDS_WO_STATUS_REPORT.

*--------------------------DATA DECLARATION----------------------------*
DATA: i_wo_status TYPE STANDARD TABLE OF ycds_wo_stat_txt_para. " CDS Entity View
* DATA: I_WO_STATUS TYPE STANDARD TABLE OF YDDLS_WO_STAT_PA. " DDL SQL View (DDIC)

*&---------------------------------------------------------------------*
*&SELECTION SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
PARAMETERS : p_status TYPE j_status. " Status
SELECTION-SCREEN END OF BLOCK a01.

*&---------------------------------------------------------------------*
*& START OF SELECTION.

http://www.sapyard.com/abaponsaphanapartv/

23/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

*&---------------------------------------------------------------------*
START-OF-SELECTION.

* Select data using CDS View with Parameter


PERFORM sub_get_data_from_cds.

*&---------------------------------------------------------------------*
*& END OF SELECTION.
*&---------------------------------------------------------------------*
END-OF-SELECTION.

68
* Display data
Shares
PERFORM sub_display_data.

*&---------------------------------------------------------------------*
*& SUB ROUTINES
*&---------------------------------------------------------------------*

FORM sub_get_data_from_cds.
* Fetch from CDS Entity View
SELECT * FROM ycds_wo_stat_txt_para( p_stat = @p_status ) INTO TABLE @i_wo

* Fetch from DDL SQL data dictionary View


* SELECT * FROM YDDLS_WO_STAT_PA( P_STAT = @P_STATUS ) INTO TABLE @I_WO_STATUS.
ENDFORM.

FORM sub_display_data.

DATA:
lv_status_rel TYPE j_status VALUE 'I0002', " Release Status
lr_functions TYPE REF TO cl_salv_functions, " ALV Functions
lr_alv TYPE REF TO cl_salv_table, " ALV Functions
lr_display TYPE REF TO cl_salv_display_settings, " ALV Functions
lv_salv_msg TYPE REF TO cx_salv_msg. "ALV Functions.

* Display the final internal table in ALV


IF i_wo_status IS NOT INITIAL.
TRY.
* Factory Method
cl_salv_table=>factory( IMPORTING r_salv_table = lr_alv
CHANGING t_table = i_wo_status ).
http://www.sapyard.com/abaponsaphanapartv/

24/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

CATCH cx_salv_msg INTO lv_salv_msg.


MESSAGE lv_salv_msg TYPE 'E'.

ENDTRY.

* Self explanatory
lr_functions = lr_alv->get_functions( ).

lr_functions->set_all( abap_true ).

68
lr_display = lr_alv->get_display_settings( ).
Shares

lr_display->set_striped_pattern( cl_salv_display_settings=>true ).

lr_display->set_list_header( text-001 ).

* Actual Diplay
lr_alv->display( ).

ELSE.
MESSAGE 'No data found' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.

ENDFORM.

Please check this video from abap channel. This video speaks about CDS
Views with Parameters in more detail
If you want to get such useful articles directly to your inbox, please
SUBSCRIBE. We respect your privacy and take protecting it seriously.
If you liked this post, please hit the share buttons and like us on facebook.
Thank you very much for your time!!
Also, check our complete list of ABAP for SAP HANA Tutorials.
http://www.sapyard.com/abaponsaphanapartv/

25/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

33

68
Shares

Isn't it Fair to Share??


Related Posts:

Real Time Analytics

http://www.sapyard.com/abaponsaphanapartv/

26/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

Lets Web Dynpro.


Part II

Previous post

68
Shares

4 COMMENTS

Next post

ON "ABAP ON SAP HANA. PART V. DEEP DIVE INTO CDS VIEWS"

Sharath | July 25, 2016 at 9:19 am | Reply


Hello Raju,
I question is not related to HANA, but in the ABAP example I found
the event END-OF-SELECTION event. My concern is why to use this
event in ABAP 7.40? Why not move the code to START-OFSELECTION? What would be difference? Though this is a basic
question, could you please clarify on this?
Thanks.

SAP Yard | July 25, 2016 at 1:15 pm | Reply

http://www.sapyard.com/abaponsaphanapartv/

27/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

Dear Sharath Thank you for your message. In


our example there is no real advantage of the
event END-OF-SELECTION. We have written it
just to make it more readable and let our young
readers know that selection is over and now it time to display. If
you move to START-OF-SELECTION, there is not difference in
this case.
68
Shares

Regards,
Team SAPYard.

Venkat Boddu | September 22, 2016 at 1:29 am | Reply


Thanq.TeamIts Nice Article to learn ABAP Hana

SAP Yard | September 22, 2016 at 5:58 am | Reply


Dear Venkat Thank you for visiting our page.
Glad, you found our tutorials useful.
Regards,
Team SAPYard.

http://www.sapyard.com/abaponsaphanapartv/

28/29

10/30/2016

ABAPonSAPHANA.PartV.DeepDiveintoCDSViewsSAPYard

Comment, Criticism, Opinion, Feedback. Please do not


hold back. Share your Thoughts!!
Enteryourcommenthere...

68
Shares

COPYRIGHT 2016 | MH NEWSDESK LITE BY MH THEMES

http://www.sapyard.com/abaponsaphanapartv/

29/29

Anda mungkin juga menyukai