Skip to Content

Implement a Business Add-in (`BAdI`) To Check a Purchase Requisition

Define and implement a developer extension (`BAdI`), which performs checks during creation of a purchase requisition item.
You will learn
  • How to log on to SAP S/4HANA Cloud ABAP Environment
  • How to create an ABAP package
  • How to find relevant existing BAdI enhancement spots for your line of business, in this case Materials-Management-Purchasing
  • How to implement a BAdI that checks for the field quantity and delivery date during creation of purchase requisition item
julieplummer20Julie PlummerFebruary 2, 2023
Created by
September 28, 2021


  • You have a license for SAP S/4HANA Cloud and have a developer user in this system
  • You have installed SAP ABAP Development Tools (ADT), latest version, and have created an ABAP Cloud project for your SAP S/4HANA Cloud System in it
  • You are familiar with the concept of extensions to the SAP standard and with BAdIs in particular. If not, see the More Information section at the end of this tutorial
  • To test the BAdI: In SAP Fiori launchpad, you have the authorization for the app Process Purchase Requisitions - Professional, i.e. SAP_BR_PURCHASER

The administrator receives an welcome e-mail after provisioning. This e-mail includes the system URL. By removing /ui you can log into the SAP S/4HANA Cloud ABAP Environment system. Further information can be found Developer Extensibility: Connect to the ABAP System.

A Business Add-In (BAdI) an object-oriented enhancement option, a hook for an object plug-in. It enables you to implement enhancements to standard SAP applications with out modifying the original code.

In these tutorials, SAP has already defined the BAdI enhancement spot, MM_PUR_S4_PR for the Fiori App Manage Purchase Requisitions – Professional, and the BAdI definition, MM_PUR_S4_PR_CHECK.

You then implemented the BAdI in the SAP Fiori app as follows:
1. At the BAdI definition MM_PUR_S4_PR_CHECK, you create a container, known as a BAdI implementation, containing a class.
2. You then create a method (i.e. implementation) within this class.

Thus it becomes a BAdI implementation for this BAdI definition.


At runtime:

  1. The user creates a purchase requisition.
  2. The enhancement checks:
    • the quantity of items ordered is 10 or fewer
    • the date is 180 days or fewer in advance
  3. If not, the application returns an error.

The application will look roughly like this:




Throughout this tutorial, objects name include a prefix, such as xx or suffix, such as XXX. Always replace this with your group number or initials.

  • Step 1
    1. Open ADT, select File > New > Other.

    2. Search ABAP Cloud Project, select it and choose Next >.

    3. Select SAP S/4HANA Cloud ABAP Environment, enter the ABAP service instance URL and choose Next.

    4. To log on, choose Open Logon Page in Browser, then choose Next. (Alternatively, e.g. if you have an admin user and a developer user in the SAP BTP Cloud landscape, you may need to choose Copy Logon URL… .)

    5. Check your ABAP service instance connection and choose Finish.


    Your project is available in the Project Explorer.

  • Step 2

    First, create a package for your development objects.

    1. Choose your project, then choose New > ABAP Package from the context menu.

    2. Enter the following.

      • Z_MM_PUR_S4_BADI_000
      • First BADI for MM Purchasing
    3. Choose Add to favorite packages, then choose Next

    4. Choose Create a new request, enter a meaningful description, e.g. Test BADIs MM-PURCHASING then choose Finish.

  • Step 3
    1. First make sure that the released APIs are displayed by application component: In your project, navigate to Released Objects.The tree should show the Released Objects sorted by Application Component.

    2. If not, choose Configure Tree from the context menu, then select Application Component from the left side ( Available Tree Levels ) and add it to the right side ( Selected Tree Levels ). Move it to the top. Then choose Finish.




    3. In the tree, drill down to MM-PUR-REQ > Enhancements > Enhancement Spots > MM_PUR_S4_PR and open it by double-clicking.


    The BAdI enhancement spot appears in a new editor, showing you the available BAdI definitions (1).

    To help you create your own enhancements, example classes are provided (2).

  • Step 4

    Now that you have identified the correct enhancement spot, you need a container within this enhancement spot for your BAdI implementations. This is known as an enhancement implementation.

    1. Select your package Zxx_MM_PUR_S4_BADI and choose New > Other ABAP Object from the context menu.

    2. Filter by BAdI, choose BAdI Enhancement Implementation, then choose Next.

    3. Enter the following and choose Next.

      • Name: ZEI_BADI_CHECK_PURCH_REQ_000
      • Description: Check date and quantity in Purchase Requisition
      • Enhancement Spot: MM_PUR_S4_PR
    4. Choose the transport request, then choose Finish.

    Your BAdI enhancement implementation appears in a new editor. It implements the enhancement spot MM_PUR_S4_PR.


    A complete searchable table of available BAdIs and the Fiori apps to which they pertain is available here:
    SAP Help Portal: Adaptation of App Behavior

  • Step 5
    1. In the BAdI enhancement implementation, choose Add BAdI implementation.

    2. Add the following, then choose Next:

      • BAdI Definition: MM_PUR_S4_PR_CHECK (Provided by SAP; add by clicking on Browse)
      • BAdI Implementation Name: ZIMP_CHECK_PURCH_REQ_000

    Ignore the error. You will fix this in the next step.

  • Step 6
    1. Choose Implementing Class.

    2. Add the following, then choose Next.

      • Description: Implement checks on creating Purchase Requisition
      • (Added automatically): Interfaces: IF_MM_PUR_S4_PR_CHECK
    3. Choose the transport request, then choose Finish.

      The class appears in a new editor with skeleton code.

    4. Format, save, and activate the class ( Shift+F1, Ctrl+S, Ctrl+F3 ).

    5. Go back to your BAdI implementation ZXX_IMPL_CHECK_PURCH_REQ and activate it too.

    The error will disappear.

  • Step 7
    1. Add the following code to the method implementation if_mm_pur_s4_pr_check~check..

      DATA ls_message TYPE mmpur_s_messages.
      READ TABLE  purchaserequisitionitem_table  INTO DATA(ls_pur_req_itm) INDEX 1    .
      IF ls_pur_req_itm-orderedquantity > 10.
        ls_message-messageid = 'DUMMY'.
        ls_message-messagetype = 'E'.
        ls_message-messagenumber = '001'.
        ls_message-messagevariable1 = ' Quantity limit 10'.           "Place holder
        APPEND ls_message TO messages.
      IF ls_pur_req_itm-deliverydate - ( cl_abap_context_info=>get_system_date( ) ) > 180.
        ls_message-messageid = 'DUMMY'.
        ls_message-messagetype = 'E'.
        ls_message-messagenumber = '001'.
        ls_message-messagevariable1 = 'Delivery date limit 180 days '.           "Place holder
        APPEND ls_message TO messages.
    2. Format, save, and activate ( Shift+F1, Ctrl+S, Ctrl+F3 ) your code.

    3. Check that yours is the implementation that will be called:

  • Step 8

    Now test that the checks are performed in the app.

    1. In SAP Fiori launchpad, open the app Manage Purchase Requisitions (Professional).

    2. Display the existing purchase requisitions by choosing Go, then choose Create.

    3. In the next screen, choose Create again, then choose Material.

    4. The Details screen appears. From the Material field, choose Value Help.

    5. Then choose the material RM122, Plant 1010.

    6. The system fills some fields with default values. Now enter a wrong quantity, e.g. 20, and date, e.g. 09.11.2021.

    7. The system shows you 2 errors. To display the errors, select the red box at the bottom left.

    8. Enter correct values, choose Apply, then choose Save.

    Your new order appears in the Overview List.


    What is a BAdI enhancement implementation?

  • Step 9

  • Step 10

Back to top