Thursday 27 July 2017

How To Create AMDP With Parameters In ABAP Modular Perspective In SAP HANA

What are AMDPs…


ABAP Managed Database Procedures are a new feature in AS ABAP allowing developers to write database procedures directly in ABAP. You can think of a Database Procedure as a function stored and executed in the database. The implementation language varies from one database system to another. In SAP HANA it is SQL Script. Using AMDP allows developers to create and execute those database procedures in the ABAP environment using ABAP methods and ABAP data types.

Advantage of AMDP Process


  • The main advantage of this method that only the AMDP class has to be transported wit ABAP transport mechanism.
  • No HANA delivery or HANA transport system is required in this process.
  • Developers only need ABAP development tools for building and managing the CDS view. There is no need for additional HANA development tools.

Features of ABAP Managed Database Procedure (AMDP)

  • Static check code and Syntax colouring are provided for embedded SQLScript
  • The user can set a Background colour for better visibility AMDP methods in the class.
  • The User can access other AMDP methods, ABAP dictionary view and ABAP tables in AMDP method.
  • AMDP method are called like other regular ABAP methods.
  • User can perform detailed analysis of various error during runtime in transaction ST22
  • Modification or Enhancement of regular ABAP classes can be done by Users.

Example of AMDP Class Definition


CLASS CL_AMBP_EXAMPLE DEFINITION.

PUBLIC SECTION.
INTERFACES IF_AMDP_MARKER_HDB. //Marker Interface for HANA DB//

METHODS process //Only ABAP code is possible//
IMPORTING it_param TYPE type1
EXPORTING et_param TYPE type2.

METHODS execute //SQLScript or ABAP code both are possible//
IMPORTING VALUE(it_param) TYPE type1
EXPORTING VALUE(et_param) TYPE type2. //specific parameter interface required//
CHANGING VALUE(ch_param) TYPE type3

ENDCLASS.

AMDP Class Implementation


CLASS CL_AMDP_EXAMPLE IMPLEMENTATION

METHODS process
// Write ABAP source code here//

ENDMETHOD

METHOD execute BY DATABASE PROCEDURE //AMDP method marker//
FOR HDB //Database platform//
LANGUAGE SQLScript //Database language//
[OPTIONS READ-ONLY] //Database-specific options//
USING name1 name2 etc… //List of used DDIC entities and AMDPs//

//Write here the SQLScript coding//
select * from dummy;

ENDMETHOD.
ENDCLASS.

Lets Take one Example: Creating AMDP with Input, Output Parameters


First Go to ABAP modeling perspective in HANA Studio

Windows->Perspective->Open Perspective->ABAP




Create ABAP class:


CLASS ztestk DEFINITION public.

PUBLIC SECTION.

types : tt_mara type table of mara.

interfaces : if_amdp_marker_hdb.

methods : my_method

importing value(im_matnr) type mara-matnr

exporting value(et_mara) type tt_mara.

ENDCLASS.

CLASS ztestk IMPLEMENTATION.

method my_method by database procedure for HDB

language sqlscript options read-only using MARA.

et_mara=SELECT * from MARA where MATNR= IM_MATNR;

endmethod.

ENDCLASS.

Save It(Control+S)

Open SAP GUI

Enter TCODE : SE24 (To see u r class is created or not)

We can see our methods and code also.


Click on Display


Enter TCODE : SE38 (To Create report )

In Report we are calling class (creating object to class)


Click on create



Type u r code here to call class

REPORT ZTESTK_REP.
PARAMETERS : p_matnr TYPE matnr DEFAULT ‘000000000000001109’.

DATA : r_amdp TYPE REF TO ztestk,
et_mara TYPE TABLE OF mara,
r_salv TYPE REF TO cl_salv_table.

CREATE OBJECT r_amdp.

r_amdp->my_method( EXPORTING im_matnr  = p_matnr
IMPORTING et_mara    = et_mara ).

TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table   = r_salv
CHANGING
t_table        = et_mara
.
CATCH cx_salv_msg .
ENDTRY.

r_salv->display( ).

——————————————
Finally press F8 Button to execute

No comments:

Post a Comment