Vous êtes sur la page 1sur 76

ABAP on SAP HANA. Part I.

First Program in ABAP HANA


Introduction to SAP ABAP on HANA

We have heard enough about SAP HANA, in-memory concept,


software/hardware innovation etc. In this article, we do not want to beat
around the theories. As an ABAP developer, we would like to know how we
can view ABAP objects (programs/FMs/tables) in HANA Studio and how we
can create/change those objects there. This is the first part in the series of
posts which would specifically target our SAP Technical folks, our ABAPer
community.

As an ABAPer, I had these queries. I am sure, many of my ABAPer friends


would have similar if not same questions. Hope these answers would provide
some light to your existing knowledge about ABAP on SAP HANA. At the
end of the last question of this article, you will learn and create your first
ABAP program from HANA Studio and also execute it successfully to view the
output.

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 Studioprovides 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. Isn’t it cool? With ABAP perspective in the studio,
you can implement end-to-end in-memory solutions in Studio with the same
UI.

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 complement 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

Q: What are perspective in HANA Studio?


4. In layman’s 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?

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.
ABAP on SAP HANA. Part II.
ADT Eclipse and HANA Studio
ADT Eclipse/HANA Studio for ABAPers

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.
Also Read: SAP HANA from space level.

[ad1ToAppearHere]

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.

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

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.
ABAP on SAP HANA. Part III. Debugging in ADT
ABAP debugger is completely integrated with Eclipse from Kernel 7.21, SAP
Basis 7.31 SP4.

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

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.
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.
6. Let’s 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

Hopefully, this article was successful in giving you the overview of Debugging
in HANA ADT. For experienced ABAPers, it is the same thing as in ABAP GUI,
with some good additions. For freshers, you need some system to get your
hands dirty and learn.

As declared in our previous post, we are planning to allow our


subscribers’ free access to SAP HANA system for a couple of hours to get
the look and feel of the system for free (for a couple of hours only). We are
still compiling the list. After we get the total list of interested users, we would
provide the credentials and date/time when they can access it. In the next
article, we would see how we can perform ABAP Profiling/Tracing in Eclipse
Studio and more.
ABAP on SAP HANA. Part IV. Core Data Services
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.

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.

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

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.

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 don’t
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 parametersthat 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 basededitor 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 shouldn’t. 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 doesn’t 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).
ABAP on SAP HANA. Part V. Deep Dive into CDS Views

In this article, we would dive a little deeper on CDS View from an ABAPer’s
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 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.

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.

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 layman’s 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.

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.

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

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

ABAP on SAP HANA. Part VI. New Age Open SQL ABAP 740
If you have been following the previous posts on SAP ABAP on HANA,
you would know that CDS View is another technique to achieve Code to
Data paradigm. If the same functionality can be achieved by both CDS
Technique and Open SQL, which one should we adopt?
Answer: SAP wants us to stay Open. Open SQL is the first choice. Then
comes CDS View and then the stored procedures (ADBC, ADMP which we will
cover in our subsequent articles).

The whole idea of the modern ABAP/SQL/HANA is to push down logic to the
database. We outsource these powerful innovations to put and execute the
logic in the database. But do remember, SAP also wants to be as Open as
possible. So given a choice between database specific and database
independent solution, always chose the latter (database independent).

Enough of preaching, let us come to the topic of the day. New Age SQL for
ABAP.

Prior to release 740, if we had the requirement to add an additional column


in the output which did not exist in SAP table with some custom logic, then
we usually wrote something like below.

We defined the TYPES. We looped through the table and added the custom
logic (High Purchase or Low Purchase) as shown below.

1
2 TYPES: BEGIN OF ty_ekpo,
3 ebeln TYPE ebeln,
4 ebelp TYPE ebelp,
5 werks TYPE ewerk,
6 netpr TYPE bprei,
7 pur_type TYPE char14,
8 END OF ty_ekpo.
9
10 DATA: it_ekpo TYPE STANDARD TABLE OF ty_ekpo.
11
12 FIELD-SYMBOLS <fs_ekpo> TYPE ty_ekpo.
13
14 SELECT ebeln ebelp werks netpr
15 FROM ekpo
16 INTO TABLE it_ekpo.
17
18 LOOP AT it_ekpo ASSIGNING <fs_ekpo>.
19
20 IF <fs_ekpo>-netpr GT 299.
21 <fs_ekpo>-pur_type = 'High Purchase'.
22 ELSE.
23 <fs_ekpo>-pur_type = 'Low Purchase'.
24 ENDIF.
25
26 ENDLOOP.
27
28 IF it_ekpo IS NOT INITIAL.
29 cl_demo_output=>display_data(
30 EXPORTING
31 value = it_ekpo
32 name = 'Old AGE SQL : 1' ).
33 ENDIF.

Let us see how we can achieve the same thing in a new way. With ABAP 740
and above, we get rid of TYPES, Data Declaration and Loop. Isn’t it cool?

