cancel
Showing results for 
Search instead for 
Did you mean: 

Problem to execute BAPI_MATERIAL_SAVEDATA using JCO

Former Member
0 Kudos

Hi,

I'm trying to create a material by calling BAPI_MATERIAL_SAVEDATA using JCO. Following various hints in other Forum-Threads i came to the following 'solution':

<code>

//Create the needed Functions
JCO.Function function_getmatnumber = createFunction(mRepository, "BAPI_STDMATERIAL_GETINTNUMBER");
JCO.Function function_create = createFunction(mRepository, "BAPI_MATERIAL_SAVEDATA");

// set Materialtype to 'FERT' for '...GETINTNUMBER', execute and retrieve new Number
function_getmatnumber.getImportParameterList().setValue("FERT", "MATERIAL_TYPE");

mConnection.execute(function_getmatnumber);
JCO.Table newMatnumbers = function_getmatnumber.getTableParameterList().getTable("MATERIAL_NUMBER");
newMatnumbers.setRow(0); //Only one number needed
String newMatnumber = newMatnumbers.getString("MATERIAL");

//retrieve HEADDATA-Structure
JCO.Structure headdata = function_create.getImportParameterList().getStructure("HEADDATA");

<snip retrieval of other needed Structures/Tables like CLIENTDATA and so on... >

//Set HEADDATA-MATERIAL to the value retrieved from BAPI_STDMATERIAL_GETINTNUMBER
headdata.setValue(newMatnumber, "MATERIAL");

<snip populating needed Fields in the different Structures/Tables with reasonable Values...>

//execute the Function
mConnection.execute(function_create);

</code>

Examining the RETURN-Structure, i now get the Message-Type 'E' (Error) and the

Message "Field MATNR has been transferred inconsistently or is blank"

I have no idea why, for i just retrieved the materialnumber immediately before and

filled the according field in HEADDATA with it.

Maybe there is some other mandatory field 'MATNR' hidden somwhere in the other structures, which i simply do not find...

Can anyone help me or show me the error in my thoughts coded above?

Thank you in advance,

Magnus

Message was edited by:

Magnus Gertkemper

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Just in case, have you checked if the function BAPI_STDMATERIAL_GETINTNUMBER

is returning a real internally assigned material number if you use FERT? Test this in se37 if you haven't. Depending on the material type configuration, sometimes they don't have an internal number range.

Next, I would input every one of the values that you are passing in the Java code and manually test it first using SE37 before proceeding. You could save the test data in se37 so you don't have to keep repopulating the inputs as you play with the parameters.

Former Member
0 Kudos

Also thank you for your answer.

Yes, BAPI_STDMATERIAL_GETINTNUMBER returns a number matching the according range.

And 2nd: Thank you for the hint, but i don't think i will use it, for i have written a simple webapp which provides jco with some default-values, so i do not have to type them already.

regards,

Magnus

Former Member
0 Kudos

Hi Magnus,

If the material number is internally assigned, you may not have to populate the matnr field - have you tried to run it without adding the material number in?

Gareth.

luciano_leitedasilva
Contributor
0 Kudos

Magnus,

Have a look at the BAPI_MATERIAL_SAVEDATA import parameters and tables by transaction SE37. Probably is missing some required field parameter.

Regards,

Luciano

Former Member
0 Kudos

Actually, i had some error-messages concerning missing parameters before. I eliminated them by subsequently adding the missing parameters one-by-one. So i am quite sure i have a sufficient set of Parameters. But maybe i am wrong: Is there an easy way (in SE37?) to find all mandatory parameters needed for a bapi-call without searching through every single structure?

Magnus

Message was edited by:

Magnus Gertkemper

luciano_leitedasilva
Contributor
0 Kudos

Magnus,

Yes, there is. So, go at SE37 transaction and display the BAPI_MATERIAL_SAVEDATA function. Go to "import" and see all import parameters that isn't checked as optional. All these parameters are required.

Regards,

Luciano

Former Member
0 Kudos

Thanks for the answer.

That is what i did. I see only one required parameter named Headdata, so at first i only provided data for the fields of that structure. But after executing i got a message that some fields in one of the optional parameters/structures also need to be filled. Therefore the information on the se37-View is not sufficient and imho misleading. I am looking for an in-depth-search for mandatory fields also inside the Parameter-Structures.

Magnus