Вы находитесь на странице: 1из 20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

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
136
Shares

ABAP on SAP HANA. Part IV. Core Data


Services
TOPICS: ABAP For Beginners
Core Data Services

Beginners SAP

CDS View In HANA

Enteremail

Subscribe

We Respect Your Privacy !

SEARCH

SAP ABAP Tutorial


Follow@sapyard

http://www.sapyard.com/abaponsaphanapartiv/

1/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

POSTED BY: SAP YARD

JUNE 27, 2016

SAPYard

Let us start our encounter with Core Data Services (CDS) View with
questions and answers. Before we explain What is CDS View, let us ask,
Why CDS View?
Question: Why do we really need CDS Views?
Answer: According to SAP, CDS Brings Conceptual and Implementation Level
Closer Together.
136
Shares

656likes

Liked

Youand2otherfriendslikethis

What does this mean?


Say our requirement is to get the id, name and the respective zip code of the
home address for all employees in org_unit 4711.
In order to meet this requirement, SQL developers write below SQL.
SAP ABAP LINKS

Abapinho

The issue with the above SQL: Large Semantic Gap between Requirement
and SQL Code.
If you are not an experienced SQL developer, you would nd it
complex/dif cult to understand the meaning/semantic of the SQL. Therefore
SAP wanted something simpler and better. This is one motivation for CDS.

7MostPopular&FeaturedArticles

SAP HANA from Space


Level
Lazy and Smart ABAPers

Being an ABAPer you nd the above SQL complex and you decide to write
your own Open SQL in ABAP.
DELETING rows of the internal
table within the LOOP. Is it a
http://www.sapyard.com/abaponsaphanapartiv/

2/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Taboo? A big NO NO?

Fiori App - An
Introduction from an
ABAPer

136
Shares

SAP HANA at Ground

Issue with the above Open SQL: SQL Complexity Leads to Imperative Code
(codes which are like instructions/statements which change its state.
Imperative programming focuses on describing how a program operates.)
There are performance concerns in the above Open SQL. Loops in loops,
nested queries with many round trips is not advisable. This is another
motivation for CDS.

Zero
ABAP on SAP HANA.
Part I. First Program in
ABAP HANA

Now, let us see how CDS would do the same task.


Same requirement: Get the id, name and the respective zip code of the home
address for all employees in org_unit 4711.

Get Latitude and


Longitude of any place
using Google Map API in
SAP

NetworkedBlogs

Blog:
SAPYard

With CDS, SQL developerssee small or no semantic gap and ABAPers do not
need any coding. You get the result directly from the CDS. Isnt this
motivation enough?

Topics:
Abap,Sap,Hana

Followourblog

Question: We already have Database Views in ABAP (SE11), then why


do we still need CDS views? Or, What are the advantages of using
http://www.sapyard.com/abaponsaphanapartiv/

3/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

CDS views?
Answer: CDS is much more powerful than what it appears. The CDS concept
is far more than simple view building but describes a DDL for building a metamodel repository involving database tables, database views, functions, and
data types.

136

CDS was invented by SAP, because the modeling capabilities of the ABAP
Dictionary and of the SAP HANA Studio are not suf cient for the needs
of all fully blown business applications with modern needs.

Shares

With HANA CDS, CDS is available for SAP HANA in the SAP HANA studio.
With ABAP CDS, the CDS concept is also made available for the AS ABAP,
where the features of CDS surpass the modeling capabilities of SE11. ABAP
CDS is open and not restricted to SAP HANA (i.e. database independent).
If we need meta-models for our application, that can be built with CDS, then
we need CDS views.
Question: OK, we read above that CDS was invented to facilitate needs
which ABAP Dictionary and HANA Studio could not meet. So, what are the
types of CDS Views?
Answer: There are two types of CDS Views.
1. ABAP CDS
2. HANA CDS
Check the details in CDS One Concept, Two Flavors

WEB DYNPRO ABAP TUTORIALS

DECEMBER 26, 2014

Lets Web Dynpro.


Part V

NOVEMBER 24, 2014

Lets Web Dynpro.


