Material Number Ranges and Formatting
May 30th, 2010 | By Ole | Category: Customizing, SAP ABAP, SAP Tables & Views, SAP Transaction CodesMaterial Numbers in R/3
The material number in R/3 is technically defined as an eighteen byte, character field.
The logic that formats material numbers is contained in a conversion exit and is controlled by configuration tables, number range objects and standard R/3 customer
functions. This document first explains how material number ranges are defined and then details a few methods for enhancing the standard functionality. The examples in this document are from a 4.6c system.
Relevant OSS Notes
The following OSS notes may be useful in understanding this process:
72286 Lexicographical / non-lexicographical material number
78093 Display of alternative material identifiers
Material Number Range Object
R/3 uses Number Range Objects to assign numbers to almost everything within the system. For materials, the number range object used is MATERIALNR. Number range objects can be viewed and maintained using transaction SNRO.
The configuration for the number range object specifies a transaction (MMNR) for maintaining the intervals. The group section specifies that intervals will be assigned using groups. In this case, the group is the material type (MTART). Table T134 is the configuration table that defines material types. NUMKI and NUMKE are the fields in table T134 that contain the internal and external number range intervals.
Assigning Intervals to Material Types
Transaction MMNR
Transaction MMNR is used to create and assign intervals to the material types.
Each group is displayed with the material types assigned. In this case, a group corresponds to an interval.
The interval for material type FERT is displayed when the maintain button is pressed from the previous screen.
Notice that the interval range contains leading zeros. This explains why zero filled material numbers exist even though the MATNR domain is defined as a character type.
Configuration Tables
When transaction MMNR is processed, the configuration tables in the following sections are referenced/updated.
Table TNRGT Number Range Groups
Table T134 Material Type Master
Table T134 is the configuration table that contains the material type parameters. The fields listed below are the subset related to material number ranges.
Table NRIV Number Range Intervals
Table NRIV contains the actual number range intervals
Controlling the Format
Transaction OMSL Material Number Format
Transaction OMSL is used to access table TMCNV, which is the configuration table that contains control settings for formatting the material number.
Table TMCNV
Below is the SE16 view of the TMCNV table.
Material Number Domain
Conversion exits are assigned at the domain level within the data dictionary. The following screen displays the material number domain (MATNR). The standard R/3 conversion routine is specified (MATN1)
Function Group OMCV
The material number conversion exit function modules are contained in function group OMCV. For each conversion exit defined, there are two function modules. One function is for input and, the other is for output. SAP has a standard naming convention for these functions that must be followed. It consists of a prefix, the conversion routine name and a suffix as follows:
‘CONVERION_EXIT_’ + Conversion routine name + ‘_INPUT’
‘CONVERION_EXIT_’ + Conversion routine name + ‘_OUTPUT’
Function CONVERSION_EXIT_MATN1_INPUT
Converts the internal material number to the output format. The logic flow is as follows:
- Calls customer function 001 if it exists.
- Reads table TMCNV and formats the number based on the settings in the table.
- Calls customer function 002 if it exists.
Function CONVERSION_EXIT_MATN1_OUTPUT
Converts the external material number to the internal format. The logic flow is as follows:
- Calls customer function 901 if it exists.
- Reads table TMCNV and formats the number based on the settings in the table.
- Calls customer function 902 if it exists.
Custom Output Format Example 1
The following example demonstrates how to format the material number output using an edit mask.
Business Requirement
The customer wants to display the material using the format xxxx-xxx-xx.
Solution
To solve this problem, standard configuration will be used to add an edit mask to the material number.
Step 1 Define the Edit Mask via TMCNV Configuration
Using transaction OMSL, the edit mask is specified in the material number template field.
Once the configuration is complete, table TMCNV contains the edit mask. Several other fields related to the edit mask are also present. These fields are used by the standard logic in the conversion exit to apply the mask to the number.
Step 2 Test the Configuration Change
Using transaction SE16, two MARA records are displayed. The conversion exit does not execute until the record detail is displayed. The material number internal format has not changed. It is still eighteen bytes, zero filled.
Once the record detail is displayed, the conversion exit logic applies the masking logic based on the TMCNV record.
Custom Output Format Example 2
The following example demonstrates how to implement a custom material number output routine.
Business Requirement
The customer uses material numbers that are either six or seven bytes long. They always want seven bytes displayed, even if the actual number is six bytes long. For numbers that are six bytes long, they want a leading zero to display.
Solution
To solve this problem, we will add logic to zero fill six byte numbers (to seven bytes) when outputting the material number. This logic will be added to customer function 902 in the output conversion exit of the material number (CONVERSION_EXIT_MATN1_OUTPUT).
It is assumed that the reader understands the CMOD/SMOD enhancement concept.
Step 1 Identify the Standard Customer Function
The output conversion exit for material numbers contains two customer function calls.
Function 901 is called at the beginning of the logic and function 902 is called at the end, just before the exit. For this project, we will use function 902.
To navigate into the customer function, double click on the function name ‘902’.
Step 2 Create the Customer Function INCLUDE
The customer function does not contain any code, only an INCLUDE. The actual code will be added to the INCLUDE.
![]()
Double click on the include name ZXMG0U11. The system will respond with ‘Include ZXMG0U11 does not exist, Do you wish to create it’. You need to go thru the normal steps to create the INCLUDE, assign a transport request, etc.
The system will create an empty include to which we will add our logic.
Step 3 Code the Logic
The logic is added into the INCLUDE. This logic is quite simple. We check the length of the material number. If it is six bytes long, a single leading zero is added.
Step 4 Find the Standard Enhancement (SMOD)
For standard customer functions, there will be an existing enhancement. It can be found using the search tool in transaction SMOD.
The standard enhancement for material number customer functions is MGA00003.
The standard enhancement contains all four of the customer functions contained in the conversion exits. It does not matter that we aren’t using the others. Alternatively, we could create a custom enhancement that contains only the customer function we are using.
Step 5 Create a Project (CMOD)
Using transaction CMOD, create a customer specific project. Customer specific projects must begin with the letter ‘Z
Step 6 Assign the Enhancement to the Project
One or more enhancements (SMOD) can be assigned to a project. In this case, we will assign the standard material number enhancement.
Step 7 Activate the Project
On the main screen of transaction CMOD are the activate/deactivate buttons. The project must be activated from this screen.
Step 8 Test the New Logic
Using transaction SE16, two MARA records are displayed. The conversion exit does not execute until the record detail is displayed. The material number internal format has not changed. It is still eighteen bytes, zero filled.
Below is the detail view of the record containing the six byte material number. The logic added one leading zero to the number for output.
Below is the detail view of the record containing the seven byte material number. The logic was not applied to this number.