Lets explore AMDP – What is happening ?
AMDP(ABAP managed database procedures) enables coding SQL Script inside an ABAP Class method directly. OK, we are writing it inside the class methods, but where it is getting executed ? Answer is HANA Database for sure. How it is happening ? Let us explore.
Create a AMDP enabled class
Here I created a AMDP enabled class and wrote necessary implementation as below(Please don’t look into the logic. Its all weird ).
Now I activated the class and executed the method GET_MATERIAL_DESC.
For each of the exporting variables specified, it created SQL Views in the ABAP Schema .
(Did you notice the View name)
For each of the methods we are creating in the AMDP class, it will create 2 database procedures in the HANA DB. Both the view creation and procedures creation will be done when the class method is used first.(That is when it is executed for the first time – This make sense. Now it is so easy to transport the developments to Quality or Production system. We don’t need to bother about the HANA here ) .
Lets go the procedures created by it.
This procedure will contain the actual logic which we have written inside the AMDP Class method. Only difference is, it will replace the objects specified in the USING clause with the view name.
This procedure is a wrapper procedure for the real one created . This procedure will call the first procedure and project the returned result set.
Limitations of AMDP – Why is it so ?
Below are some key limitations of AMDP classes. Let us see, why it is so.
1.Methods with returning parameters cannot be implemented as AMDPs : A Procedure does not return anything. Which exports multiple outputs.
2.Method parameters have to be tables or scalar types – No Single line concept here in procedure returns.
3.Method parameters have to be passed as values : Well, how you will pass it by reference from ABAP to HANA SQL Script ? 🙂
Indeed a very informative post! I have two small questions:
1. If you change the coding in the method, will the database view adjust accordingly? And also not just the code, maybe the signature as well or the used tables.
2. If you delete the AMDP class, will the hdb view also be deleted?
Thanks, keep up the good work!
1. Changing code in the method will alter the procedure code, and any change we make in the method signature will alter the view. No tables will be directly used in the procedure, but will create views correspondingly(may be to avoid update operations directly SAP tables)
2. No, If we delete the AMDP class, the methods will not be deleted automatically.
Good one ... Really helpful and ℹ nformative.
Good one .
Thanks Jhansi 🙂
It's good article to understand AMDP lifecycle 🙂
BTW, could you please let me know why 2nd procedure, "CLASSNAME=>METHODNAME#stub#timestamp procedure"?
It seems the 1st one , "CLASSNAME=>METHODNAME" is already good enough..
Sorry for the late reply. As you said, CLASSNAME=>METHOD name is good enough. In my understanding, #stub is a wrapper to the actual procedure definition. Reason for this could be to isolate the definition and variable mapping parts.
Thank you for your helpful answer~!!
I saw your video and also I have been looking at the documentation in SQL script. I wonder if there is any possibility to do an AMDP that can include in its first query a range variable (WHERE f1 IN r_var ) or something similar to a for all entries?
I appreciate any help you can provide.
You can create an instance of class CL_LIB_SELTAB and it's method SQL_WHERE_CONDITION to generate a native-compliant SQL statement from your select-option before actually calling your procedure.
one more option. Using the range variable, I will get a list of key values(for ebeln range, I issue a select ebeln from ekko, to get the list) first from the abap context. Then this list is passed directly into the AMDP procedure. From the procedure, ill issue the IN statement or in case of information models, I will serialize the list to make a comma separated list .
very nice , giving clear picture about AMDP 🙂
Thanks u so much 🙂
Thanks Atul 🙂
how to consume amdp procedures in CDS views and table functions?
its been a long time i checked scn notifs. Did you resolve these ?
Very usefull information 🙂
Very nice blog. thanks for that. Well could you please help me to understand that when to use CDS view and When to AMDP. I have read that for performance always use CDS so when AMDP best to use ??
I know its late to reply !
There are situations where you need to use many core features of HANA which can not be done through CDS - Say, you need to do a predictive analysis on a set of data. Writing it in CDS will be difficult ( possible still) -