Nothing Special   »   [go: up one dir, main page]

0% found this document useful (0 votes)
387 views52 pages

Abap On Hana

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 52

The below explanations are as per our understanding.

We would like to appeal our experienced ABAPers to


throw some more light to the below answers if they know more about it.

Q: What is HANA Studio and what is the need of HANA Studio?


1. HANA as a database has evolved manifold in the last few years. In order to keep pace with these
hardware and software innovations, HANA Studio is introduced. HANA Studio provides the right
environment for HANA administration, modeling and data provisioning.

Studio is needed so that the developers can create models, procedures etc using the Eclipse-based tool in
HANA. Studio is also utilized to develop SQL Script which writes Application logic that would push down
data-intensive queries and logic to HANA database and improves the overall performance of the system.

Studio also provides monitoring and other tracing facilities.

Also, the Studio gives freshness to developers who were bored with the blue GUI screen editor. (on a
lighter note)

Hopefully, you have some idea of HANA Studio and its need.

Q: What is ADT and what is the need of ADT?


2. ABAP Development Tool is the full form of ADT. ADT provides eclipse base ABAP Integrated
Development Environment (IDE).

ADT does not come by default. It has to be installed as a plugin on Eclipse (in Studio -> Help -> Add New
Software).

We need ADT because with ADT in Eclipse, the HANA Studio becomes super powerful. You can connect
to different ABAP systems from single Eclipse User Interface. Isnt it cool? With ABAP perspective in the
studio, you can implement end-to-end in-memory solutions in Studio with the same UI.

One entry point and multiple benefits. Dont you like it?

Q: Seems ADT does the same thing like SE80 T-code. Then why do we really need ADT?
3. You are right. Both ADT and SE80 have same source code repository and locking mechanism and thus
both compliment each other. But ADT is more powerful than SE80. Some advanced features like creating
external views for exposing HANA view to ABAP DDIC* (external views), creating Database proxy
procedures* are available only when using ADT.

SE80 has been with SAP from birth. ADT is new and still has some enhanced features. SAP is continuously
working on more exclusive features which would be possible only from ADT in future. So, ADT is the future

Also Read : View the HANA Views from different angles

Q: What are perspective in HANA Studio?


4. In laymans term, perspectives are predefined layouts for different roles. For example, we have ABAP
perspective for ABAP developers. Java perspective for Java developers. Debug perspective for debugging.
Modeler for modeling in SAP HANA. Administration console for Admin tasks etc. So, every member of the
team would use the perspective as per his job role, responsibilities and activities they need to perform.

Q: In which perspective can we create/change/display ABAP programs?

5. You guessed it right!! ABAP perspective. So obvious, right?


Bonus question . Can we directly write and execute ABAP program in HANA studio?

No, it has to be connected to an ABAP system first. So, what helps Eclipse to connect to ABAP system? The

answer is ABAP Project. Did you expect this answer? ABAP project helps to connect the Eclipse
base IDE to ABAP backend system. The project provides eclipse based frameworks for creating, processing
and testing development objects.

In short, ABAP project represents a system logon and contains all ABAP development objects of the related
system.
Check this image below. Project S4H_800_SIMPLE3_SAPYARD is our project which is connected to our
S4H system.

Similarly, we can have multiple projects pointed to multiple systems from one HANA Studio UI.

Q: How do we view ABAP programs in HANA Studio?


6. Check there is an ABAP program YSAPYard in ABAP system (Left side). We can see the same program
from our Project which is connected to the same ABAP system. Expand the System Library and go to your
custom package and program.
Check, we can view the same program in GUI and HANA Studio.

Q: Can we edit the same program in GUI and in HANA Studio simultaneously?
7. No, we cannot edit the same program simultaneously. Both ADT and SE80 have same source code
repository and locking mechanism (as mentioned in answer 3), therefore, we cannot interfere when other is
editing it at the same time.

You get the below error in ADT if you try to edit the already opened program (in GUI).

Finally, the much-awaited question by the ABAPer..

Q. How can we write ABAP programs using ADT and execute it?
8. Select the Package where you want to save your program. Right-click on it and select ABAP Program.
Give the name and description of the program. Do not forget, the Z* or Y* naming convention holds good
even while creating custom objects from ADT.
You need to choose the transport where you want to save your program.

Write your program and check the syntax and activate it. Most of the icon are similar to GUI. Done, your
program is ready in Studio. Actually, you created the program just like in SE38/SE80, just the front end was

different. You can go to your ABAP system and check, the new program exists there.

Execute the RUN icon in HANA studio and your program would show the output.

