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:
Sales Order Creation: Automatically reserve stock or trigger purchase requisitions if stock is insufficient. Order Status Tracking: Provide real-time updates on sales order status. Delivery Management: Update the status of deliveries once completed.
Steps to achieve AMDP CURD Operations:
Create a AMDP class.
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.
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.
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.
Output:
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.
Output:
Read Operations:
METHOD read_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.
it_booking = SELECT * FROM zgr_t_booking ;
ENDMETHOD.
Output:
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.
Output:
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.
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: Sales Order Creation: Automatically reserve stock or trigger purchase requisitions if stock is insufficient. Order Status Tracking: Provide real-time updates on sales order status. Delivery Management: Update the status of deliveries once completed. Steps to achieve AMDP CURD Operations: Create a AMDP class.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. 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. 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. Output: 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. Output: Read Operations: METHOD read_data BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT USING zgr_t_booking.
it_booking = SELECT * FROM zgr_t_booking ;
ENDMETHOD. Output: 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. Output: 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. Read More Application Development Blog Posts articles
#SAP