How To Create AMDP – ABAP Managed Data Procedures
In our previous tutorial, we learned how to create CDS views where we can define data model and views and today we will learn how to create data procedure in SAP HANA database called AMDP (ABAP Managed Data Procedures).
What you will learn? |
1. Create AMDP using Eclipse |
2. Execute AMDP using ABAP program |
Prerequisites |
1. SAP System Access: Developer role, SE38 |
2. Eclipse software |
AMDP is a global class and uses ABAP OOP (Object Oriented Programming) framework that allows you to create and implement classes and methods for data procedures (just like stored procedure in SQL server).
Now follow these steps to create our first AMDP using Eclipse.
Step 1. Right click your custom package->New->ABAP Class

Step 2. Type in the name and description of your AMDP, click next.

Step 3. You can choose an existing TR numbers of create a new one, click Finish.

Step 4. No here’s the default or initial code for AMDP.

Step 5. Add interface IF_AMDP_MARKER_HDB inside the public section. This is a marker interface in ABAP to identity the class as an AMDP class for SAP HANA Database.

Step 6. Now just below the interfaces section, add the structure type, table type to populate the data, after that define the method to get the flight data.
public section.
Interfaces: IF_AMDP_MARKER_HDB.
types:begin of typ_flight_data,
carrid type s_carrid,
carrname type S_CARRNAME,
fldate type S_DATE,
price type S_PRICE,
SEATSMAX type S_SEATSMAX,
PAYMENTSUM type S_SUM,
end of typ_flight_data.
types: tt_flight_data type standard table of typ_flight_data.
methods: get_flight_data importing value(pv_carrid) type s_carrid
exporting value(et_sflight) type tt_flight_data.
Step 7. Next we need to implement the method get_flight_data, go to the implementation section and write this code below.
class zcl_sflight_data implementation.
method get_flight_data by database procedure
for hdb
language sqlscript
using scarr sflight .
et_sflight = select f.carrid, s.carrname, f.fldate,
f.price, f.seatsmax, f.paymentsum
from scarr as s inner join sflight as f
on s.carrid = f.carrid
where f.carrid = :pv_carrid;
endmethod.
endclass.
Step 8. Save and activate. Now we have successfully created AMDP in SAP HANA Database, next we want to execute it using ABAP Report.

How To Test AMDP in SAP?
We can test the AMDP using ABAP report and also using Tcode se24.
Follow these steps to test AMDP using ABAP report.
Step 1. Create a new ABAP Report program in SE38.

Step 2. Write this code below.
REPORT ZABAPSFLIGHT.
PARAMETERS: p_carrid TYPE scarr-carrid.
START-OF-SELECTION.
DATA(o_sflight) = new ZCL_SFLIGHT_DATA( ).
CALL METHOD o_sflight->get_flight_data
exporting
pv_carrid = p_carrid
importing
et_sflight = data(it_data)
.
cl_demo_output=>display( it_data ).
Step. 3. Run the program and input the p_carrid parameter. Click the execute button.

Here’s the result.

You can also test the AMDP using tcode SE24. Click F8.

Click GET_FLIGHT_DATA execute button.

Input the P_CARRID parameter and click the execute button.

Now click the table entries result.


SAP References:
Share this tutorial with Fellow Geeks!