Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
Showing results for 
Search instead for 
Did you mean: 
In this blog post, I want to show you step-by-step how to use the Custom Function interface to extend the code in the Manage Substitution/Validation Rules app with customer-defined functions, and adapt it to your business needs. To better illustrate the procedure, I’ll provide you with an example implementation.

Note: Developer extensibility is only available in SAP S/4HANA Cloud with a 3-system landscape. For more information about system landscapes, see System Landscapes in SAP S/4HANA Cloud.

Content Overview

    1. Create a Custom Field

    2. Set up and Install Local ABAP Development Tools (ADT)

    3. Develop a Custom Function using Demo Implementation

    4. Create Custom Rule in Manage Substitution/Validation Rules App

    5. Derive Field Value

Business Background

In general, the Manage Substitution/Validation Rules app allows you to display, change, and create substitution and validation rules for selected business contexts and events. These rules can be used in the respective business processes to validate, derive, or replace values at the time of entry for the relevant fields.

When you record documents or other relevant data in Finance, for example, the quality of data is key to ensure correct legal and management reporting. Incorrect data should be detected as early and as quickly as possible to avoid costs and efforts that arise from subsequent errors in reports and corresponding decision-making.

In addition, different business processes require the substitution of values in financial documents. Field values are either derived or changed based on the specific context of a transaction.

Example Business Scenario

Market segmentation in Margin Analysis is used to make the profit of an individual enterprise area (market segment) transparent in your reporting. Market segments are a combination of, for example customers, products, or sales organizations. SAP provides the possibility to substitute field values for the characteristics in your market segments.

A business scenario, in which the possibility to extend the code of the Manage Substitution/Validation Rules app might come in handy, is analyzing the profitability of a market segment according to the weekday of the posting dates.

To start, the administrator in your company adds a custom field ‘YY1_WEEKDAY’ to the business context Accounting: Market Segment in the Custom Fields app. However, this isn’t sufficient since the automatic calculation of the weekday corresponding to the posting date of a business transaction isn’t available out of the box. The G/L accountant would have to add the weekday to the journal entry, manually, using the Post General Journal Entries app.

So, this is where the new Custom Function interface comes into play. Let’s see how the automatic derivation of the weekday can be added to the Manage Substitution/Validation Rules app.

Please note that this is just an example of a custom function, which is meant to illustrate the calculation of a value inside a substitution or validation rule. Instead of this weekday calculation, any functional logic could be wrapped in such a function and thus, be made available inside the Manage Substitution/Validation Rules app.

Step-by-Step Procedure

Note: All screenshots in this blog post are taken from an SAP S/4HANA Cloud test system and are based on the UI as delivered standard by SAP. Interfaces may differ slightly depending on the version of your apps or on your configuration settings.

  1. Create a Custom Field (Administrator)

    1. Launch your SAP Fiori launchpad.

    2. Using the Custom Fields app, create and publish a Weekday field in the business context Accounting: Market Segment.

    3. Optionally, check that the new field is available in the Post General Journal Entries app. (Role: G/L Accountant).

    4. Choose Assign Profitability Segment in Line Item section.
      Note: If the field isn't visible, enable the corresponding UI for your field in the Custom Fields app above and Publish the custom field again.

  2. Set up and install ABAP Development Tools (Developer)

    1. Download and install ABAP Development Tools (ADT) from https://tools.hana.ondemand.com/#abap.

    2. Follow the installation procedure or check out this interactive tutorial: https://developers.sap.com/tutorials/abap-install-adt.html

    3. Create an ABAP cloud project with ADT to connect to the ABAP system. See Connect to the ABAP System.

    4. Create an ABAP package. See Creating ABAP Packages.Now that you’ve installed and set up your ADT environment, you can start enhancing the existing code in the Manage Substitution/Validation Rules app by implementing the Custom Function interface.

      Tip: To familiarize yourself further with the development in ADT, see ABAP Development User Guide.

  3. Develop a Custom Function using Demo Implementation (Developer)

    1. Open the interface by choosing Navigate > Open ABAP Development Object from the menu bar or use the keyboard combination Ctrl+Shift+A. Then, enter the name of the interface in the search bar: IF_FIN_RE_CUSTOM_FUNCTION.Note: The interface and the class contain thorough inline documentation, which should support you in implementing your custom function.

    2. For this purpose, use the demo implementation in class CL_SUBVAL_WEEKDAY.

    3. Duplicate the class and adapt the name of the class to your own name space.

    4. Choose Next to create your own new class that defines a new function within the Manage Substitution/Validation Rules app.

    5. Select a transport request to transfer your changes.

    6. Replace all other places in the coding with the new name.

    7. Remove the method IF_FIN_RE_CUSTOM_FUNCTION~is_disabled.
      Note: The demo implementation is hidden by default. This is why this step is necessary.

    8. Activate the class.
      As soon as this is done, the function will be available in the Manage Substitution/Validation Rules app.

  4. Create a Custom Rule in Manage Substitution/Validation Rules app (Configuration Expert)

    1. Launch your SAP Fiori launchpad and open the Manage Substitution/Validation Rules app.

    2. Create a new substitution rule for the Market Segment business context.

    3. Add a Rule Name and a Description to your substitution rule.

    4. In the Substitution section, choose the value help for the Target Field. Now, the YY1_WEEKDAY appears in the list.

    5. As the Substitution Type choose Substitute with Field / Function.

    6. Choose the value help for the Source Field. Then, choose the custom-defined function that was just implemented by your developer from the list.

    7. In the pop up, choose Field Value as the input parameter based on which the weekday is calculated.

    8. Choose the DocumentDate as the field from the value help.

    9. Save your changes.

    10. Save the changes made to the substitution rule and activate it.

  5. Derive Field Value (G/L Accountant)

    1. Go to the Post General Journal Entries app.

    2. Choose Assign to Profitability Segment.

    3. In the pop up that appears choose Derive and the current weekday is derived.

Wrap Up

This blog post guided you through the procedure of extending the Manage Substitution/Validation Rules app with custom code. The weekday class is a simple example of a calculation wrapped in a function, which is then integrated into the app.

In addition to custom-defined functions, the app also allows the configuration expert to integrate existing functionality into substitution or validation rules using the predefined functions: CONCATENATE and SUBSTRING.

Would you like to read more process descriptions? Then provide your feedback and comments in the section below this post.

To get answers to your questions, post a question in the Q&A of the SAP Community and use the tag FIN Finance.

More Information

For more information about the Manage Substitution/Validation Rules app, see the following documentation: Manage Substitution/Validation Rules , SAP Note 3093515.