AMDP and CDS
AMDP and CDS
AMDP and CDS
Prerequisites
SAP NetWeaver AS ABAP 7.4 Support Package 5 (or higher) running on SAP HANA
SAP HANA Appliance Software SPS 05 (or higher)
To create an AMDP you need to use at least ABAP Development Tools in Eclipse 2.19
It is of course still possible to open an AMDP with se80 /se24, but you won’t be able to edit it
ABAP Managed Database Procedures are a new feature in AS ABAP allowing developers to write database procedures
directly in ABAP.
Using AMDP allows developers to create and execute those database procedures in the ABAP environment using
ABAP methods and ABAP data types.
1. Start the ABAP Development Tools (aka ABAP in Eclipse) – or your SAP HANA Studio – and open the
ABAP perspective by selecting menu entry WindowOpen perspectiveOthers, and choosing
the ABAP entry in the appearing dialog box.
2. Go to your ABAP project in the Project Explorer and create a new class in the package of your choice by
selecting the context menu entry New… > ABAP Class
3. Maintain the required information (e.g. ZCL_OIA_TOPANDFLOP as name and “EPM OIA: Best and Worst
Customers” as description) and click on Next.
Select a transport request if required and confirm the creation dialog.
4. Now go to the class definition and insert following line directly after PUBLIC SECTION:
INTERFACESif_amdp_marker_hdb.
5. Save.
Info: An AMDP class can contain both regular ABAP methods and AMDP methods. An AMDP is declared like a regular static method or
instance method in any visibility section. An AMDP method cannot be identified as such in the declaration part of the class. Nevertheless,
the parameter interface of an AMDP method has to fulfill specific prerequisites. For example the parameters must be declared
using VALUE for pass by value and return values cannot be declared using RETURNING.
Before going ahead with the method definition, we first have to defined the type of the result sets.
1. Define the two types ty_bupa_selection and tt_bupa_selection in the PUBLIC SECTION of the
class definition – With ty_bupa_selection defining the table line of our return set,
and tt_bupa_selection defining the type of the returned tables.
For that just copy the below coding after the interface declaration done in the previous steps:
TYPES:
BEGIN OF ty_bupa_selection,
company_name TYPE c LENGTH 80,
gross_amount TYPE p LENGTH 8 DECIMALS 2,
END OF ty_bupa_selection.
TYPES:
tt_bupa_selection TYPE STANDARD TABLE OF ty_bupa_selection WITH EMPTY KEY.
2. Now define the public static method get_top_and_flop.
Just copy and pase the coding below directly after the type definitions in the public section:
CLASS-METHODS get_top_and_flop
IMPORTING
VALUE(iv_client) TYPE mandt
VALUE(iv_number) TYPE i
EXPORTING
VALUE(et_top) TYPE tt_bupa_selection
VALUE(et_flop) TYPE tt_bupa_selection.
Info: Analog to native SQL with ADBC and EXEC, the AMDP framework does not support automatic client handling. It means that in case
of client-specific computations, the client context has to be passed to the AMDP method and used appropriately in the SQLScript coding.
3. An error will be displayed in the editor due to the missing method implementation. Just use the Quick Fix
(Ctrl+1) function “Add implementation for get_top_and_flop” to quickly solved this issue.
4. Save your AMDP class.
ENDMETHOD.
The compiler now knows, that the implementation of the method get_top_and_flop of the
class ZCL_OIA_TOPANDFLOP is a SQLScript-based AMDP for the HANA database platform. The
addition USING contains the name of the DDIC tables which will be used in the implementation.
2. Now implement the database procedure by copying the SQLScript source below
Info: In order to quickly visualize whether a class contains AMDP methods and where, it is recommended to set a different
background color for embedded languages – such as native SQL and SQLScript.
To achieve this, go to the ADT menu entry Windows > Preferences and select the path General > Appearance
> Color and Fonts > ABAP > Syntax Coloring > Embedded Languages (background
Enter the required information (name, a description – e.g. “Retrieve and Display Sales Order with
Open Days and BuPa Data”-) and press Next.
Select a transport request if required and press Finish to confirm the creation dialog.
2. Now implement the report.
For this purpose, just copy & paste the source code below into the ABAP editor.
Regarding the transport aspect, AMDP classes are transported similarly to regular ABAP classes using the standard
ABAP transport mechanism. No HANA artifacts have to be transported. This means that the HANA transport container
and the HANA delivery units are not involved in this process.
You can have a look at video tutorials demonstrating how to create an AMDP and how to debug an AMDP here.
Tipp: As direct comparison to this “Top-Down”-approach, you can have a look at another step-by-step
tutorialshowing the “Bottom-Up”-approach for consuming the same HANA database procedures
Related Content
Find more content under ABAP for SAP HANA,SCN space
ABAP for SAP HANA Reference Scenario, SCN document
https://blogs.sap.com/2014/12/15/modification-free-enhancement-of-amdp-in-as-abap-74-sp08/
CDS View Definition Features
• View-on-View
– View can have other views as data basis
– No restriction on the number of layers