In this unit, you'll learn how to set up automatic checks for business partner tax numbers in SAP S/4HANA. This check helps ensure that tax numbers are correctly formatted and valid before they are saved in the system.
This implementation validates business partner tax numbers through three main configuration steps.
Implementation Steps
- 1. Define Tax Number Categories
- Configure tax number categories in SAP Central Business Configuration. These categories are required when adding tax numbers to business partner master data and will be referenced in our custom validation. We do this with the configuration activity Define Tax Number Categories (104758).
- 2. Create Custom Code List
- Set up error messages in the Custom Reusable Elements app:
Code Descriptions 001 Tax number must start with 'C' or 'I' 002 Tax number must be 12 characters long 003 Characters 2-12 must be numerical digits - 3. Create Custom Logic Implementation
- Build the validation implementation using the "Custom Logic" app. The implementation will:
- Reference the configured tax number category
- Use the custom code list for error messages
- Validate tax numbers against the defined rules
For the implementation the following code will be used.
Code Snippet12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849DATA ls_message LIKE LINE OF ct_validationmessage. DATA ls_tax_num LIKE LINE OF it_bp_tax_num. DATA lv_digits TYPE string VALUE '0123456789'. DATA lv_message TYPE string. DATA: lv_len_tax TYPE i, lv_tax_digits TYPE string. LOOP AT it_bp_tax_num INTO ls_tax_num. "Validate tax number type for Malives IF ls_tax_num-bptaxtype = '9MV1' OR ls_tax_num-bptaxtypeforedit = '9MV1'. * Check first character of the tax number IF ls_tax_num-bptaxnumber(1) <> 'C' AND ls_tax_num-bptaxnumber(1) <> 'I'. CLEAR lv_message. SELECT SINGLE FROM YY1_MV_MESSAGE FIELDS description WHERE code = '001' INTO @lv_message. IF sy-subrc = 0. ls_message-msgv1 = lv_message. ls_message-msgty = 'E'. APPEND ls_message TO ct_validationmessage. ENDIF. ELSE. * Check the total length of the tax number lv_len_tax = STRLEN( ls_tax_num-bptaxnumber ). IF lv_len_tax <> 12. CLEAR lv_message. SELECT SINGLE FROM YY1_MV_MESSAGE FIELDS description WHERE code = '002' INTO @lv_message. IF sy-subrc = 0. ls_message-msgv1 = lv_message.. ls_message-msgty = 'E'. APPEND ls_message TO ct_validationmessage. ENDIF. ELSE. * Check that positions 2 - 12 are numerical characters only lv_tax_digits = ls_tax_num-bptaxnumber+1. IF NOT lv_tax_digits CO lv_digits. CLEAR lv_message. SELECT SINGLE FROM YY1_MV_MESSAGE FIELDS description WHERE code = '003' INTO @lv_message. IF sy-subrc = 0. ls_message-msgv1 = lv_message. ls_message-msgty = 'E'. APPEND ls_message TO ct_validationmessage. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDLOOP.Note
When reusing this implementation, update both the Tax Number Category ID and Custom Code List to match your configuration.
In the following simulation, we'll walk through each step in detail and test the validation to ensure it works correctly.