How To Create AMDP With Out Parameters In ABAP Perspective
What are AMDPs…
ABAP Managed Database Procedures are a new feature in AS ABAP allowing developers to write database procedures directly in ABAP. You can think of a Database Procedure as a function stored and executed in the database. The implementation language varies from one database system to another. In SAP HANA it is SQL Script. Using AMDP allows developers to create and execute those database procedures in the ABAP environment using ABAP methods and ABAP data types.
Advantage of AMDP Process
- The main advantage of this method that only the AMDP class has to be transported with ABAP transport mechanism.
- No HANA delivery or HANA transport system is required in this process.
- Developers only need ABAP development tools for building and managing the CDS view. There is no need for additional HANA development tools.
Features of ABAP Managed Database Procedure (AMDP)
- Static check code and Syntax colouring are provided for embedded SQLScript
- The user can set a Background colour for better visibility AMDP methods in the class.
- The User can access other AMDP methods, ABAP dictionary view and ABAP tables in AMDP method.
- AMDP method are called like other regular ABAP methods.
- User can perform detailed analysis of various error during runtime in transaction ST22
- Modification or Enhancement of regular ABAP classes can be done by Users.
Example of AMDP Class Definition
CLASS CL_AMBP_EXAMPLE DEFINITION.
INTERFACES IF_AMDP_MARKER_HDB. //Marker Interface for HANA DB//
METHODS process //Only ABAP code is possible//
IMPORTING it_param TYPE type1
EXPORTING et_param TYPE type2.
METHODS execute //SQLScript or ABAP code both are possible//
IMPORTING VALUE(it_param) TYPE type1
EXPORTING VALUE(et_param) TYPE type2. //specific parameter interface required//
CHANGING VALUE(ch_param) TYPE type3
AMDP Class Implementation
CLASS CL_AMDP_EXAMPLE IMPLEMENTATION
// Write ABAP source code here//
METHOD execute BY DATABASE PROCEDURE //AMDP method marker//
FOR HDB //Database platform//
LANGUAGE SQLScript //Database language//
[OPTIONS READ-ONLY] //Database-specific options//
USING name1 name2 etc… //List of used DDIC entities and AMDPs//
//Write here the SQLScript coding//
select * from dummy;
Lets Take one Example: Creating AMDP with Input, Output Parameters
First Go to ABAP modeling perspective in HANA Studio
Windows->Perspective->Open Perspective->ABAP ()
Create ABAP class:
CLASS zcl_amdp_demo DEFINITION public.
types : tt_mara type table of mara.
interfaces : if_amdp_marker_hdb.
methods : my_method
exporting value(et_mara) type tt_mara.
CLASS zcl_amdp_demo IMPLEMENTATION.
method my_method by database procedure for HDB
language sqlscript options read-only using MARA.
et_mara=SELECT * from MARA;
Open SAP GUI
Enter TCODE : SE24 (To see u r class is created or not)
We can see our methods and code also.
Click on Display
Enter TCODE : SE38 (To Create report )
In Report we are calling class (creating object to class)
Click on create
DATA : r_amdp TYPE REF TO zcl_amdp_demo,
et_mara TYPE TABLE OF mara,
r_salv TYPE REF TO cl_salv_table.
CREATE OBJECT r_amdp.
IMPORTING et_mara = et_mara ).
CALL METHOD cl_salv_table=>factory
r_salv_table = r_salv
t_table = et_mara
CATCH cx_salv_msg .
Finally press F8 Button to execute