By

ABAP Managed Database Procedures (AMDP)

AMDPs enable ABAP developers to write database procedures directly in ABAP. Using specialized ABAP classes known as AMDP classes, developers can embed SQLScript code that is utilized to create database procedures within the SAP HANA database layer.

➢ ABAP Managed Database Procedures (AMDP), introduced in Release 7.40, SP05, enable developers to write database procedures directly in ABAP. These procedures are fully managed within the ABAP environment.

➢ To enable native use of SAP HANA features within the ABAP layer, the SAP HANA database procedure language SQLScript has been integrated into the ABAP stack. AMDP is implemented through ABAP class methods, known as AMDP methods, which act as containers for SQLScript code.

Sample example:

An AMDP is implemented within an AMDP class using either a static or instance method, which can be defined in any visibility section.

Steps to create AMDP:

  1. Create a global class.
  • Login in Eclipse >> Right click on your package >> New >> ABAP Class.
  • Enter name and description >> Click Next >> Click Finish.

2. Add AMDP marker interface IF_AMDP_MARKER_HDB.

  • Create structure and table types.

3. Create a method definition.

4. Implement the method using DATABASE PROCEDURE.

Complete Class:

CLASS ycl_amdp_demo DEFINITION PUBLIC FINAL CREATE PUBLIC .

PUBLIC SECTION.

INTERFACES: if_amdp_marker_hdb.

TYPES:

BEGIN OF lty_po_hdr,

ebeln TYPE ebeln,

bukrs TYPE bukrs,

bstyp TYPE ebstyp,

bsart TYPE esart,

END OF lty_po_hdr,

ltt_po_data TYPE STANDARD TABLE OF lty_po_hdr.

CLASS-METHODS: m_amdp_method

IMPORTING

VALUE(iv_po_num) TYPE ebeln

EXPORTING

VALUE(et_tab) TYPE ltt_po_data

RAISING cx_amdp_execution_error.

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.

CLASS ycl_amdp_demo IMPLEMENTATION.

METHOD m_amdp_method

BY DATABASE PROCEDURE

FOR HDB

LANGUAGE SQLSCRIPT

OPTIONS READ-ONLY

USING ekko.

et_tab = select ebeln, bukrs, bstyp, bsart FROM ekko WHERE ebeln = :iv_po_num;

ENDMETHOD.

ENDCLASS.

How to consume AMDP?

  • Create one ABAP program and call AMDP method using class name.

CDS vs AMDP:

What to Use? ABAP SQL Versus CDS Views and AMDPs

AMDP procedures vs AMDP functions

I hope this article helps you to understand the concept of AMDP and it’s comparison with CDS.

Thanks for vising!

Sangeeta Singh

2 responses to “ABAP Managed Database Procedures (AMDP)”

  1. bitwiselearn Avatar
    bitwiselearn

    Really Helpful! Thanks for sharing!!

    1. Sangeeta Singh Avatar

      Thanks for the support 😊

Leave a Reply

Discover more from HANAxABAP

Subscribe now to keep reading and get access to the full archive.

Continue reading