Part IV

NOVEMBER 11, 2014

Lets Web Dynpro.


Part III

NOVEMBER 5, 2014

Lets Web Dynpro.


Part ZZ

NOVEMBER 3, 2014

Lets Web Dynpro.


Part II

Also,CDS Views can be categorized as of two types:


1) CDS Views without Parameters
2) CDS Views with Parameters
(We will check the details of CDS View with and without Parameters in our next
article)
http://www.sapyard.com/abaponsaphanapartiv/

4/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Also Read: SAP HANA for Beginners from a Beginner.


Question: Why was CDS introduced? (same question in a different way)
Answer: With CDS, data models are de ned and consumed on the database
rather than on the server. CDS also offers capabilities beyond the traditional
data modeling tools, including support for conceptual modeling and
relationship de nitions, built-in functions, and extensions. Originally, CDS was
available only in the design-time and runtime environment of SAP HANA.
Now, the CDS concept is also fully implemented in SAP NetWeaver AS ABAP,
136
Shares enabling developers to work in the ABAP layer with ABAP development tools
while the code execution is pushed down to the database.
Question: Finally, What is Core Data Services?
Answer: CDS is an infrastructure layer for de ning semantically rich data
models, which are represented as CDS views. In a very basic way, CDS allows
developers to de ne entity types (such as orders, business partners, or
products) and the semantic relationships between them, which correspond
to foreign key relationships in traditional entity-relationship (ER) models.
CDS is de ned using an SQL-based data de nition language (DDL) that is
based on standard SQL with some additional concepts, such as associations,
which de ne the relationships between CDS views and annotations, which direct
the domain-speci c use of CDS artifacts. Another example is expressions,
which can be used in scenarios in which certain CDS attributes are
considered as measures to be aggregated.
Similar to the role of the DDIC in the traditional ABAP world, data models
based on CDS serve as central de nitions that can be used in many different
domains, such as transactional and analytical applications, to interact with
data in the database in a uni ed way . However, CDS data models go beyond
the capabilities of the DDIC, which were typically limited to a transactional
scope (think of traditional online transaction processing functionality). For
example, in CDS, you can de ne views that aggregate and analyze data in a
http://www.sapyard.com/abaponsaphanapartiv/

5/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

layered fashion, starting with basic views and then adding powerful views that
combine the basic views. Another difference is the support for special operators
such as UNION, which enables the combination of multiple select statements to
return only one result set.
CDS artifacts are stored in the DDIC and can be accessed in ABAP programs
via Open SQL in the same manner as ordinary ABAP tables or views.
136
Shares

In simple words:
Core data services are a new infrastructure for de ning and consuming
semantically rich data model in SAP HANA. Using a data de nition language
(DDL), a query language (QL), and an expression language (EL), CDS is
envisioned to encompass write operations, transaction semantics,
constraints, and more .

We can use the CDS speci cation to create a CDS document which de nes
the following artifacts and elements:
Entities (tables)
Views
User-de ned data types (including structured types)
http://www.sapyard.com/abaponsaphanapartiv/

6/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Contexts
Associations
Annotations
Question: When do we need CDS Views?
Answer: It depends on reusability. If the functionality of a view is only
needed once, then no need to create CDS Views. We can use Joins, SQL
expressions, subqueries etc in Open SQL for this code push down. But if we
want to reuse a view, need semantical or technical capabilities of CDS that
136
Shares exceed those of Open SQL (but we try to keep the technical capabilities on
the same level, e.g., CDS knows UNION, Open SQL will know UNION with an
upcoming release) or we just want to push down the full data model to the
database, we need CDS.
Question: What is the fundamental difference between HANA CDS and
ABAP CDS?
Answer: The subtle differences between CDS in native SAP HANA and CDS in
ABAP lies in the view de nition. In both the ABAP and HANA scenarios, views
are created on top of existing database tables that are contained in the
DDIC. With CDS in native SAP HANA, we must create the basic entity types that
correspond to the DDIC tables as part of the CDS view de nition. With CDS in
ABAP, we can refer to any underlying DDIC table, view, or type from within the
CDS view de nition, avoiding the need to duplicate the DDIC table de nitions
on the CDS layer. In the ABAP scenario, the CDS de nitions are considered
DDIC artifacts and need to be activated like any other DDIC artifact and
when changes are made, their impact is propagated to dependent artifacts.
Question:What is preferred ABAP CDS or HANA CDS if the client is in
ABAP on HANA DB?
Answer: If you use ABAP on HANA DB, you can work directly on the DB and
also use HANA CDS there. But then the CDS objects created are not managed
http://www.sapyard.com/abaponsaphanapartiv/

