Create an ABAP Managed Database Procedure (AMDP) and Analyze Its Performance
Create an AMDP and analyze its runtime performance along with the performance of the executed SQL statements, using the AMDP Profiler in ABAP Development Tools (ADT).
You have a valid instance of SAP S/4HANA on-premise edition, version 1909 or higher. For a free Cloud Appliance Library (CAL) version, of SAP S/4HANA 1909, see SAP S/4HANA Fully-Activated Cloud Appliance
Select your project. From the context menu, choose New > ABAP Package.
Image depicting step2-package
Enter a name and description for your package, then choose Next.
Image depicting step2b-package-name
Create or assign a transport request and choose Finish.
Step 2Create an ABAP class
+
Again, from the context menu of your package, choose New > ABAP Class.
Enter a name and description, then choose Next.
Name: ZCL_AMDP_DEMO_XXX
Description: AMDP Demo w Flight Ref Scenario
Assign the transport request and choose Finish.
Step 3Add two interfaces
+
Add two interfaces by adding this code to the public section. Ignore the warning for now.
if_amdp_marker_hdb defines the class as an AMDP class, allowing you to implement AMDP methods - that is, ABAP methods that call a SAP HANA database procedure from within a global ABAP class.
if_oo_adt_classrun allows you to output the results to the ABAP Console.
ABAP
INTERFACES:if_amdp_marker_hdb,if_oo_adt_classrun.
Step 4Create structures and table types
+
Add these structures and types to the public section, just after the interface definitions.
Note the data elements that you imported earlier.
ABAP
TYPES:BEGIN OFty_result_line,airlineTYPE/dmo/carrier_name,flight_connectionTYPE/dmo/connection_id,old_priceTYPE/dmo/flight_price,old_currencyTYPE/dmo/currency_code,new_priceTYPE/dmo/flight_price,new_currencyTYPE/dmo/currency_code,END OFty_result_line,BEGIN OFty_flights_line,airlineTYPE/dmo/carrier_name,flight_connectionTYPE/dmo/connection_id,priceTYPE/dmo/flight_price,currencyTYPE/dmo/currency_code,END OFty_flights_line,ty_result_tableTYPE STANDARD TABLE OFty_result_lineWITHEMPTYKEY,ty_flights_tableTYPE STANDARD TABLE OFty_flights_lineWITHEMPTYKEY,ty_flightsTYPE STANDARD TABLE OF/dmo/flight.
Step 5Add method definitions
+
Add these two method definitions to your code. Ignore the errors for now.
In the class definition, select any one of the methods and choose Add 3 unimplemented methods. All three (empty) implementations will appear in the class implementation.
Image depicting step7-implement-3-methods
Image depicting step7b-implems
Add the following to the method implementation get_flights. Both this and convert_currency are SQLScript.
Add the SELECT statement. Ignore the warning for now.
ABAP
flights=selectdistinctfrom"/DMO/FLIGHT" as f
innerjoin"/DMO/CARRIER" as c
onf.carrier_id=c.carrier_id;
Add the fields. You can do this using Auto-complete (Ctrl+1), to make sure you are using the correct field names.
ABAP
flights=selectdistinctc.nameasairline,f.connection_idasflight_connection,f.priceasprice,f.currency_codeascurrencyfrom"/DMO/FLIGHT" as f
innerjoin"/DMO/CARRIER" as c
onf.carrier_id=c.carrier_id;
Finally, call the other AMDP method, convert_currency. Your method should look like this:
ABAP
METHODget_flightsBYDATABASEPROCEDUREFORHDBLANGUAGESQLSCRIPTOPTIONSREAD-ONLYUSING/dmo/flight/dmo/carrierZCL_AMDP_DEMO_XXX=>convert_currency.flights=selectdistinctc.nameasairline,f.connection_idasflight_connection,f.priceasprice,f.currency_codeascurrencyfrom"/DMO/FLIGHT" as f
innerjoin"/DMO/CARRIER" as c
onf.carrier_id=c.carrier_id;call"ZCL_AMDP_DEMO_XXX=>CONVERT_CURRENCY"( :flights, result );
ENDMETHOD.
Code
### Implement the method convert_currency
Similarly, implement the `convert_currency` method.
```ABAP
METHOD convert_currency BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
declare today date;
declare new_currency nvarchar(3);
select current_date into today from dummy;
new_currency := 'EUR';
result = select distinct
airline,
flight_connection,
price as old_price,
currency as old_currency,
convert_currency(
"AMOUNT" => price,
"SOURCE_UNIT" => currency,
"TARGET_UNIT" => :new_currency,
"REFERENCE_DATE" => :today,
"CLIENT" => '100',
"ERROR_HANDLING" => 'set to null',
"SCHEMA" => current_schema
) as new_price,
:new_currency as new_currency
from :flights;
ENDMETHOD.
Step 7Implement the method `main` of the interface if_oo_adt_classrun
+
Finally, implement the main method of the interface if_oo_adt_classrun. This will allow you to output your results to the ABAP Console.
Call the method get_flights from the current instance of the class:
The view opens below the Class Editor, beside the Console. If necessary, refresh the view ( F5 ). Double-click on your class.
Image depicting step12c-abap-traces-class
The Trace Results view appears. The ABAP Managed Database Procedures tab appears to the right.
Image depicting step12d-amdp-tab
In older versions of SAP AS ABAP (earlier than 7.55): In the ABAP Profiler display for the AMDP Trace, the column “Execution Time” sometimes contains values that are larger than the values in column “Duration”. As the ABAP Profiler usually displays elapsed time, the column “Execution Time” may only be smaller than “Duration”, as there might be some “Compile Time” involved in the overall duration.
This is a known issue and is fixed in SAP AS ABAP Release 7.55.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 13
1. Create an ABAP package2. Create an ABAP class3. Add two interfaces4. Create structures and table types5. Add method definitions6. Implement get_flights7. Implement the method `main` of the interface if_oo_adt_classrun8. Check your code9. Format, save, activate, and test your code10. Set the Run configuration to ABAP Console11. Open the AMDP tab12. Test yourself13. More Information
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.