Field MATNR has been transferred inconsistently or is blank
And the material is created using external number range that is ill give the material number in the excel sheet.
Can you explain, AFAIK field MATERIAL of HEADDATA must always been filled (either with your external code or for internal number from the value returned by BAPI_MATERIAL_GETINTNUMBER)
Nevertheless, here RETURN is an internal table, so you cannot rely on a simple check on header line (?) but must execute a LOOP looking for message type 'A' or 'E'. ANd if you trigger a COMMIT when there are some errors, you can get this kind of message (SAP has already cleared some data...)
Also, did you check for OSS notes for your version/SP, there are some notes with text like "only first material gets created successfully and subsequent materials does not get created."
Also check length of your matnr vs length of subfield material, you could replace your statements with a single
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = wa_matmaster-matnr IMPORTING output = bapimathead-m
aterial.
to prevent errors generation.
Regards,
Raymond