Implement a Field Control Using a Business Add-in (`BAdI`)
- How to logon to SAP S/4HANA Cloud ABAP Environment
- How to create an ABAP package
- How to find relevant existing
BAdIenhancement spots for your line of business, in this case Materials-Management-Purchasing
- How to hide a field, Price, by changing the status of a field control
- 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
BAdIsin particular. If not, see the More Information section at the end of this tutorial
The administrator receives an welcome e-mail after provisioning. This e-mail includes the system URL. By removing
/uiyou 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) enables you to implement enhancements to standard SAP applications without modifying the original code.
In this case, the
BAdI is implemented in the SAP Fiori app as follows:
- Use an existing enhancement spot
MM_PUR_S4_PR_FLDCNTRL_SIMPLE, with an existing
- Create a container ( enhancement implementation ) in the enhancement spot
- Create a
BADIimplementation for the
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
Open ADT, select File > New > Other.
Search ABAP Cloud Project, select it and choose Next >.
Select SAP S/4HANA Cloud ABAP Environment, enter the ABAP service instance URL and choose Next.
To log on, choose Open Logon Page in Browser, then choose Next.
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, or use an existing package (for example, if you have already created a
Choose your project, then choose New > ABAP Package from the context menu.
Enter the following.
BADIsfor MM Purchasing
Optional: Choose Add to favorite packages, then choose Next
Choose Create a new request, enter a meaningful description, e.g. Test
BADIsMM-PURCHASING then choose Finish.
- Step 3
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.
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.
In your project, drill down to Released Objects > MM-PUR-VM > Enhancements > Enhancement Spots >
MM_PUR_S4_PR_FLDCNTRL_SIMPLEand open it by double-clicking.
BAdIenhancement spot appears in a new editor, showing you the available
To help you create your own enhancements, example classes are provided (2).
A complete searchable table of available
BAdIsand the Fiori apps to which they pertain is available here:
SAP Help Portal: Adaptation of App Behavior
- Step 4
Next, you need a container within the enhancement spot for your
BADIimplementations. This is known as an enhancement implementation.
Select your package
Zxx_MM_PUR_S4_BADIand choose New > Other ABAP Object from the context menu.
BAdIEnhancement Implementation, then choose Next.
Add the following and choose Next.
- Description: Field control: Change price to hidden
- Enhancement Spot:
Choose the transport request, then choose Finish.
BAdIenhancement implementation appears in a new editor. It implements the enhancement spot
- Step 5
Add the following, then choose Next:
MM_PUR_S4_PR_FLDCNTRL_SIMPLE(Add by clicking on Browse)
Ignore the error. You will fix this in the next step.
- Step 6
Choose Implementing Class.
Add the following, then choose Next.
- Description: Implement hide price for given user
Choose the transport request, then choose Finish.
The class appears in a new editor with skeleton code.
Format, save, and activate the class (
Shift+F1, Ctrl+S, Ctrl+F3).
Go back to your
ZXX_BADI_FLDCONTROL_PO_IMPLand activate it too.
The error will disappear.
- Step 7
Add the following code to the method implementation
* Disclaimer: * Any software coding or code lines / strings ("Code") provided are only examples * and are not intended for use in a productive system environment. The Code is only * intended to better explain and visualize the syntax and phrasing rules for certain * SAP coding. SAP does not warrant the correctness or completeness of the Code * provided herein and SAP shall not be liable for errors or damages cause by use of * the Code, except where such damages were caused by SAP with intent or with gross * negligence. *------------------------------------------------------------------------------------ * Value for FIELDSTATUS can be set to anyone of the following * '-' Field is Hidden * '*' Field is only Displayed, which means no entry is possible * '+' Field is Mandatory, which means an entry must be made * '.' Field is Optional, which means an entry may be made *------------------------------------------------------------------------------------ ** Sample Code **price hidden when created user is 'CB9980000609'. * IF purchaserequisitionitem-createdbyuser EQ 'CB9980000609'. READ TABLE fieldselection_table ASSIGNING <fs> WITH KEY field = 'PURCHASEREQUISITIONPRICE'. IF sy-subrc EQ 0. <fs>-fieldstatus = '-'. ENDIF. ENDIF. ** **Alternative sample code 1: ** price hidden when requisitioner is a specific person ** * enter in field purchase requisitioner = HIDEPRICE * IF purchaserequisitionitem-purreqnrequestor EQ 'HIDEPRICE'. * READ TABLE fieldselection_table ASSIGNING <fs> WITH KEY field = 'PURCHASEREQUISITIONPRICE'. * IF sy-subrc EQ 0. * <fs>-fieldstatus = '-'. * ENDIF. * ENDIF. ** **Alternative sample code 1: ** hide price for all users ** * READ TABLE fieldselection_table ASSIGNING <fs> WITH KEY field = 'PURCHASEREQUISITIONPRICE'. * IF sy-subrc EQ 0. * <fs>-fieldstatus = '-'. * ENDIF.
Format, save, and activate (
Shift+F1, Ctrl+S, Ctrl+F3) your code.
Check that yours is the implementation that will be called:
- Step 8
- Step 9
- Start here: SAP blog post: How to Extend SAP Standard Using ADT
- SAP Help Portal: Working with Business Add-Ins (
- SAP Help Portal: Sourcing and Procurement: Adaptation of App Behavior (Overview and List of Available