Add custom logic in standard Fiori app using Custom Logic App

With Custom Logic app, you can add your own business logic to SAP standard applications and backend process. The added logic is protected by SAP as only released BAdI are allowed to implement the custom logic.

Depending on which S4 version you are, this app is now part of Custom Fields app. If you are using app with title Custom Fields and Logic, it will most likely be deprecated in the later release.

If you only have Custom Fields app, go into the Fiori app and you can see three tabs on the top(Custom Fields, Datasource Extension, Custom Logic).

The Setup

In this blog, we will learn how this Custom Logic works by doing a simple exercise to add our custom logic to Manage Cost Center app and if User Responsible in Cost Center is not entered, returns error message to ask user to input the field.

1. Create an Enhancement Implementation

Go to Custom Logic app(or Custom Logic inside Custom Fields app) in Fiori and create a new implementation. Choose Cost Center Master Data as business context and choose ‘Cost center on save action’.

You will see the coding panel where custom logic can be added. You will also see the parameter available that holds the cost center master data at runtime.

2. Add custom check and test it

Change the code so that we implement our own logic to check the entry Person Responsible. Save the change and Publish the implementation.

*--------------------------------------------------------------------*
*** BAdI usage
*-- In this BAdI you are able to check the field values,
*-- or update the fields before they are stored in DB.
*--------------------------------------------------------------------*

*   Case: Check Responsible person 
    DATA: ls_validationmessage  LIKE LINE OF ct_messages.

    IF cs_cost_center-costctrresponsibleuser IS INITIAL.
      ls_validationmessage-msgid = 'FCO_COST_CENTER'.
      ls_validationmessage-msgno = '031'.
      ls_validationmessage-msgty = 'E'.
      ls_validationmessage-msgv1 = 'The Field User Responsible must be filled'.
      INSERT ls_validationmessage INTO TABLE ct_messages.
    ENDIF.

Now let’s test the custom check. Go to Manage Cost Center app and create or edit a cost center. If you leave User Responsible open and save, you should get an error message defined in the custom logic.

3. Debugging custom logic

Find the implementation ID in Custom Fields app. In our case, ZZ1_COSTCENTERVALIDATEONSAVE.

Go to SE19 and enter the name in New BAdI.

Go to implementation class and double click IF_FIN_COST_CENTER_ON_SAVE~EXECUTE. You should be able to see your custom code.

Set external breakpoint on the first line of logic.(external because user is accessing from Fiori)

Go to Manage Cost Center app again and save a cost center. It will load and a separate debug session should appear in your SAP GUI.