7/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

by the ABAP Dictionary meaning you cannot access them directly with Open
SQL and they are not TYPEs in the ABAP TYPE system.
Question: When should we use ABAP CDS and when should we use
HANA CDS?
Answer: If you run SAP HANA standalone or in a side-by-side scenario
(there is no ABAP stack on top) you cannot use ABAP CDS. You must use
HANA CDS.
136
Shares

If you have an ABAP stack on top of a HANA database (an AS ABAP uses the
HANA database as central database) then:
i) If you want to access the CDS entities in ABAP as data types or in Open
SQL or if you want to evaluate the CDS annotations in ABAP, you must use
ABAP CDS.
ii) If you do not want to access the CDS entities in ABAP, but you want to
transport and upgrade them like ABAP repository objects, you can use ABAP
CDS.
iii) If you do not want to access the CDS entities in ABAP as data TYPEs or in
Open SQL, you can use HANA CDS, which is better integrated into SAP
HANA. An access from ABAP is then possible using Native SQL (ADBC,
AMDP) only.
Question: Can we consume ABAP CDS natively in HANA?
Answer: Yes we can. For each CDS view a database view (SQL view) is created
in the database during activation. We can access that database view natively if
we want to. CDS table functions are managed by AMDP. The respective
database functions can also be accessed natively.
Question: Is it also possible to access the database views (generated by
having a corresponding ABAP CDS view) in HANA natively and

http://www.sapyard.com/abaponsaphanapartiv/

8/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

simultaneously consider the authorization logic de ned in the


corresponding DCL?
Answer: Yes. Open SQL checks the authorization implicitly but is of course
translated into native SQL code doing that on DB level (implicit conditions).
Same for the SADL framework that checks the authorizations itself natively.
The problem is that you need to have access to the internal role
representation which is not published and subject to change or you have to
build a framework yourself that parses the role de nition and creates the
136 corresponding conditions.
Shares

Also Read: Write your rst Program in SAP HANA.


Question: How can we nd all CDS views in SAP?
Answer: Check the table TADIR in SE16; PGMID = R3TR, OBJECT =
DDLS; here we nd all DDL sources and the package of each source in
column DEVCLASS. Knowing the package, we can use ADT (ABAP
Development Tool in HANA Studio) to nd the DDL sources in ADT.

http://www.sapyard.com/abaponsaphanapartiv/

9/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

136
Shares

Examine table DDLDEPENDENCY in SE16; it contains the names of all DDL


sources and the names of the CDS entities (value STOB in column
OBJECTTYPE) de ned therein as well as the names of the generated
database views (value VIEW in column OBJECTTYPE); (one row for each ->
two rows for each DDL source). => Selecting VIEW for OBJECTTYPE gives
you all CDS database views.

http://www.sapyard.com/abaponsaphanapartiv/

10/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Now let us try to open the DDL source of the CDS in SE11.

136
Shares

Check it would prompt us to go to ADT Tools to view it.


Now, let us open the DDL SQL View of the CDS. Note the warning below
which says DDL SQL views are only supported in a limited way by SE11.

http://www.sapyard.com/abaponsaphanapartiv/

11/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

136
Shares

Having one name is just not good enough in CDS; we need two names.
One name is for the SQL view that is going to be created in the dictionary
(the one we will be able to look at in SE11), and the other name we have is a
name for the CDS view entity, which is viewed and changed via Eclipse.
PS: We could name both the SQL view and the CDS view the same, but we
should not as they are different things, so the name should re ect the
difference.
SQL view is visible in SE11, however, we cannot edit it in SE11.
CDS View entity is the one we should refer to in SELECT statements in our
ABAP programs. Although we can use DDL SQL View in our programs, but
we should not.

