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
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) 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 BADI definition MM_PUR_S4_PR_FLDCNTRL_SIMPLE
Create a container ( enhancement implementation ) in the enhancement spot
Create a BADI implementation for the BADI definition.
step0-badi-creation-enhancement-process
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 1Log on to SAP S/4HANA Cloud ABAP Environment
โ
Open ADT, select File > New > Other.
logon
Search ABAP Cloud Project, select it and choose Next >.
logon
Select SAP S/4HANA Cloud ABAP Environment, enter the ABAP service instance URL and choose Next.
logon
To log on, choose Open Logon Page in Browser, then choose Next.
logon.logon
Check your ABAP service instance connection and choose Finish.
logon
Your project is available in the Project Explorer.
logon
Step 2Create package
+
First, create a package for your development objects, or use an existing package (for example, if you have already created a BAdI.)
Choose your project, then choose New > ABAP Package from the context menu.
step1a-package-new
Enter the following.
Zxx_MM_PUR_S4_BADI
BADIs for MM Purchasing
Optional: Choose Add to favorite packages, then choose Next
step1b-package-name
Choose Create a new request, enter a meaningful description, e.g. Test BADIs MM-PURCHASING then choose Finish.
Step 3Choose enhancement spot
+
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
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_SIMPLE and open it by double-clicking.
step2c-enhancement-spot-choose-field-control
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
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 4Create enhancement implementation
+
Next, you need a container within the enhancement spot for your BADI implementations. This is known as an enhancement implementation.
Select your package Zxx_MM_PUR_S4_BADI and choose New > Other ABAP Object from the context menu.
step3a-badi-implem-create
Filter by BAdI, choose BAdI Enhancement Implementation, then choose Next.
Add the following and choose Next.
Name: Zxx_BADI_FIELD_CONTROL_PO
Description: Field control: Change price to hidden
Enhancement Spot: MM_PUR_S4_PR_FLDCNTRL_SIMPLE
step3c-BAdi-enh-impl-editor-hide-price
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_FLDCNTRL_SIMPLE.
step3d-badi-enh-impl-editor-field-control
Step 5Add `BAdI` Implementation
+
Choose Add BAdI.
step4a-badi-impl-add
Add the following, then choose Next:
BAdI Definition: MM_PUR_S4_PR_FLDCNTRL_SIMPLE (Add by clicking on Browse)
The class appears in a new editor with skeleton code.
step5c-class-editor
Format, save, and activate the class ( Shift+F1, Ctrl+S, Ctrl+F3 ).
Go back to your BAdI implementation ZXX_BADI_FLDCONTROL_PO_IMPL and activate it too.
The error will disappear.
Step 7Implement code
+
Add the following code to the method implementation if_mm_pur_s4_pr_fldcntrl~modify_fieldcontrols.
ABAP
* 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'.*IFpurchaserequisitionitem-createdbyuserEQ'CB9980000609'.READTABLEfieldselection_tableASSIGNING<fs>WITHKEYfield='PURCHASEREQUISITIONPRICE'.IFsy-subrcEQ0.<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:
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 9
1. Log on to SAP S/4HANA Cloud ABAP Environment2. Create package3. Choose enhancement spot4. Create enhancement implementation5. Add `BAdI` Implementation6. Create implementing class7. Implement code8. Test yourself9. More information
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.