Congrats, you created your first program in SAP HANA and executed it successfully. Although this was a
dummy program, in actual projects as well, the process remains the same.

In the SAP ABAP on HANA Part I, we talked about some common questions and answers. We also created
our first program in HANA Studio. In this article, we would get accustomed with the HANA Studio screen,
various buttons and icons. How/Why to use them and also we would try to correlate the functionalities of
HANA screen icons to that of classic GUI icons.

HANA Studio Toolbar


Most of the icons are self-explanatory.

Open ABAP Development Object: The system-wide search for development objects is possible.

Search: The workspace-wide search for development objects is possible. With this function, we can search
for ABAP development objects across all usable ABAP projects.

A. What is NOT there in ADT Eclipse/HANA Studio, which was available in ABAP GUI editor?

1. Change/Display Icon
We were not able to figure out the change/display toggle icon in HANA Studio ABAP editor. Whenever we
opened the program in our development system, it opened in change mode. If any reader knows about the
change/display icon (or shortcuts) in eclipse, please do mention it in the comment section or email us and
educate all.

2. Pattern Icon
Another significant button which we could not figure out in HANA Studio is the Pattern Icon. When we
want to auto generate the FM/Class/Method or any custom pattern, we are so habituated to use this Pattern
icon in ABAP editor. We were little surprised, not to find this commonly used button. But you need not be
disappointed. Type initial letters of the syntax you want to use and then use Ctrl + Space and Shift + Enter
to insert the full signature (e.g. for function module / method selected).
3. Pretty Printer
There is no pretty printer icon. How would developers impress their team leads and quality reviewers

without the pretty printer? Do not worry, the pretty printer button might not be there, but the
functionality still exists. Go to Windows -> Preference -> ABAP Development -> Source Code Editor ->
Formatter to set up the formatting needs.

You might not see the Formatter option upfront. You need to click on Source Code Editors. Then you would
see settings for different options (number 5 in above image) and Formatter is one of them.

Once you set the format, Shift + F1 is the shortcut for the desired formatting.

So, Pretty Printer in GUI = Shift + F1 in HANA Studio


These are some commonly used icons/buttons which are missing in Eclipse ADT. Please note, this is not the
whole elaborate list.

B. Check the common/similar or near similar features in Vanilla ABAP editor and Eclipse/HANA
Studio ABAP editor

1. Outline View
Let us start with the Outline View in HANA Studio. Check the outline view on the lower left corner of the
studio.

The Outline view displays the internal structure of a program or class that is currently open in the ABAP
source code editor. The Outline view is synonyms to the Object detailed screen of ABAP editor in SE80.
Just like when we click any element on SE80, it takes to that element in the main program, similarly, the
outline is synchronized with the contents of the editor. Hence, when an element in the Outline view is
selected, we can navigate quickly to the corresponding position in the ABAP source code.

Just like in SE80 editor, for each element in Outline View in Studio, we can navigate to the declaration part
in the source code editor or the implementation part (e.g. in the case of methods of a class).

2. Keyword Completion/Suggestion
Just like in GUI, ABAP editor on HANA studio suggests keywords as you type the syntax. The GUI
shortcut Ctrl +Space holds good in eclipse too.
3. Where-Used List
This powerful feature is still available.

4. Revision History.
Like in GUI ABAP editor, we can compare changes from one transport of source code to another in ADT.
Right click on the source code area of the program and choose Compare with -> Revision History.
4. Transport Organizer
Transport Organizer in ADT for Eclipse enables ABAP developers to perform the below Transport related
operation through Studio.
i) Adding user to Transport request (TRs)
ii) Changing owner of TRs and tasks.
iii) Checking consistency
iv) Releasing and deleting TRs
Right-click on the transport to see all the activities you can perform. One example of adding a user under an
existing transport is shown below.

Limitation of Transport Organizer in HANA Studio:

Transport request CANNOT be created within the Transport Organizer view of ABAP Development Tools.
But, if you create/edit an object (say table/program/FM/package etc) in Studio ADT and it asks for a new
transport, you can create new transport within that corresponding wizard. Remember, transports can be
created from those wizards and not stand alone from Transport Organizer.

[ad2ToAppearHere]

Advantage of Transport Organizer in HANA Studio:

The Search option in the Transport Organizer. Any object (table/program/FM/package etc) can be searched
for, to check the TR and task it belongs to. In SAP GUI transaction SE10, we cannot search that easily.
Although we have other t-codes and ways to figure it out. But the ease and user experience in Transport
Organizer in HANA Studio is unmatched.

Read more: SAP HANA at Ground Zero

C. The new features in Eclipse/HANA Studio ABAP editor, which were not available in GUI editor.

