Sub topic 1
What the material master is and why it matters
Prerequisites
This chapter assumes you have the following:
- Basic familiarity with SAP GUI navigation and transaction codes.
- A general understanding of procurement, production, sales, and inventory processes.
- A basic understanding of SAP organizational units such as company code and plant.
- Optionally, basic ABAP reading skills for the code examples.
You do not need to have created a material before. This chapter gives you the working model that the rest of the tutorial builds on.
What the material master is
The material master is the central record that describes every material a company buys, makes, stores, or sells. In SAP S/4HANA, "material" is a broad term. It covers raw materials, semifinished goods, finished products, trading goods, spare parts, packaging, and also things you never physically stock, such as a service you purchase.
Each material has one record. Many departments read and write that record, but each department cares about different fields:
- Purchasing needs the order unit and the purchasing group.
- Planning needs the lot size and the planned delivery time.
- Sales needs the delivering plant and the item category group.
- Accounting needs the valuation class and the price control.
- The warehouse needs the storage conditions.
The material master holds all of these in one place. This is the main design idea. Instead of every department keeping its own list of products, they all share a single record that is split into departmental slices called views. Later chapters cover the views in detail.
Why it matters
Almost every logistics and finance transaction refers to a material. When a user enters a material number in a purchase order, a sales order, a production order, or a goods movement, the system reads the material master and copies defaults from it.
The table shows which processes depend on the material master and what they read from it.
| Process | Typical data read from the material master |
|---|---|
| Procurement | Purchasing group, order unit, planned delivery time, tolerances |
| Material requirements planning (MRP) | MRP type, lot-sizing procedure, safety stock, procurement type |
| Production | Procurement type, production storage location, scheduling data |
| Sales and distribution | Delivering plant, item category group, availability check, tax data |
| Inventory management | Base unit of measure, storage location, batch management flag |
| Financial accounting and costing | Valuation class, price control, standard or moving average price |
Two consequences follow from this.
- Errors spread. A wrong valuation class or a wrong base unit of measure affects every document that uses the material afterwards. Fixing the master record does not fix documents that already exist.
- Ownership is shared. Several departments maintain different parts of the same record, so you need clear rules about who maintains which view.
How the data is organized
The material master does not store everything in one flat row. Data is held at different organizational levels, and each level answers a different question.
- Client level: data that is true for the material everywhere in the company, such as its number, base unit of measure, and weight.
- Plant level: data that depends on the location, such as MRP settings and purchasing data.
- Storage location level: data about stock in a specific storage area within a plant.
- Sales organization level: pricing and delivery data for one selling unit.
- Valuation area level: the price and the valuation class. The valuation area is usually the plant.
A material is created once at client level. It is then extended to the plants, storage locations, and sales areas where it is used. The next chapter covers these levels in detail. For now, remember that a material can exist in plant 1010 and not exist in plant 1020, even though it is the same material number.
The following diagram shows how a single material reaches the levels below it.
Material type and industry sector
Two header-level attributes classify every material when you create it.
The industry sector is a short code, such as M for mechanical engineering. It controls which field selection settings apply to the material.
The material type, such as ROH for raw materials, HALB for semifinished products, FERT for finished products, or HAWA for trading goods, is more important. It decides which views the material can have, whether the system assigns the number internally or you enter it yourself, and whether the system tracks quantity and value. You cannot change these facts casually after the material has been used, so choosing the type is one of the first real decisions when you create a material. A later chapter covers material types in full.
Seeing the data in the system
You can read the material master directly from the database tables. The main tables are MARA (general data), MAKT (descriptions), and MARC (plant data). The query below joins them to list materials that have been extended to plant 1010, together with their material type and MRP type.
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.Notice how the structure of the data shows up in the query:
maraholds one row per material, so it carries client-level data such as the material typemtart.maktholds one row per material and language, which is why the join filters onspras = @sy-langu. Without that condition, you would get one row per language.marcholds one row per material and plant, which is why the plant filter is in theWHEREclause.
If you leave out the language condition, the result looks correct in a single-language test system and breaks in a multilingual one. This is a common error.
Maintaining the material master
Users normally maintain materials with the classic transactions MM01 (create), MM02 (change), and MM03 (display), or with the Fiori apps that replace them in S/4HANA. A program can do the same with the function module BAPI_MATERIAL_SAVEDATA. The example below creates a trading good with a base unit of measure, a description, and one plant-level purchasing field.
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.Three points explain how this code works.
- Every value structure has a partner structure that ends in
X. A field is only changed if its flag in the partner structure is set. If you fillls_client-base_uombut forgetls_clientx-base_uom, the BAPI silently ignores your value. - The flags in the header, such as
basic_viewandpurchase_view, tell the BAPI which views to create. - The BAPI does not commit by itself. The program checks the return type and then commits or rolls back. Type
E,A, orXmeans failure.
Common errors
- Treating the material as one flat record. Most "field not found" and "no data for plant" problems come from looking at the wrong organizational level.
- Forgetting that extending a material to a new plant creates new plant-level data. It does not copy the settings of another plant automatically, unless you use a reference.
- Setting a value in a BAPI structure without setting its flag in the
Xstructure. - Joining MAKT without a language condition.
- Choosing the material type casually. It controls views, number assignment, and valuation.
Exercise
A colleague runs a join of MARA and MAKT and gets three rows for every material instead of one. What is the most likely cause, and how do you fix it?
Show answer
MAKT stores one description row per material and language, and the system has descriptions in three languages. The join has no language condition. Add AND makt~spras = @sy-langu to the join so that only the description in the logon language is returned.
Exercise
You call BAPIMATERIALSAVEDATA with a purchasing group in the plant data structure, and the BAPI returns no error. The purchasing group is still empty in the material. What did you probably miss?
Show answer
You did not set the matching field in the plant data flag structure (the one ending in X). The BAPI only applies fields whose flag is set, so it ignored the value without raising an error.