In this post, you will learn –
- How to call AMDP from ABAP
- How to call AMDP from another AMDP
This is continuation of post Exploring ABAP on HANA [8] : Introduction to AMDP where below AMDP method was created.

Calling AMDP from ABAP
AMDP can be called as usual methods in ABAP.
ABAP Program / Other Class


Same Class

Static or Instance?
In this series the AMDP method is declared as instanec method so far, but going forward all AMDPs will be static methods.
As AMDP methods do not access any of the instance inttributes from the class, it makes sense to use static methods as then creating object is not needed to call the methods. So the program/another class call can be simplified as below.

Calling AMDP from another AMDP
Regardless of the method type i.e. static or instance, while calling it from another method, it is called as if it is a static method.

Important
- Use Static Method to implement AMDP
- The AMDP to be called, needs to be specified in USING as class_name=>method_name.
- Specifiying importing, exporting is not required, but the parameter list is separated with comma (,)
- SQL Script statements end in semi-colon (;)
The resulting data from all methods is same, hence output is not shown again.
Code in Text Format
"AMDP Class Code
CLASS zjp_simple_amdp_class DEFINITION
PUBLIC FINAL CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES : if_amdp_marker_hdb.
TYPES : tt_flights TYPE STANDARD TABLE OF sflight.
CLASS-METHODS : get_flights IMPORTING VALUE(iv_carrid) TYPE sflight-carrid
EXPORTING VALUE(et_flights) TYPE tt_flights.
ENDCLASS.
CLASS zjp_simple_amdp_class IMPLEMENTATION.
METHOD get_flights BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
USING sflight.
et_flights = select * from sflight WHERE carrid = :iv_carrid;
ENDMETHOD.
ENDCLASS.
"Call AMDP instance method
DATA(lo_amdp) = new zjp_simple_amdp_class( ).
lo_amdp->get_flights( EXPORTING iv_carrid = 'AA'
IMPORTING et_flights = data(lt_flights) )
"Call AMDP static method
zjp_simple_amdp_class=>get_flights( EXPORTING iv_carrid = 'AA'
IMPORTING et_flights = DATA(lt_flights) ).
"Call AMDP from AMDP
CLASS-METHODS : call_flight EXPORTING VALUE(et_flights) TYPE tt_flights.
METHOD call_flight BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zjp_simple_amdp_class=>get_flights.
CALL "ZJP_SIMPLE_AMDP_CLASS=>GET_FLIGHTS"( iv_carrid => 'AA',
et_flights => et_flights );
ENDMETHOD.
In SAP Trial system, SFLIGHT table is not accessible. Use below code which uses alternative table.
CLASS zjp_simple_amdp_class DEFINITION
PUBLIC FINAL CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES : if_amdp_marker_hdb.
TYPES : tt_flights TYPE STANDARD TABLE OF /dmo/flight.
METHODS : get_flights IMPORTING VALUE(iv_carrid) TYPE /dmo/flight-carrier_id
EXPORTING VALUE(et_flights) TYPE tt_flights.
CLASS-METHODS : call_flight EXPORTING VALUE(et_flights) TYPE tt_flights.
ENDCLASS.
CLASS zjp_simple_amdp_class IMPLEMENTATION.
METHOD get_flights BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING /dmo/flight.
et_flights = select * from "/DMO/FLIGHT" WHERE carrier_id = :iv_carrid;
ENDMETHOD.
METHOD call_flight BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zjp_simple_amdp_class=>get_flights.
CALL "ZJP_SIMPLE_AMDP_CLASS=>GET_FLIGHTS"( iv_carrid => 'AA',
et_flights => et_flights );
ENDMETHOD.
ENDCLASS.
Visit ABAP on HANA series for Tutorials on CDS, AMDP, Eclipse, and ALV IDA.
If you like the content, please subscribe…