AMDP - ABAP Manage Database Procedure

AMDP – ABAP Managed Databased Procedure

ABAP Managed Database Procedures, is a procedure, we can write code inside AMDP by using SQLSCRIPT which is a database language same as SQL script, this language is easy to understand and code. 

After coding logic inside AMDP method, you can consume it in ABAP report, or use AMDP same as delegate method in CDS table function.

With AMDP, We can take advantage of new features of HANA (code push-down technique), hence we still code all logic on application layer, then this logic will be executed on the database layer.

AMDP is only supported in ADT bundle or HANA studio, and don’t be supported in SAP GUI. So if you want to learn AMDP, please change IDE to ADT bundle instead SAP GUI.

Besides HANA DB, AMDP can support many other DB, maybe in the future. So, at this time, we can only use it in HANA DB

Limitations of AMDP

We can only create, debug AMDP in ADT bundle or HANA studio.

With AMDP, we can’t use MSEG table. So, we can use MATDOC table or proxy object (NSDM_V_MSEG) instead

Data type of parameter must be table or scalar type(Int, char,…).

With select-option parameters, we must convert to string value by using method  cl_shdb_seltab=>combine_seltabs at ABAP program,then pass it to parameters. After that, we will use APPLY_FILTER to filter this condition inside AMDP method

AMDP does not handle automatic client. You need to add client as parameter value or using SESSION_CONTEXT(‘CLIENT’) in where condition Sometimes, the system will catch syntax error with SD table,in this case, you need to select from table with alias name instead. (I don’t know another system, but in my system, when transport TR to staging environment, it always catches syntax error

1. First Program With AMDP
Open ABAP Development Toll(Eclipse or HANA studio ) and Go to ABAP Perspective.  Create ABAP Class


Provide name and Descriptions.



AMDP Class Definition
  • An AMDP is implemented in an AMDP class with a regular static method or instance method in any visibility section. The editing environment for AMDP is the ABAP class editor.
  • The AMDP class must contain the appropriate tag interface. IF_AMDP_MARKER_HDB is Marker Interface for DB Procedures.
Example:
  • In Class Definition provide interface IF_AMDP_MARKER_HDB.
  • Define the table type TT_ORDER and structure type TY_ORDER.
  • Define the method GET_SALESORDER_DETAILS (Method parameters should be Passed  by value).



Implementations Of AMDP Class




Activate the AMDP Class and check the created class in Transaction SE24



Execute the AMDP method using report




AMDP Method stored as database procedure In HANA DB




CDS Table Functions
ABAP CDS table functions define table functions that are implemented natively on the database and can be called in CDS.
A table function can be created with syntax- DEFINE TABLE FUNCTION  [table func name ] and set of input parameters and return fields can be mentioned with data types and a class >method name must be maintained which is responsible for the actual implementation.




The Table function implementation class method.
The method declaration must specify – [ for table function Name ] and the sample method implementation




SESSION Variable Access in AMDP Methods

The predefined function SESSION_CONTEXT( )  is used to access the session variables of SAP HANA database .

Few session variables are as below:
CLIENT                                   –   sy-mandt
APPLICATIONUSER            –   sy-uname
LOCALE_SAP                       –   sy-langu

How they can be Accessed:
SESSION_CONTEXT(‘CLIENT’) 
SESSION_CONTEXT(‘APPLICATIONUSER’)
SESSION_CONTEXT(‘LOCALE_SAP’)  
SESSION_CONTEXT('SAP_SYSTEM_DATE');



AMDP Exception























Comments

Popular posts from this blog

ABAP RESTful Application Programming Model (RAP)

CDS View