Skip to Content

Introduction


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 ).

class.JPG

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 .

view.JPG

(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.

procedure1.JPG

     1.CLASSNAME=>METHODNAME Procedure

          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.

procedure2.JPG

     2.CLASSNAME=>METHODNAME#stub#timestamp procedure

          This procedure is a wrapper procedure for the real one created . This procedure will call the first procedure and project the returned result set.

               procedure3.JPG

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 ? 🙂

Regards

Sreehari

    

To report this post you need to login first.

19 Comments

You must be Logged on to comment or reply to a post.

  1. Tudor Riscutia

    Hello Sreehari,

    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!

    Tudor

    (0) 
    1. Sreehari V Pillai Post author

      Hi Tudor,

      Thanks.

      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.

      Sree

      (0) 
  2. Hyuk Joo Lee

    Hello Sreehari,

    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..

    Best Regards,

    Hyukjoo

    (0) 
    1. Sreehari V Pillai Post author

      Hi Lee,

      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.

      Sree

      (0) 
  3. Jose David Alzate

    Hi Carine,

    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.

    Cheers,

    David

    (0) 
    1. Tudor Riscutia

      Hi Jose,

      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.

      Tudor

      (0) 
    2. Sreehari V Pillai Post author

      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 .

      Sree

      (0) 
  4. sameer bhavsar

    Hello Sreehari,

    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 ??

    (0) 
    1. Sreehari V Pillai Post author

      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) –

      SH

      (0) 

Leave a Reply