Sample 1 ( Using comma separated fields with inline data declaration


and usage of CASE for reference fields)

1
2 SELECT ebeln, ebelp, werks, netpr,
3 CASE
4 WHEN netpr > 299
5 THEN 'High Purchase'
6 ELSE 'Low Purchase'
7 END AS pur_type
8 FROM ekpo
9 INTO TABLE @DATA(lt_sales_order_header).
10
11 IF sy-subrc = 0.
12 cl_demo_output=>display_data(
13 EXPORTING
14 value = lt_sales_order_header
15 name = 'New AGE SQL : 1' ).
16 ENDIF.
Outputs from both the above techniques are same. But the path does

matters. Isn’t it?

If you have some confusion regarding HANA, check this popular post: SAP
HANA from Space Level.

Next, let us check the powerful inbuilt functions in SELECT.

Sample 2 ( Using JOIN and COUNT / DISTINCT functions in SELECT )

1
2 PARAMETERS: p_matnr TYPE matnr,
3 p_lgort TYPE lgort_d.
4
5 SELECT mara~matnr,
6 mard~lgort,
7 COUNT( DISTINCT ( mard~matnr ) ) AS distinct_mat, " Unique Number of Material
8 COUNT( DISTINCT ( mard~werks ) ) AS distinct_plant, " Unique Number of Plant
9 SUM( mard~labst ) AS sum_unrest,
10 AVG( mard~insme ) AS avg_qlt_insp,
11 SUM( mard~vmspe ) AS sum_blocked
12 FROM mara AS mara INNER JOIN mard AS mard
13 ON mara~matnr EQ mard~matnr
14 INTO TABLE @DATA(lt_storage_loc_mat)
15 UP TO 1000 ROWS
16 WHERE mard~matnr = @p_matnr
17 AND mard~lgort = @p_lgort
18 GROUP BY mara~matnr,
19 mard~lgort.
20
21 IF sy-subrc = 0.
22 cl_demo_output=>display_data(
23 EXPORTING
24 value = lt_storage_loc_mat
25 name = 'New AGE SQL : 2' ).
26 ENDIF.
27
28

DISTINCT Material is 1 and DISTINCT Plant is 2. SUM for the Unrestricted


stock is 2, AVG is 2/2 = 1 and SUM of Blocked stock is 2. This is just a
sample to showcase how versatile and powerful the SELECT statement has
become.

Next, in our menu, today is the Mathematical Operators in SELECT. Check


the below snippet where we can directly assign ’10’ (as rebate percent)
which would be in the internal table. CEIL function, multiplication, subtraction
etc can be handled during the SELECT statement. If we were not in 740, we
would have needed a separate loop and bunch of code to achieve this

function. Isn’t ABAP real modern now?

Sample 3 ( Using vivid mathematical operators in SELECT )

DATA: lv_rebate TYPE p DECIMALS 2 VALUE '0.10'.

SELECT ebeln,
10 AS rebate_per,
CEIL( netpr ) AS whole_ord_net,
( @lv_rebate * netpr ) AS rebate,
( netpr - ( @lv_rebate * netpr ) ) AS act_net
FROM ekpo
USING CLIENT '130'
UP TO 10 ROWS
INTO TABLE @DATA(lt_po_data).

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_po_data
name = 'New AGE SQL : 3' ).
ENDIF.

Not only Mathematics is fun with ABAP 740, but also logical programming.
Continue below to taste the new flavour.

Sample 4 ( Using Complex Case statement on non-referenced fields


i.e. multiple in one Select )

1
2 PARAMETERS: p_werks TYPE werks_d.
3 DATA:
4 lv_rebate TYPE p DECIMALS 2 VALUE '0.10',
5 lv_high_rebate TYPE p DECIMALS 2 VALUE '0.30'.
6
7 SELECT ebeln,
8 werks,
9 CEIL( netpr ) AS whole_ord_net,
10 ( @lv_rebate * netpr ) AS rebate,
11 ( netpr - ( @lv_rebate * netpr ) ) AS act_net,
12
13 CASE WHEN werks = @p_werks " For specific plant
14 THEN @lv_rebate
15 ELSE @lv_high_rebate
16 END AS rebate_type,
17
18 CASE WHEN werks = @p_werks " For specific plant
19 THEN 'low rebate'
20 ELSE 'high rebate'
21 END AS low_high
22
23 FROM ekpo
24 USING CLIENT '130'
25 UP TO 25 ROWS
26 INTO TABLE @DATA(lt_po_data).
27
28 IF sy-subrc = 0.
29 cl_demo_output=>display_data(
30 EXPORTING
31 value = lt_po_data
32 name = 'New AGE SQL : 4' ).
33 ENDIF.
34
35

OALESCE’s literal meaning from the dictionary is ‘come together and form
one mass or whole‘ or ‘combine (elements) in a mass or whole‘.

According to SAP documentation, the COALESCE function in Open SQL


