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 PlummerJuly 2, 2025
Created by
julieplummer20
March 9, 2023
Contributors
mervey45
julieplummer20
jmmargo

Prerequisites

  • 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 without 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 implement the BAdI in the SAP Fiori app as follows:
1. For the BAdI definition MM_PUR_S4_PR_CHECK, you create a container, known as an enhancement implementation - here ZEI_BADI_CHECK_PURCH_REQ_000.
2. You can then create one or more BAdI implementations - here ZIMP_CHECK_PURCH_REQ_000.
3. For each BAdI implementation you create an ABAP Class - here ZCL_CHECK_PURCH_REQ_000.
4. Within this class, you then create a method of the BAdI- here MM_PUR_S4_PR_CHECK~check.

step0-badi-enhancement-creation-process-v2

The advantage of this approach is that you can group several related BAdI implementations in one enhancement implementation.

step0-several-zimps

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:

step0-app-overviewstep0-app-w-badi

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

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

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

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

      logon
    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… .)

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

      logon

    Your project is available in the Project Explorer.

    logon
  • Step 2

    First, create a package for your development objects.

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

      step1a-package-new
    2. Enter the following.

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

      step1b-package-name
    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.

      step2b-released-objects
    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.

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

      step2c-enhancement-spot-choose

    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).

    step2d-enhancement-spot-editor
  • 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 Z_MM_PUR_S4_BADI_000 and choose New > Other ABAP Object from the context menu.

      step3a-badi-implem-create
    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
      step3b-badi-enhancement-implem
    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.

    step3c-BAdi-enh-impl-editor

    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
      step5b-badi-input-values

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

  • Step 6
    1. Choose Implementing Class.

      step5a-implementing-class-create
    2. Add the following, then choose Next.

      • Name: ZCL_CHECK_PURCH_REQ_000
      • Description: Implement checks on creating Purchase Requisition
      • (Added automatically): Interfaces: IF_MM_PUR_S4_PR_CHECK
      step5b-implementing-class-name
    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 ZIMP_CHECK_PURCH_REQ_000 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..

      ABAP
      Copy
      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.
      
      ENDIF.
      
      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.
      
      ENDIF.
      
      
    2. Format, save, and activate ( Shift+F1, Ctrl+S, Ctrl+F3 ) your code.

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

    step5d-impl-called

    What is a BAdI enhancement implementation?

  • Step 8

    Now test that the checks are performed in the app.

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

      step7a-app-open
    2. Display the existing purchase requisitions by choosing Go, then choose Create.

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

      step7c-create-material
    4. The Details screen appears. From the Material field, choose Value Help.

    5. Then choose the material RM122, Plant 1010.

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

      step7f-wrong-date-and-quantity
    7. The system shows you 2 errors. To display the errors, select the red box at the bottom left.

      step7g-errors
    8. Enter correct values, choose Apply, then choose Save.

    Your new order appears in the Overview List.
    .

    step7h-new-order
  • Step 9
  • Step 10

Back to top