1. Syntax Error Marker:


Check the red cross on the left side of the code editor. This feature warns you of any error lines while you
are typing your program and even before you hit the syntax checker. This comes really handy for the
ABAPers to type the right syntax as and when he/she is.

2. Local code comparison:


Compares current saved version with the selected saved version.
Right click on the code area of the program and choose Compare with -> Local History. Choose one of the
previously saved version and see the comparison. This local change history gives the comparison between
saves in the ADT, showing changes in the code as stored in the local workspace.

Check, the code difference can be so easily identified.


3. Rename elements/texts.
Although we have Find and Replace (or Ctrl + H) option in SAP GUI, but Eclipsed based ADT has better
renaming experience. Just right click on the source editor and select Rename or hit Alt+Shift+R, to open the
replace wizard.

Select the element you want to replace and hit Rename (Alt+Shift+R), give the new name for the element
and hit Next.
Before it finishes, it would show the Original code and the new code after the change. It would also show all
the lines which would be changed.

Hit Finish and the element is renamed throughout the entire source code.

Summary of some prominent misses and inclusions


All the standard debugging features which were earlier available in GUI editor are also available in eclipse.
Such as:
i) Set breakpoints
ii) Step through the code
iii) Display and change variable values
iv) View internal tables
v) Monitor the call stacks

Salient Properties of ADT breakpoints:

The breakpoints in ADT are User External breakpoints, so:


i) They are valid in your ABAP project
ii) Programs running under your ABAP user
iii) On all App servers in the backend system

Two types of breakpoints in ADT:

1. Static Breakpoint
Static breakpoints are set at a particular line of the code. A static breakpoint stays with the line of code at
which you set it. If you delete code lines above the breakpoint, it slides along with the relocated code at that
particular line.

2. Dynamic Breakpoint
Dynamic breakpoints are determined at run time. They are triggered when the running program reaches a
particular ABAP statement e.g. loop, perform, select, calls, submits etc.
Please note: Dynamic breakpoints take effect for all programs that run under your user. You need to be
careful to remove the dynamic breakpoint once you have finished your analysis. Or else, it would stop for
any application where the dynamic breakpoint condition is found. And we are sure, you do not want speed

breakers in a highway. We can always limit the scope of dynamic breakpoints to the scope of the
debugger.

Advantage of ADT debugger:


One feature of the debugger in ADT is that you can work with the source code in debug mode as you work
in ABAP perspective. That means, when you see a bug in the code during debugging, you can correct your
code in the same editor in the same screen. Unlike traditional GUI debugger, where you need to go to
SE38/SE37/SE80 etc in a separate session to change the code.

[ad1ToAppearHere]

Hands On Section:
Enough of preaching!! Well, above are the theories and I am sure you would be more interested in looking at
the actual screens. Let us have a quick look at the Debugger screen and substantiate our understanding.

1. Check the icons/buttons which you can see during debugging:


All the buttons are self-explanatory.

Resume button : Run to the next breakpoint or to the end of the program.
Terminate button : Abort the execution of the program in the debugger. Program execution ends.
Disconnect button : Run to the end of the program, ignoring any intervening breakpoints.
Step Into (F5) button : Execute the next single ABAP instruction in the program in the debugger.
Step Over (F6) button : Execute the next ABAP statement. If the next step is a procedure call, run the entire
procedure.
Step Return (F7) button : Run until the current procedure returns to its caller or until the program ends.
Run to Line (Shift F8) button : Run to the statement on which the cursor is positioned. Breakpoints in
between will be respected or not is set in Windows->Preferences->ABAP Development->Debug.

Also, check ABAP on HANA. Part II to get accustomed to HANA Studio.

2. Put Static Breakpoint


Double click on the area shown below or right click and choose Toggle Breakpoint or press Ctrl + Shift +
B.
3. Execute the program
You would get this pop-up. Select OK and continue. The debugger stops at the breakpoint.

4. Check the Variables view, Debugger editor, Breakpoints view, Debug perspective etc
You can change the values of variables at the run time as you used to do in ABAP GUI debugger. You can
also move the cursor over the variable to display its value.
[ad2ToAppearHere]

5. Check the ABAP Internal Table (Debugger) view


Double click on the internal table name and see the values in the internal table view.
You can also right click on the internal table name and choose Open Data Preview to see the values of the
internal table.
[adToAppearHereLink]

6. Lets set a Dynamic Breakpoint

Go to the Breakpoints View and Add dynamic breakpoints at the statements you need. Type the statment in
the search area and get your dynamic statements.
See two examples of dynamic breakpoint below.
7. Manage the Breakpoint Properties of a particular breakpoint
Manage breakpoints using Breakpoints View. Right click on the breakpoint and choose the Breakpoint
Properties and choose the restriction you want.

