Using AMDP in BADI implementation in SAP

Estimated read time 10 min read

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 

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. Efficiency: AMDP enables you to write optimized database-specific logic , which is more efficient than executing equivalent logic on the application server. 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. 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 

2.Create BADI Definition for the Enhance spot. 

 

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

4.Create Interface for that BADI 

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

 

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

 

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

 

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

9.Provide the implementation to the fallback class 

 

10.Now we can activate the Business Add-Ins

 

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

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

 

12.Now create a report program

 

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. 

 

 

 

 

 

​ Introduction to AMDP in Business add in: Revolutionizing ABAP DevelopmentAs 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 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. Efficiency: AMDP enables you to write optimized database-specific logic , which is more efficient than executing equivalent logic on the application server. 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. 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 2.Create BADI Definition for the Enhance spot.  3.Once you created Business Add-Ins definition click on the AMDP Business Add-Ins checkbox 4.Create Interface for that BADI 5.Once you created interface go to source code-Based  6.There provide ID_AMDP_MARKER_HDB interfaces and declare the method  and activate it.  7.We have to create the Fallback class if you didn’t create the fallback class it will gives the error 8.Copy the fallback class name now go to eclipse by providing alt+f8 we can find the fallback class in eclipse  9.Provide the implementation to the fallback class  10.Now we can activate the Business Add-Ins 11.To call the Business Add-Ins we have to create one more ABAP class in eclipse. We have to use Business Add-Ins? definition name while calling the method   12.Now create a report program  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.        Read More Application Development Blog Posts articles 

#SAP

You May Also Like

More From Author