This little article shows the minimum requirement to create and read material master data in SAP. A material object consists of multiple layers or so called views. Each view may exist multiple times (e.g. one plant view for plant 1000 and one for plant 2000 both for the same material). To keep the samples as simple and short as possible this code only shows how to handle the basic views but the others will work in the same way. The attributes of the basic view are the Material Number itself, the so called Old Material Number (which can come from a legacy system), the Industry Sector and the Material Type (in our case HAWA which stands for Trading Goods, if you know German: HAWA is the abbreviation for Handelsware). And last but not least the basic measure unit, which is mandatory.
We use the BAPI BAPI_MATERIAL_SAVEDATA which can be used for both creating a new material or changing / extending an existing Material. As you see in the code, beside the regular structure for submitting data (CLIENTDATA) there an additional so called checkbox structure called CLIENTDATAX. Any data that is submitted in CLIENTDATA must be confirmed by an X value in the CLIENTDATAX structure.
Here’s the code snippet for reading the material attributes that were used in the first sample: