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
- Create a Custom Field
- Set up and Install Local ABAP Development Tools (ADT)
- Develop a Custom Function using Demo Implementation
- Create Custom Rule in Manage Substitution/Validation Rules App
- 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.
Create a Custom Field (Administrator)
- Launch your SAP Fiori launchpad.
- Using the Custom Fields app, create and publish a Weekday field in the business context Accounting: Market Segment.
- Optionally, check that the new field is available in the Post General Journal Entries app. (Role: G/L Accountant).
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.
Set up and install ABAP Development Tools (Developer)
- Download and install ABAP Development Tools (ADT) from https://tools.hana.ondemand.com/#abap.
- Follow the installation procedure or check out this interactive tutorial: https://developers.sap.com/tutorials/abap-install-adt.html
- Create an ABAP cloud project with ADT to connect to the ABAP system. See Connect to the ABAP System.
- 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.
Develop a Custom Function using Demo Implementation (Developer)
- 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.
- For this purpose, use the demo implementation in class CL_SUBVAL_WEEKDAY.
- Duplicate the class and adapt the name of the class to your own name space.
- Choose Next to create your own new class that defines a new function within the Manage Substitution/Validation Rules app.
- Select a transport request to transfer your changes.
- Replace all other places in the coding with the new name.
- 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.
- Activate the class.
As soon as this is done, the function will be available in the Manage Substitution/Validation Rules app.
Create a Custom Rule in Manage Substitution/Validation Rules app (Configuration Expert)
- Launch your SAP Fiori launchpad and open the Manage Substitution/Validation Rules app.
- Create a new substitution rule for the Market Segment business context.
- Add a Rule Name and a Description to your substitution rule.
- In the Substitution section, choose the value help for the Target Field. Now, the YY1_WEEKDAY appears in the list.
- As the Substitution Type choose Substitute with Field / Function.
- Choose the value help for the Source Field. Then, choose the custom-defined function that was just implemented by your developer from the list.
- In the pop up, choose Field Value as the input parameter based on which the weekday is calculated.
- Choose the DocumentDate as the field from the value help.
- Save your changes.
- Save the changes made to the substitution rule and activate it.
Derive Field Value (G/L Accountant)
- Go to the Post General Journal Entries app.
- Choose Assign to Profitability Segment.
- 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.