http://www.sapyard.com/abaponsaphanapartiv/

12/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Question: How can we use CDS views?


Answer: Basically, a CDS View is an entity that can be addressed by its name:
in ABAP as a TYPE
in Open SQL as a DATA SOURCE
Basically, a CDS View is an entity that can be addressed by its name in ABAP
as a TYPE in Open SQL as a data source
136
Shares

Seeing a CDS View in SE11 is kind of a technical artifact and we should not
address the database view that is shown there in our ABAP programs. From
SE11 you can also navigate to the database object that is generated from the
de nition. This database object can even be accessed directly with Native SQL.
This means we can access our CDS Views directly in ABAP programs or from
elsewhere. For evaluating the semantic properties (annotations) of a CDS
View (stored in system tables) we should use an appropriate API
(CL_DD_DDL_ANNOTATION_SERVICE if available in your system).
The database views created from the CDS source code are merely for technical
reasons. The CDS source code and the CDS entity de ned there should be
the real thing.
Question: What are the Salient Features of CDS?
1. Semantically Rich Data-Models
2. Domain speci c languages (DDL, QL, DCL)
3. Declarative, close to conceptual thinking
4. CDS is completely based on SQL
5. Any Standard SQL features (like joins, unions, built-in functions) is
directly available in CDS
6. Fully Compatible with Any DB
7. Generated and managed SQL Views
8. Native integration in SAP HANA

http://www.sapyard.com/abaponsaphanapartiv/

13/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

9. Common Basis for Domain-Speci c Frameworke.g. UI, Analytics, Odata,


BW,@AnalyticsDetails.aggregationBehaviour: SUM
10 Built-in Functions and Code Pushdown
11 Table Functions for Breakout Scenarios
12 Rich Set of Built-in SQL Functions
13 Extensible
14 On model level thru extensions
15 On meta-model level thru annotations
136
Shares

Summary of Core Data Services


SAP claims that whereas a traditional database view is just a linkage of one
or more tables, a CDS view is a fully edged data model, which, in addition
to having extra features that SE11-de ned views do not, can be used even by
applications outside of the SAP domain.
Note: We cannot do OUTER JOINs in an SE11 database view (just one
limitation to point which CDS can overcome).
Technically, CDS is an enhancement of SQL which provides us with a data
de nition language (DDL) for de ning semantically rich database
tables/views (CDS entities) and user-de ned types in the database.
The enhancements include:
i) Annotations to enrich the data models with additional (domain speci c)
metadata.An annotation is a line of code that starts with an @ sign.
ii) Associations on a conceptual level, replacing joins with simple path
expressions in queries
iii) Expressions used for calculations and queries in the data model
CDS views, like the well-known dictionary views created and maintained in
transaction SE11, are managed by the ABAP data dictionary. During
activation, a database view is created on the HANA layer, yet only the ABAP

http://www.sapyard.com/abaponsaphanapartiv/

14/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

CDS view (de ned in a so-called DDL source) has to be transported via the
ABAP Change and Transport System (CTS). Moreover, the functionality
provided by CDS views can be used on all SAP supported databases, we dont
have to worry when transporting these objects in a heterogeneous system
landscape.
CDS views are entities of the ABAP CDS in the ABAP Dictionary that are
much more advanced than the classical SE11 views. We can in uence CDS
views with parameters that can be used at different positions of the DCL. As
136
Shares for classical SE11 views, for a CDS View, a platform dependent runtime object
is generated at the database that we can examine in SE11. When accessing a
(CDS) view with Open SQL (i.e ABAP), the database interface accesses this
runtime object. A CDS view is created with a source code based editor in Eclipse
using a DDL (which ha nothing to do with SQLScript).
For technical reasons, from the source code a classical DB view is generated in
SE11 that we can access like any classical view, but we shouldnt. Instead, the
so-called CDS entity should be accessed because it carries more meaning
than the mere technical DB view and involves new kind of client handling.
PS: In an upcoming release, the direct access to the DB view of a CDS view will
be declared as obsolete. So, better not to use them if it can be avoided.
We use CDS to model large parts of our application in the Dictionary and use
simple Open SQL SELECTs in ABAP for relatively straight joins and
subqueries in ABAP. Some day Open SQL might have the same power like
CDS but it doesnt mean that those are redundant. Already before CDS, we
had the choice between creating a reusable view in SE11 or programming a
join in Open SQL in ABAP. As a rule of thumb, we created a view if it is used in
more than one program and programmed a join when we needed it only once.
That is very similar for CDS, but with much more possibilities for modeling
semantically rich models for reuse in ABAP programs.
http://www.sapyard.com/abaponsaphanapartiv/