8. Manage the Debug Properties for the user/session


You can change the user for which external breakpoints are effective. Breakpoints cab also be effective for
the entire project independent of the users.
Question: Why do we really need CDS Views?
Answer: According to SAP, CDS Brings Conceptual and Implementation Level Closer Together.

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.

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

Being an ABAPer you find the above SQL complex and you decide to write your own Open SQL in ABAP.

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.

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.

With CDS, SQL developers see small or no semantic gap and ABAPers do not need any coding. You get the

result directly from the CDS. Isnt this motivation enough?

[ad1ToAppearHere]

Question: We already have Database Views in ABAP (SE11), then why do we still need CDS views?
Or, What are the advantages of using 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 meta-model repository involving database tables, database
views, functions, and data types.

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

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

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)

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 defined 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 definitions, 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, 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 defining semantically rich data models, which are represented as
CDS views. In a very basic way, CDS allows developers to define 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 defined using an SQL-based data
definition language (DDL) that is based on standard SQL with some additional concepts, such as
associations, which define the relationships between CDS views and annotations, which direct the domain-
specific 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
definitions that can be used in many different domains, such as transactional and analytical applications, to
interact with data in the database in a unified 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 define views that aggregate and analyze data in a
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.

Also Read: Create you first SAPUI5 App and Consume a Custom OData Service without any code

In simple words:
Core data services are a new infrastructure for defining and consuming semantically rich data model in SAP
HANA. Using a data definition 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 specification to create a CDS document which defines the following artifacts and
elements:

Entities (tables)
Views
User-defined data types (including structured types)
Contexts
Associations
Annotations

[ad2ToAppearHere]

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 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
definition. 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 definition. With CDS in ABAP, we can refer to any
underlying DDIC table, view, or type from within the CDS view definition, avoiding the need to duplicate
the DDIC table definitions on the CDS layer. In the ABAP scenario, the CDS definitions 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 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.

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 simultaneously consider the authorization logic defined 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 definition and
creates the corresponding conditions.

Also Read: Write your first Program in SAP HANA.

Question: How can we find all CDS views in SAP?

Answer: Check the table TADIR in SE16; PGMID = R3TR, OBJECT = DDLS; here we find 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 find the DDL sources in ADT.

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) defined 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.

Now let us try to open the DDL source of the CDS in SE11.
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.
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 reflect 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.

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

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 definition. 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 defined there should be the real thing.
Question: What are the Salient Features of CDS?
1. Semantically Rich Data-Models
2. Domain specific 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
9. Common Basis for Domain-Specific Framework e.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

[ad3ToAppearHere]

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 fledged data model, which, in addition to having extra features that SE11-defined 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 definition language (DDL) for
defining semantically rich database tables/views (CDS entities) and user-defined types in the database.
The enhancements include:
i) Annotations to enrich the data models with additional (domain specific) 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 CDS view (defined 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 influence CDS views with parameters that can be used at different positions
of the DCL. As 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.

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

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 defined in CDS view.

Before I show, how CDS View is created in HANA ADT, let me start with, how CDS View can be deleted.

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

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


Answer: No.

Check the below image, I am trying to delete the DDL SQL which is created when CDS View is created.
HANA does not allow me to delete this independently. Generated DDL SQL views cannot be deleted.
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.


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 first program in SAP HANA Studio/ADT/Eclipse.

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.
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.
The above images are self-explanatory. Let us pause at the final 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 first 5 templates. You would
find the sixth template Define 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 find more that 6 templates.

Let us select the first template Define View and hit Finish button.
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.

For our example the SQL View Name is YDDLS_WO_STAT and CDS View is YCDSV_WO_STATUS.

Also Read: Create your first SAPUI5 and Consume Custom OData Service with NO code

Food for thought for all ABAPers


What is the maximum length of the name which we can give to the SQL View Name?

Look at the first four auto-generated lines. They precede with @. They are called Annotation.

Additional information and properties can be specified 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 specific) metadata.

In laymans words, Annotations are extensions of CDS to SQL.

Annotation AbapCatalog.sqlViewName is mandatory for the definition 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 field list.

Now, let us try to open the CDS View entity in SE11.


Oops, it is not meant for Data Dictionary.

Open the DDL SQL CDS View in SE11.

No problem to view it. We can even display the data pulled by the view.
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.


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 Define 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.
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.

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 filter the data and is useful in WHERE Clause.

