Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Golla_rusitha
Explorer
3,257

AMDP CURD OPERATIONS 

 AMDP CURD Operations: 

AMDP (ABAP Managed Database Procedures) is a feature in SAP HANA that allows you to write database procedures in SQL Script directly within the ABAP environment. AMDP provides a seamless way to execute database-level operations from ABAP while leveraging the power of HANA's in-memory capabilities. When it comes to CRUD operations (Create, Read, Update, Delete), here's how they are typically handled with AMDP: 

Why Use AMDP for CRUD Operations? 

Performance: AMDPs run directly on the database layer, making them faster than traditional ABAP for complex operations. 

Complex Scenarios: 
AMDP can handle bulk data operations efficiently, such as processing thousands of orders in real time. 

Seamless Integration: 

AMDP allows developers to stay in the ABAP environment while leveraging HANA’s advanced database features like parallel processing. 

Business Scenarios: 

A manufacturing company wants to streamline its sales process to ensure accurate order fulfillment and improve customer satisfaction. The company uses AMDP in the SD module to handle the following tasks: 

  1. Sales Order Creation: Automatically reserve stock or trigger purchase requisitions if stock is insufficient. 
  1. Order Status Tracking: Provide real-time updates on sales order status. 
  1. Delivery Management: Update the status of deliveries once completed. 

 Steps to achieve AMDP CURD Operations: 

Create a AMDP class.

Golla_rusitha_0-1737443345689.png

Golla_rusitha_1-1737443345693.png

Most important part is here is, if you want to use any class with AMDP’s, you have to implement “ if_amdp_marker_hdb” interface. 

Golla_rusitha_2-1737443345694.png

So when you are writing the method of the class you have to add some keywords with which tables you are going to use, if not you cannot do any operations on these tables. 

So we add both method declarations and table names to our methods. 

Golla_rusitha_3-1737443345695.png

Create operation: 

 

METHOD create_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking. 

it_insert_data = SELECT 'BID0000103', 'RUSHITHA', 'KADAPA', 'BANGALORE', 100, ' ' frOM dummy ; 
inSERT iNTO zgr_t_booking seLECT * FROM :it_insert_data ; 

ENDMETHOD.

 

Golla_rusitha_4-1737443661442.png

Output: 

Golla_rusitha_5-1737443661443.png

Update Operation: 

 

METHOD update_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.

UPDATE zgr_t_booking SET passenger_name = 'RESHMA' WHERE booking_id = 'BID0000103' ; 

ENDMETHOD. 

 

Golla_rusitha_6-1737443879103.png

Output: 

Golla_rusitha_7-1737443879105.png

Read Operations: 

 

METHOD read_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking. 

it_booking = SELECT * FROM zgr_t_booking ; 

ENDMETHOD. 

 

Golla_rusitha_8-1737443999115.png

Output: 

Golla_rusitha_9-1737443999116.png

Golla_rusitha_10-1737443999117.png

Delete Operation: 

 

METHOD delete_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking. 

DELETE fROM zgr_t_booking WHERE booking_id = 'BID0000101' ; 

ENDMETHOD. 

 

Golla_rusitha_11-1737444116019.png

Output: 

Golla_rusitha_12-1737444116020.png

AMDP CURD operation Entire Logic :

 

CLASS zcl_gr_amdp_curd DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    TYPES: tt_booking TYPE TABLE OF zgr_t_booking.

    INTERFACES if_amdp_marker_hdb.
    CLASS-METHODS : create_data,
      update_data,
      read_data EXPORTING VALUE(it_booking) TYPE tt_booking,
      delete_data.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_gr_amdp_curd IMPLEMENTATION.

  METHOD create_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.

    it_insert_data = SELECT 'BID0000103', 'RUSHITHA', 'KADAPA', 'BANGALORE', 100,'' frOM dummy ;

    inSERT iNTO zgr_t_booking seLECT * FROM :it_insert_data ;

  ENDMETHOD.

  METHOD update_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.

    UPDATE zgr_t_booking SET passenger_name = 'RESHMA' WHERE booking_id = 'BID0000103' ;

  ENDMETHOD.

  METHOD read_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.

    it_booking = SELECT * FROM zgr_t_booking ;

  ENDMETHOD.

  METHOD delete_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.

    DELETE fROM zgr_t_booking WHERE booking_id = 'BID0000101' ;

  ENDMETHOD.
ENDCLASS.

 

1 Comment