15/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

CDS is open. It is not restricted to HANA (but performance can be different


in different DB).
Hope these Q&A would help to clear out some cobwebs regarding Core Data
Services. In the subsequent articles, we would show how we can create the
CDS Views and use them in ABAP Programs.

136
Shares

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.

Source:
1. DEV200 Core Data Services TechEd 2015 session
2. Blogs and answers from SAP Expert Horst Keller
3. SAPInsider
4. GIThub

67

Isn't it Fair to Share??


Related Posts:

http://www.sapyard.com/abaponsaphanapartiv/

16/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Related Posts:

136
Shares

Real Time Analytics

Previous post

4 COMMENTS

Next post

ON "ABAP ON SAP HANA. PART IV. CORE DATA SERVICES"

http://www.sapyard.com/abaponsaphanapartiv/

17/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

NickNick | August 9, 2016 at 1:21 pm | Reply


Great set of articles, very useful and thanks a lot.
If I had a Calculation View in HANA, how would that relate to a CDS
View?
136

vinay singh | August 23, 2016 at 4:31 pm | Reply

Shares

Hello Nick,
Thanks for reading our Blogs.
SAP HANA Live uses native SAP HANA SQL views,so they are
maintained via HANA Studio. CDS views SAP HANA S/4HANA
Embedded Analytics is based on ABAP-managed core data
services (CDS) of the ABAP layer of SAP. S/4HANA. CDS views
can be maintained in ABAP for Eclipse.you can consume both
via the Fiori.
Regards,
Team SAPYARD

Sam | September 16, 2016 at 11:49 pm | Reply


http://www.sapyard.com/abaponsaphanapartiv/

18/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

Is this statement: CDS View entity is the one we should


refer to in SELECT statements in our ABAP programs.
Although we can use DDL SQL View in our programs, but
we should not. correct ? I am not able to de ne the TYPE of the
internal table when using the CDS entity but I can use the TYPE
corresponding to DDL SQL View (as seen in SE11) when I use it for
OpenSQL statement.
136
Shares

SAP Yard | September 17, 2016 at 1:43 pm | Reply


Dear Sam Yes the statement is correct. What is
the error message you are getting? Can you please
share your code snippet (email at mailsapyard@gmail.com)
We have check in our system as show in below code snippet.
*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)
*DATA SELECTION-*
* Fetch from CDS Entity View
SELECT * FROM ycds_wo_stat_txt_para( p_stat = @p_status )
INTO TABLE @i_wo_status.
* Fetch from DDL SQL data dictionary View
* SELECT * FROM YDDLS_WO_STAT_PA( P_STAT = @P_STATUS )

http://www.sapyard.com/abaponsaphanapartiv/

19/20

10/30/2016

ABAPonSAPHANA.PartIV.CoreDataServicesSAPYard

INTO TABLE @I_WO_STATUS.


Please check our next article with code snippet for select from
both CDS and DDL.
SAP ABAP on HANA. Part V. Deep Dive into CDS View
Regards,
Team SAPYard.
136
Shares

Comment, Criticism, Opinion, Feedback. Please do not


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

COPYRIGHT 2016 | MH NEWSDESK LITE BY MH THEMES

http://www.sapyard.com/abaponsaphanapartiv/

20/20

Вам также может понравиться