Académique Documents
Professionnel Documents
Culture Documents
Also, the Studio gives freshness to developers who were bored with the blue
Hopefully, you have some idea of HANA Studio and its need.
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
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
You get the below error in ADT if you try to edit the already opened program
(in GUI).
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
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.
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]
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.
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:
[ad2ToAppearHere]
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.
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.
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
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.
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.
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.
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
(We will check the details of CDS View with and without Parameters in our
next article)
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 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.
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.
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”.
[ad3ToAppearHere]
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.
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.
In this article, we would dive a little deeper on CDS View from an ABAPer’s
perspective.
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.
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?
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
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”.
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.
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.
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.
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
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
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.
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
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.
I would like to request HANA Experts to provide some more insight and
justification of using CDS View Entity (DDL Source) in SELECTs.
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.
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?
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
If you have some confusion regarding HANA, check this popular post: SAP
HANA from Space Level.
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
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.
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‘.
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.
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?
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.
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).
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.