Sub topic 13
Creating a Material and Extending It to Other Levels
This chapter assumes you know basic SAP GUI navigation, the organizational units (client, company code, plant, storage location, sales organization), and the idea of material types and views from earlier chapters. It covers how a material is created, how it is extended to more organizational levels, and the errors you will meet most often.
Create versus extend
Creating a material and extending it are different operations.
- Creating writes the material number and the general (client-level) data, such as the base unit of measure and the description. It also writes the data for the first organizational levels you choose, for example one plant and one storage location.
- Extending adds more organizational levels to a material that already exists. The client-level data is reused. Only the level-specific data is new.
The material number exists once per client. A material is never copied to a second plant. It is extended to it, and the extension creates a new plant-level record that points to the same material.
| Data | Stored at | Created when |
|---|---|---|
| Base unit, material group, description | Client | The material is first created |
| Purchasing, MRP, plant data | Plant | The material is created or extended to that plant |
| Stock and storage bin data | Storage location | The material is created or extended to that location |
| Sales data, delivering plant | Sales organization and distribution channel | The material is created or extended to that sales area |
| Valuation, price control | Valuation area (usually the plant) | The material is created or extended to that valuation area |
Creating a material with MM01
The classic transaction is MM01 (Create Material). The Fiori app Manage Material (or the older Create Material app) offers the same function. The flow in MM01 is:
- Enter the material number, or leave it empty if the material type uses internal number assignment.
- Choose the industry sector and the material type. Both are fixed after saving.
- Select the views you want to maintain. The material type limits which views are offered.
- Enter the organizational levels: plant, storage location, sales organization, distribution channel, and valuation type if used.
- Fill in the fields on each view and save.
A reference material can pre-fill the screens. You enter an existing material and its organizational levels in the copy-from fields. The system copies the values, and you then change what differs. This is the fastest way to create many similar materials.
Extending a material
To extend, you use MM01 again with an existing number. You do not use MM02 for this. MM02 (Change Material) edits data that already exists. If you open MM02 and select an organizational level that the material does not yet have, the system reports that the data does not exist and does not offer to create it.
In MM01, after you enter the existing material number, the system detects that it exists. You select the views and enter the new organizational levels. Fields are often proposed from the first plant if you name a reference plant. You then save, and only the new level records are written.
Typical extension cases:
- Adding a second plant, which needs plant-level views (purchasing, MRP, plant data) and a valuation record.
- Adding a storage location in an existing plant, which writes storage location data.
- Adding a sales area, which writes sales organization data for that distribution channel.
Mass extension is done with the Fiori mass maintenance apps, LSMW-style migration tools in older systems, or the Migration Cockpit for initial loads. For repeated extensions in code, use a BAPI (see the end of this chapter).
What is checked on save
The system runs several kinds of checks when you save. Knowing them helps you read error messages.
- Required entries. Fields marked required by the field selection must be filled. Which fields are required depends on material type, plant, and transaction (see the field control chapter).
- Dependent organizational data. A plant needs a valuation area before plant-level views can be saved. Without it, the accounting view cannot be created. In S/4HANA the valuation area is normally the plant.
- Customizing links. The plant must be assigned to a company code. A sales organization must be assigned to a company code and linked to the plant through a distribution channel and division assignment for sales processing.
- Units and groups. Units of measure, material groups, and MRP controllers must exist in their customizing tables.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The material type is not offered | The type is not allowed for the chosen industry sector | Check the sector and the type customizing |
| Views are missing from the selection | The material type does not allow that view (the user department is not set up for the type) | Check the "Material type" customizing for views and quantity/value updating |
| "Plant is not defined for valuation" or similar | No valuation area for the plant | Check the valuation level and plant assignment in customizing |
| Number already exists | An external number was entered for a material that exists | Use extension instead of create |
| Material is in the system but not found in the plant | The extension to that plant has not been done | Extend with MM01 |
| Stock posting is rejected | Storage location data is missing | Extend the material to that storage location |
Order of extension and dependencies
Some levels depend on others. The client-level data must exist first. The plant-level record (MARC) must exist before a storage location record (MARD), and the valuation record (MBEW) must exist before any goods movement that updates value. The sales organization data requires the plant to be entered as the delivering plant for typical sales processing.
You can create several levels in one run. MM01 writes them together in one logical unit of work, so either all of them are saved or none.
Fiori and S/4HANA notes
In S/4HANA the same data model is used, with some differences you will notice when creating a material:
- The Fiori app and MM01 both work. Older transactions such as MM01 are still available and are the ones most projects use for training and support.
- The business partner is used for suppliers and customers, but the material master itself is not changed by this.
- The material number can be up to 40 characters if the extended length is activated. Plan the length before you load data, because it affects interfaces and custom code that assume 18 characters.
Creating a material from code
The BAPI BAPI_MATERIAL_SAVEDATA can create a material or extend it, because it writes whichever levels you pass. The example below creates a trading good with a base unit, a description, and one plant-level purchasing field. Each value structure has a matching structure ending in X that holds the change flags. A field is saved only when its flag is set. The program commits only when the BAPI returns no error.
DATA: ls_head TYPE bapimathead,
ls_client TYPE bapi_mara,
ls_clientx TYPE bapi_marax,
ls_plant TYPE bapi_marc,
ls_plantx TYPE bapi_marcx,
lt_desc TYPE STANDARD TABLE OF bapi_makt,
ls_return TYPE bapiret2.
ls_head-material = 'ZDEMO_MAT_001'.
ls_head-ind_sector = 'M'.
ls_head-matl_type = 'HAWA'.
ls_head-basic_view = abap_true.
ls_head-purchase_view = abap_true.
ls_client-base_uom = 'EA'.
ls_clientx-base_uom = abap_true.
ls_plant-plant = '1010'.
ls_plant-pur_group = '001'.
ls_plantx-plant = '1010'.
ls_plantx-pur_group = abap_true.
APPEND VALUE #( langu = 'E' matl_desc = 'Demo trading good' ) TO lt_desc.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = ls_head
clientdata = ls_client
clientdatax = ls_clientx
plantdata = ls_plant
plantdatax = ls_plantx
IMPORTING
return = ls_return
TABLES
materialdescription = lt_desc.
IF ls_return-type CA 'EAX'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true.
ENDIF.Points to notice:
- The header flags (
basic_view,purchase_view) tell the BAPI which views you are maintaining. - Running the same call again for an existing material changes it. To extend it to another plant, pass a different
plantinplantdataandplantdatax. - The BAPI does not commit by itself. The commit or rollback is your responsibility.
Verifying the result
After creating or extending, confirm what exists at each level. You can check with MM03 (Display Material), or read the tables with ABAP SQL:
SELECT mara~matnr,
makt~maktx,
mara~mtart,
marc~werks,
marc~dismm
FROM mara
INNER JOIN makt ON makt~matnr = mara~matnr
AND makt~spras = @sy-langu
INNER JOIN marc ON marc~matnr = mara~matnr
WHERE marc~werks = '1010'
INTO TABLE @DATA(lt_materials)
UP TO 100 ROWS.Each plant the material is extended to gives one row in MARC, so a material extended to three plants appears three times if you do not filter on the plant.
Exercise
A material exists in plant 1010. A buyer needs it in plant 2020. Which transaction do you use, and why is MM02 not the right choice?
Show answer
Use MM01 with the existing material number and enter plant 2020 as the new organizational level. This extends the material and writes new plant-level records. MM02 only changes data that already exists, so it cannot create the records for plant 2020.
Exercise
A BAPIMATERIALSAVEDATA call returns no error, but the plant purchasing group is empty afterward. What is the most likely cause?
Show answer
The matching flag in the structure ending in X (for example plantdatax-purgroup) was not set to abaptrue, so the BAPI ignored the value.