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: 
sowjanya_hr
Explorer
3,733

Introduction to AMDP in Business add in: Revolutionizing ABAP Development

As businesses move towards SAP HANA, leveraging its in-memory computing capabilities becomes essential for developing efficient and high-performing applications. One of the critical tools in this journey is the ABAP Managed Database Procedures (AMDP). When combined with Business Add-Ins , AMDP provides a powerful way to customize and enhance SAP applications, especially when performance is a concern. In this blog, we'll dive into what AMDP is, how it can be used within Business Add-Ins, and the benefits it brings to the table.

What is a Business Add-Ins? 

Business Add-Ins (Business Add-Ins) are SAP's standard mechanism for extending the functionality of SAP applications without modifying the original code. Business Add-Ins provide predefined hooks or enhancement spots where custom code can be inserted. This makes Business Add-Ins a powerful tool for customizations in SAP. 

Combining AMDP with Business Add-Ins: Why and When? 

When implementing Business Add-Ins, the custom logic traditionally runs on the ABAP application server, which might not fully exploit the capabilities of SAP HANA. However, by integrating AMDPs within a Business Add-Ins, you can move resource-intensive operations to the database level. This is particularly useful for scenarios where the custom logic involves complex data retrieval, aggregation, or transformation, as these operations are executed much faster on the HANA database. 

  Benefits of Using AMDP in Business Add-Ins 

  1. Performance: By offloading data-intensive operations to the HANA database, you can significantly reduce the time taken to execute these operations, especially on large datasets. 
  1. Efficiency: AMDP enables you to write optimized database-specific logic , which is more efficient than executing equivalent logic on the application server. 
  1. Scalability: As your data volume grows, AMDP-based solutions can scale more effectively because they leverage the power of in-memory processing directly on the database. 
  1. Maintenance: AMDPs can reduce the complexity of ABAP code by delegating heavy data processing tasks to the database level, making the ABAP codebase cleaner and easier to maintain. 

Best Practices 

  • Use Read-Only AMDPs: Ensure that your AMDP methods are marked as read-only unless you specifically need to update the database. This reduces the risk of unintended side effects and enhances performance. 
  • Error Handling: Implement robust error handling in your AMDP methods to handle any database-related issues gracefully. 
  • Testing: Thoroughly test your AMDP logic with different data volumes to ensure that it performs as expected under various scenarios. 

There are some rules if a Business Add-Ins is marked as AMDP 

  •  It doesn't support any filter values. 
  • It’s mandatory to assign a fallback class 
  • All AMDP Business Add-Ins method must implemented AMDP procedure with same database system 
  • AMDP enabled BADI can be instantiated and called like general Business Add-Ins GET BADI and CALL BADI 

Now we will see the practical things how to use BADI in AMDP 

1.Create a enhancement spot in se18 T-code 

sowjanya_hr_0-1724141233011.png

2.Create BADI Definition for the Enhance spot. 

sowjanya_hr_1-1724141233013.png

 

3.Once you created Business Add-Ins definition click on the AMDP Business Add-Ins checkbox 

sowjanya_hr_2-1724141233015.png

4.Create Interface for that BADI 

sowjanya_hr_3-1724141233017.png

5.Once you created interface go to source code-Based 

sowjanya_hr_4-1724141233018.png

 

6.There provide ID_AMDP_MARKER_HDB interfaces and declare the method  and activate it. 

sowjanya_hr_5-1724141233019.png

 

7.We have to create the Fallback class if you didn’t create the fallback class it will gives the error

sowjanya_hr_6-1724141233021.png

 

sowjanya_hr_7-1724141233023.png

8.Copy the fallback class name now go to eclipse by providing alt+f8 we can find the fallback class in eclipse  

sowjanya_hr_8-1724141233024.png

9.Provide the implementation to the fallback class 

sowjanya_hr_9-1724141233025.png

 

10.Now we can activate the Business Add-Ins

sowjanya_hr_10-1724141233027.png

 

sowjanya_hr_11-1724141233029.png

11.To call the Business Add-Ins we have to create one more ABAP class in eclipse. 

sowjanya_hr_12-1724141446391.png

  • We have to use Business Add-Ins? definition name while calling the method  

 

sowjanya_hr_13-1724141446393.png

12.Now create a report program

sowjanya_hr_14-1724141446394.png

 

sowjanya_hr_15-1724141446398.png

Refer the code Below 

 

 

class ZSH_AMDP_FALLBACK_FLIGHTS1 definition 

public 

final 

create public . 

 

public section. 

 

interfaces IF_AMDP_MARKER_HDB . 

interfaces IF_BADI_INTERFACE . 

interfaces ZSH_IF_FLIGHT_DETAILS1 . 

protected section. 

private section. 

ENDCLASS. 

 

 

 

CLASS ZSH_AMDP_FALLBACK_FLIGHTS1 IMPLEMENTATION. 

METHOD ZSH_IF_FLIGHT_DETAILS1~fetch_data by DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING sflight. 

et_flight = SELECT * FROM sflight WHERE carrid = iv_carrid; 

ENDMETHOD. 

ENDCLASS. 

 

CLASS zsh_cl_amdp_badi1 DEFINITION 

PUBLIC 

FINAL 

CREATE PUBLIC . 

 

PUBLIC SECTION. 

INTERFACES : if_amdp_marker_hdb. 

 

METHODS : execute IMPORTING VALUE(iv_carrid) TYPE sflight-carrid 

EXPORTING VALUE(et_flight) TYPE flighttab. 

PROTECTED SECTION. 

PRIVATE SECTION. 

ENDCLASS. 

 

 

 

CLASS zsh_cl_amdp_badi1 IMPLEMENTATION. 

METHOD execute BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY USING ZSH_BADI_DEF_FLIGHT1=>FETCH_DATA. 

CALL "ZSH_BADI_DEF_FLIGHT1=>FETCH_DATA"(iv_carrid => :iv_carrid , et_flight => :et_flight); 

ENDMETHOD. 

ENDCLASS. 

 

REPORT ZSH_RP_AMDP_BADI1. 
  
DATA(lo_obj) = new zsh_cl_amdp_badi1( ). 
  
lo_obj->execute( 
   EXPORTING 
     iv_carrid =  'AA' 
   IMPORTING 
     et_flight = DATA(lt_flight) 
 ). 
 cl_demo_output=>display( lt_flight ). 

 

 

 

Why AMDP Business Add-Ins? 

  • AMDP Business Add-Ins are used to execute calls of AMDP  procedures from AMDP procedure with enhancement concept. 
  • When you created a BADI inside that Business Add-Ins you have one normal method when you implemented the Business Add-Ins the normal method gets implemented 
  • In case of AMDP Business Add-Ins inside that Business Add-Ins AMDP method will be there instead of normal method. So that whenever you implemented the Business Add-Ins AMDP method gets implemented .

Purpose  Of AMDP Business Add-Ins 

  • To give a full flexibility to the users to  implement the AMDP method the way he wants. So as of now when you created AMDP your defining your method also implementing your method inside a AMDP 
  • When you create AMDP enhancement you will be creating or defining AMDP method however you will be giving full flexibility to the user.