Sub topic 12
Material number assignment: internal and external
This chapter explains how a material gets its number, which setting controls that, and what goes wrong when the setting is misread. It assumes you know what a material type is and how a material is created and extended. Reading ABAP is optional.
Why the number matters
The material number (field MATNR) is the key of the general material table MARA. Every other material table, such as MAKT, MARC, MARD and MBEW, points back to it. A material number is also hard to correct. After a material is saved, you cannot rename it. If you used the wrong number, you create a new material and block or flag the old one for deletion.
The number scheme is therefore a design decision. It is made once, in Customizing, and then applies to every user and interface that creates materials.
Internal and external assignment
There are two ways to assign a number:
- Internal assignment: the system takes the next free number from a number range when you save the material. The user does not type a number.
- External assignment: the user, or the calling program, supplies the number. The system checks that it falls inside an allowed interval and that it is not already in use.
The choice is not made per material. It is made per number range interval, and each material type is linked to one number range. A material type such as HAWA (trading goods) can therefore be internal in one system and external in another.
| Aspect | Internal | External |
|---|---|---|
| Who picks the number | System | User or interface |
| Characters allowed | Digits only | Digits, or letters and digits if the interval allows it |
| Gaps between numbers | Possible | Depends on your own scheme |
| Typical use | Newly created materials with no legacy numbering | Migrated materials, numbers taken from another system, meaningful part numbers |
| Risk | Numbers carry no meaning | Duplicates and inconsistent formats if there is no convention |
Gaps with internal assignment are normal. Number ranges can be buffered, and a number that was drawn is not given back if the transaction is cancelled. Never build a control that assumes consecutive numbers.
How the configuration fits together
Three Customizing objects work together:
- Number range intervals for the number range object for materials. Each interval has a from-number, a to-number, and an Ext indicator that marks it as external. Internal intervals must be numeric. An external interval can allow alphanumeric values.
- Number range groups, which collect one or more intervals under a number range key.
- The assignment of material types to a number range, so that creating a material of type
FERTdraws from, or is validated against, a specific interval.
In the IMG, under Logistics - General, Material Master, Basic Settings, you find the activities "Define Number Ranges for Each Material Type" and "Define Number Assignment for Each Material Type". Their names differ slightly between releases, so search the IMG for "number range" if you cannot find them.
Several material types can share one range. This is common for types that behave alike. You can also give a type its own range, for example to keep raw materials in a recognizable block.
Number format and conversion
A numeric external number is stored with leading zeros. The conversion exit MATN1 handles this. The value 4711 is stored as 000000000000004711 when the field is 18 characters long. An alphanumeric number such as ZPUMP-100 is stored as typed, with no padding.
This matters in code. Assigning a literal to a MATNR variable does not apply the conversion exit. A select that compares against the unpadded value then finds nothing. The next report shows the conversion in both directions.
REPORT zdemo_matnr_conv.
DATA: lv_ext TYPE c LENGTH 40 VALUE '4711',
lv_int TYPE matnr,
lv_out TYPE c LENGTH 40.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = lv_ext
IMPORTING
output = lv_int
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE / 'Conversion failed'.
RETURN.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = lv_int
IMPORTING
output = lv_out.
WRITE: / 'Internal format:', lv_int,
/ 'Display format: ', lv_out.
SELECT SINGLE matnr
FROM mara
WHERE matnr = @lv_int
INTO @DATA(lv_found).
IF sy-subrc = 0.
WRITE / 'Material exists.'.
ELSE.
WRITE / 'Material does not exist.'.
ENDIF.The existence check works only because the value went through the input exit first. Fields on screens and in standard APIs apply the exit for you, but your own selects do not.
What changed in S/4HANA
S/4HANA extends the material number from 18 to 40 characters. The longer field is available but must be switched on in Customizing. Plan this early:
- Treat the activation as one-way. Test it in a sandbox first.
- Check every interface, custom table, IDoc segment, and file layout that holds a material number. A 40-character value that is cut to 18 characters in a downstream system can silently match a different material.
- The extended length does not change the internal and external rules. It only widens the field.
Material numbers still live in the same tables. The Fiori app for product master data and the classic transactions use the same number range configuration, so a number scheme set once covers both.
Common errors and how to read them
- "Number is not in the defined interval": the number you entered falls outside every external interval for that material type. Check which range the type uses before changing the number.
- Entering a number for an internally numbered type: the number field is not ready for input, or any value you supply is ignored. In a program, passing a number to an internally numbered type produces an error or is discarded, depending on the API. Check the interval's Ext flag first.
- Letters in an external number that the interval forbids: the interval is numeric only. Letters require an interval that allows alphanumeric values.
- Exhausted internal range: the interval's current number reached its upper bound. Extend the interval or add a new one, and check the current number status before a mass load.
- Different numbering across systems: if development and production have different interval settings, a number that worked in test is rejected in production. Number range intervals are often not transported with the rest of Customizing, so check them separately in each system.
Choosing between the two
Use internal assignment by default. It avoids duplicates, needs no convention, and works cleanly with mass creation. Choose external assignment when:
- You migrate materials and must keep their existing numbers.
- Another system is the master of the number, for example a PLM system.
- Users rely on a meaningful scheme, and you accept the cost of enforcing it with validation or a user exit.
A mixed setup is common. Raw materials might be internal while finished goods take numbers from a PLM system. This works because the setting follows the material type.
When you create materials from code, a program that supplies its own number needs an externally numbered type. A program that wants a system-assigned number needs an internal one. Decide which before you write the interface, because the same program will not work against both.
Exercise
A migration team loads 5,000 legacy materials with numbers like A-1001. Loads for material type ROH fail with a message that the number is not in the defined interval. Name two things to check in Customizing, and explain why a run of numeric-only legacy numbers would behave differently from A-1001.
Show answer
First, check whether the number range linked to ROH has an interval marked as external. If the interval is internal, it rejects any number you supply. Second, check whether that external interval allows alphanumeric values and whether its from and to values cover A-1001. A numeric-only legacy number such as 4711 can load into a numeric external interval, where the system pads it with leading zeros through the MATN1 conversion exit. A value containing a letter or hyphen cannot, so it needs an alphanumeric external interval.
Exercise
A report selects from MARA with WHERE matnr = '4711' and finds nothing, although the material exists and shows as 4711 in the transaction. What is the likely cause, and how do you fix it?
Show answer
The number is stored with leading zeros (000000000000004711 at 18 characters), and the literal bypasses the conversion exit. Convert the value with CONVERSION_EXIT_MATN1_INPUT before you use it in the select, or pass it through a field that applies the exit.