Validate externally asigned numbers for master data.

When creating master data it is a common practice to externally number data coming from legacy systems before loading into SAP. To create master data with externally assigned numbers in SAP requires a number range with the capacity to be externally assigned.
The numbering ranges for Master Data are stored in the NRIV
table. Additionally, a flag in the same table denotes whether or not the number may be externally assigned during creation instead of automatically assigned from within SAP.
The first step is to pad numeric values with the proper number of zeros. A simple way to do this is by creating a character variable the desired length and then using the shift
and overlay
commands to pad the number with leading zeros. In this case we will use a recyclable User Routine that calls the CONVERSION_EXIT_MATN1_INPUT
function.
PERFORM ur_F_CONV_EXIT_MATN1_INPUT CHANGING IMM00-MATNR. FORM ur_F_CONV_EXIT_MATN1_INPUT CHANGING CV_MATNR TYPE MARA-MATNR. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING INPUT = CV_MATNR IMPORTING OUTPUT = CV_MATNR EXCEPTIONS LENGTH_ERROR = 0 OTHERS = 0. ENDFORM.
The second step is to loop through the NRIV
table to compare the externally assigned number against the number ranges in the table. When the number range is found the flag denoting the ability to externally assign (EXTERNID
) is checked to see if it is populated with an 'X'.
In this example the 'MATERIALNR' value in the filter indicates that the number range being searched for is for Material Master data. Replace that with 'KREDITOR' to find Vendor numbering ranges or with 'DEBITOR' to find Customer numbering ranges.
if BMM00-TCODE eq 'MM01'. "Creating new material--must check. select * from NRIV into lNRIV where OBJECT eq 'MATERIALNR' and FROMNUMBER le IMM00-MATNR and TONUMBER ge IMM00-MATNR. if lNRIV-EXTERNIND ne 'X'. "Cannot be assigned externally. write: / IMM00-MATNR, 'Material number cannot be assigned externally.' color isSkipped = 'X'. endif. endselect. if sy-subrc ne 0. "No numbering range found for this number. write: / IMM00-MATNR, 'Material number not in any numbering range.' color 6. isSkipped = 'X'. endif. endif.
The isSkipped
variable is set to 'X' if the material is to be skipped. By calling the SKIP_TRANSACTION
at the end of the program the other routines for validating other fields are still executed so that the meaningful report includes all of the issues encountered and not just the first one.