returns the value of the argument arg1 (if this is not the null value);
otherwise, it returns the value of the argument arg2. A blank must be placed
after the opening parenthesis and before the closing parenthesis. A comma
must be placed between the arguments

Check the usage below. If data for ekko~lifnr is present (means PO is


created for the lessor) then the LIFNR (Vendor Number) from EKKO is
printed else, ‘No PO’ literal is updated. This function is quite handy in many
real practical scenarios.

Sample 5 ( Using COALESCE and Logical operators like GE / GT/ LE /


LT etc in JOIN which was originally not available

SELECT lfa1~lifnr,
lfa1~name1,
ekko~ebeln,
ekko~bukrs,
COALESCE( ekko~lifnr, 'No PO' ) AS vendor
FROM lfa1 AS lfa1 LEFT OUTER JOIN ekko AS ekko
ON lfa1~lifnr EQ ekko~lifnr
AND ekko~bukrs LT '0208'
INTO TABLE @DATA(lt_vend_po)
UP TO 100 ROWS.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_vend_po
name = 'New AGE SQL : 5' ).
ENDIF.

How many times and in how many projects did you have the requirement to
print Plant and Plant description together like 0101 (Houston Site) or in
forms you had the requirement to write Payee (Payee Name)? We achieved it
by looping and concatenating. We did not have better option earlier, but now
we can do it while selecting the data. Thanks to the SAP Development Team.
Sample 6 (Concatenation while selecting data )

SELECT lifnr
&& '(' && name1 && ')' AS Vendor,
ORT01 as city
FROM lfa1
INTO TABLE @DATA(lt_bp_data)
UP TO 100 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_bp_data
name = 'New AGE SQL : 6' ).
ENDIF.

Every report/conversion/interface asks us to validate the input data and we


do it by checking its existence in the check table. That has become easier
and better now like shown below.

Sample 7 ( Check existence of a record )

SELECT SINGLE @abap_true


FROM mara
INTO @DATA(lv_exists)
WHERE MTART = 'IBAU'.
IF lv_exists = abap_true.
WRITE:/ 'Data Exists!! New AGE SQL : 7'.
ENDIF.
ABAP was always a fifth generation programming language and it has
become more so. It has become more readable and real life syntactically

too. . HAVING function is another feather to the crown.

Sample 8 ( Use of HAVING functions in SELECT )

SELECT lfa1~lifnr,
lfa1~name1,
ekko~ebeln,
ekko~bukrs
FROM lfa1 AS lfa1 INNER JOIN ekko AS ekko
ON lfa1~lifnr EQ ekko~lifnr
AND ekko~bukrs LT '0208'
INTO TABLE @DATA(lt_vend_po)
GROUP BY lfa1~lifnr, lfa1~name1, ekko~ebeln, ekko~bukrs
HAVING lfa1~lifnr > '0000220000'.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_vend_po
name = 'New AGE SQL : 8' ).
ENDIF.

Remember, sometimes we need to select all fields of more than one table
and provide custom names in the output. Wasn’t it tiresome to create TYPEs
and achieve our requirement?

Sample 9 ( Use of selection of all columns with renaming of fields.


This is handy in case you have to do all field select )
I thought with ABAP 740, I could do the below.

SELECT jcds~*,
tj02t~*
FROM jcds INNER JOIN tj02t
ON jcds~stat = tj02t~istat
WHERE tj02t~spras = @sy-langu
INTO TABLE @DATA(lt_status)
UP TO 1000 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_status
name = 'New AGE SQL : 9' ).
ENDIF.
The above code is syntactically correct. Wow!! I was so excited to test it as it
would show all columns from both the tables.

OOPs!! We get the above message. Too early to be so happy.

Let us modify the same code a little bit. We need to define the TYPEs and
declare the internal table (Inline did not work above).

TYPES BEGIN OF ty_data.


INCLUDE TYPE jcds AS status_change RENAMING WITH SUFFIX _change.
INCLUDE TYPE tj02t AS status_text RENAMING WITH SUFFIX _text.
TYPES END OF ty_data.

DATA: lt_status TYPE STANDARD TABLE OF ty_data.


SELECT jcds~*,
tj02t~*
FROM jcds INNER JOIN tj02t
ON jcds~stat = tj02t~istat
WHERE tj02t~spras = @sy-langu
INTO TABLE @lt_status
UP TO 100 ROWS.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_status
name = 'New AGE SQL : 9' ).
ENDIF.
Check _CHANGE is added to the field name. _TEXT is also added in the
column name from second table (not captured in the screen print below)
These were just the tip of the icebergs. We would stumble upon more
features and surprises as we work on projects in real system. Just to let you
know, all the above code snippets are from a traditional database (not
HANA) which has EhP 7.4. So do not confuse that we need HANA database
to take advantage of modern SQL techniques. We just need near and above
EhP 7.4.

Vous aimerez peut-être aussi