CDS View with Parameters is normally created to filter the data during selection process at database level
itself (i.e additional filtration is done using CDS View with Parameters). So, there is no need to put
additional filtering (where condition) at ABAP Layer. Code to Data shift (one of the motivations of Core

Data Services).

Let us see how we can define a CDS View with Parameter.

Choose the template Define 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.
Check the usage of parameters in the above image. If we define 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.

1
2 with parameters p_stat: j_status,
3 p_lang: spras
4
5 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.
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.

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.

1
2 SELECT * FROM ycds_wo_stat_txt_para( p_stat = @p_status ) INTO TABLE @i_wo_status.

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.

Also Read: End to End Config and Implementation of Two Fiori Apps with NO code
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 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.

I would like to request HANA Experts to provide some more insight and justification of using CDS View
Entity (DDL Source) in SELECTs.

Finally, the program to show usage of CDS View with Parameter.

1
2 *&---------------------------------------------------------------------*
3 *& Report YCDS_WO_STATUS_REPORT
4 *&---------------------------------------------------------------------*
5 *& Description: Demo to fetch data from CDS View with Parameter
6 *& Note: This program is just to show how CDS View can be used.
7 *& This does not depict the true strength (Core to Data Paradigm) of CDS
8 *&---------------------------------------------------------------------*
9 REPORT YCDS_WO_STATUS_REPORT.
10
11 *--------------------------DATA DECLARATION----------------------------*
12 DATA: i_wo_status TYPE STANDARD TABLE OF ycds_wo_stat_txt_para. " CDS Entity View
13 * DATA: I_WO_STATUS TYPE STANDARD TABLE OF YDDLS_WO_STAT_PA. " DDL SQL View
14 (DDIC)
15
16 *&---------------------------------------------------------------------*
17 *&SELECTION SCREEN
18 *&---------------------------------------------------------------------*
19 SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
20 PARAMETERS : p_status TYPE j_status. " Status
21 SELECTION-SCREEN END OF BLOCK a01.
22
23 *&---------------------------------------------------------------------*
24 *& START OF SELECTION.
25 *&---------------------------------------------------------------------*
26 START-OF-SELECTION.
27
28 * Select data using CDS View with Parameter
29 PERFORM sub_get_data_from_cds.
30
31 *&---------------------------------------------------------------------*
32 *& END OF SELECTION.
33 *&---------------------------------------------------------------------*
34 END-OF-SELECTION.
35
36 * Display data
37 PERFORM sub_display_data.
38
39 *&---------------------------------------------------------------------*
40 *& SUB ROUTINES
41 *&---------------------------------------------------------------------*
42
43 FORM sub_get_data_from_cds.
44 * Fetch from CDS Entity View
45 SELECT * FROM ycds_wo_stat_txt_para( p_stat = @p_status ) INTO TABLE @i_wo_status.
46
47 * Fetch from DDL SQL data dictionary View
48 * SELECT * FROM YDDLS_WO_STAT_PA( P_STAT = @P_STATUS ) INTO TABLE
49 @I_WO_STATUS.
50 ENDFORM.
51
52 FORM sub_display_data.
53
54 DATA:
55 lv_status_rel TYPE j_status VALUE 'I0002', " Release Status
56 lr_functions TYPE REF TO cl_salv_functions, " ALV Functions
57 lr_alv TYPE REF TO cl_salv_table, " ALV Functions
58 lr_display TYPE REF TO cl_salv_display_settings, " ALV Functions
59 lv_salv_msg TYPE REF TO cx_salv_msg. "ALV Functions.
60
61 * Display the final internal table in ALV
62 IF i_wo_status IS NOT INITIAL.
63 TRY.
64 * Factory Method
65 cl_salv_table=>factory( IMPORTING r_salv_table = lr_alv
66 CHANGING t_table = i_wo_status ).
67
68 CATCH cx_salv_msg INTO lv_salv_msg.
69 MESSAGE lv_salv_msg TYPE 'E'.
70
71 ENDTRY.
72
73 * Self explanatory
74 lr_functions = lr_alv->get_functions( ).
75
76 lr_functions->set_all( abap_true ).
77
78 lr_display = lr_alv->get_display_settings( ).
79
80 lr_display->set_striped_pattern( cl_salv_display_settings=>true ).
81
82 lr_display->set_list_header( text-001 ).
83
84 * Actual Diplay
85 lr_alv->display( ).
86
87 ELSE.
88 MESSAGE 'No data found' TYPE 'I'.
89 LEAVE LIST-PROCESSING.
90 ENDIF.

ENDFORM.

Please check this video from abap channel. This video speaks about CDS Views with Parameters in more
detail.

You might also like