AMDP – A Quick Code Start

light111AMDP – A Quick Code Start

Let’s start  with how the syntax looks like for the AMDP class and method:


CLASS amdp_class DEFINITION. PUBLIC SECTION. * Marker interface with SAP HANA DB as database type INTERFACES IF_AMDP_MARKER_DB_TYPE. METHODS amdp_method. ENDCLASS. CLASS amdp_class IMPLEMENTATION. * AMDP method METHOD amdp_method BY DATABASE PROCEDURE FOR db_type LANGUAGE db_language OPTIONS db_options USING db_entity. "Implementation of the procedure in a DB-specific language ENDMETHOD. ENDCLASS.

Open eclipse or HANA studio and in ABAP perspective create a class.

The marker interface IF_AMDP_MARKER_HDB must be implemented to enable it as AMDP class.

The method implementation must its a DATABASE PROCEDURE and other options.

0.jpg

Code Lines:


CLASS zcl_flight_calc DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. * Marker interface with SAP HANA DB as database type INTERFACES: if_amdp_marker_hdb. METHODS: get_flight_detail IMPORTING VALUE(iv_carrid) TYPE sflight-carrid EXPORTING VALUE(et_flight) TYPE flighttab. ENDCLASS. CLASS zcl_flight_calc IMPLEMENTATION. METHOD get_flight_detail BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING SFLIGHT. * Implementation of the procedure in a DB-specific language et_flight = SELECT * FROM sflight WHERE carrid = iv_carrid; ENDMETHOD. ENDCLASS.


Let’s test the method.

2

Test the method.

3

Provide some input value.

4

Some results found.

5

It brings records from all  the clients. So SQLSCRIPT doesn’t handle implicit client as open SQL.

6

To get current client specific data: either client number can be pas explicitly with one more importing parameter or in the method itself the function SESSION_CONTEXT( ) can be used as shown.

7

Test the method.

8

So we receive the client specific data.

9


The above AMDP method is used just to read some data [OPTIONS READ-ONLY]. Lets add one more method where we can do change on DB record. Then for such a method OPTIONS READ-ONLY must not be specified.

10

Test. Check what are the values.

11

Modify fields for CARRID.

12

Check again.

13

So its updated.

14


Important Points: 1. Transaction control commands like COMMIT WORK /ROLLBACK WORK are not allowed inside AMDP method. 2. Update statement can not be performed on BUFFERED tables inside AMDP method. 3. AMDP are a part of native SQL and don't support automatic client handling.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s