This blog post describes a sample business scenario for validating tax ID formats, and how to do such an extension on the SAP S/4HANA Cloud.
You have administrative access to SAP S/4HANA Cloud and have implementation experience on the system. Coding experience is also necessary, since this extensibility solution requires implementation of a coding logic.
|Business Role||Business Role ID|
|Configuration Expert – Business Network Integration||SAP _ BR _ CONF _ EXPERT _ BUS _ NET _ INT|
|Master Data Specialist – Business Partner Data||MASTER _ SPECIALIST|
For example, you want to validate the format of the tax identification number (TIN) for a country and display an error message in case of an invalid format. You can do so by implementing a cloud BAdI to validate the format. You will also have to create repository to store custom error messages.
Implement the validation Logic
- Create a New Enhancement Implementation using the Custom Logic option in the Custom Fields and Logic app.
- Write the implementation logic for validating the tax ID format in the Draft Logic area and publish the New Enhancement Implementation.
- Enter a solution specific to the purpose of this implementation in the code logic. This is necessary because the BAdI does not have an option to set a filter.
- You need to implement/adapt (duplicate) the provided sample code for each country, for which, the check is applicable.
Additionally, you need to replace the XX Country Code place holders in the coding with country code used in your implementation.
- Since the BADI implementation is referring to the tables where the custom messages are stored, the system will display error messages when you implement the BADI, and before you have created the required message class(es).
- You can create a custom message while implementing the validation logic, or use an existing custom message. If you create a new custom message, you must publish the implementation logic only after storing this message in the repository.
View a sample code using the GitHub link – validate_tax_id.abap
To validate a VAT Number for country ‘XX’
The VAT number should start with an Alphabet (C = company or I=individual ) followed by 11 digits. The first six digits should be the same as the taxpayer’s income tax number.
|Cloud BAdI||Implement the BAdI under the Business Partner Core View ->Validate BP BAdI|
|Result||When a user enters the tax number, the system checks for the correct format and displays an error message in case of an invalid format.|
Create a Repository to Store Custom Messages
- Create a repository for customer messages by creating a Code List using the Custom Reusable Elements app.
- Create a Custom Code list for each country using the following naming convention (so that it fits to the sample BAdI Coding):
Name: MESSAGE_CLASS_XX where XX reflects the Country Code
Code List ID: YY1_MESSAGE_XX
Maximum Code Length: 3
- Specify the translation language and enter the translated text for the custom messages. Do this step only if translation is required.
Since system does not translate the message, you manually enter the translated text for the message in the language, in which, the system must display the message. For example, if the translated text is to be in German, enter the translated message in German.
Test the BAdI Implementation
- Open Customer List in the edit mode on the Custom Master Data app, and select a customer.
- Add a new tax ID number and save it. If the new tax ID number is in an incorrect format, the system will display the error message.
Note: To test the BAdI implementation, log in using an end user authorization profile.
When an end user enters a tax ID number, the system will check for the format that is relevant for the country. If the format is incorrect, it will give the user an error message.
Here is a video that explains how to implement the tax ID format validation – https://video.sap.com/media/t/1_4i23j6rh