In our current project we are using SAPNCO3 with RFC calls. The requirement is to create material with the function "BAPI_MATERIAL_SAVEDATA" and some custom fields (via EXTENSIONIN). The problem now is how to extend the needed structures "BAPI_TE_MARA/X" so that they can carry the custom fields? I cannot found any function for this.
Please have a look at the Code snippet at the bottom.
Thank you!
Tobias
var BAPI_TE_MARA = repo.GetStructureMetadata("BAPI_TE_MARA");
IRfcStructure structure = BAPI_TE_MARA.CreateStructure();
structure.SetValue("MATERIAL", material.Number);
//structure.SetValue("ZMM_JOB_REFERENCE", "f");

BAPI_MATERIAL_SAVEDATAhas two table parametersEXTENSIONINandEXTENSIONINXto which you pass lines with the values of your custom fields.These table parameters have to indicate what extension structures you want to use and their values.
As these custom fields may extend different tables of the material, you have to indicate different extension structures depending on which table these fields belong to:
MARA, the extension structures areBAPI_TE_MARAandBAPI_TE_MARAX.MARC, the extension structures areBAPI_TE_MARCandBAPI_TE_MARCX.These extension structures should preferably have character-like fields to simplify the programming (and to support IDocs, as rule-of-thumb).
For instance, if you have the custom fields
ZZCNAME(7 characters) andZZCTEXT(50 characters) in the tableMARA, they will also be defined inBAPI_TE_MARAand have the same names and types. InBAPI_TE_MARAX, you also have two fields with the same names, but always of length 1 character and their values must be 'X' to indicate that a value is passed inBAPI_TE_MARA(useful in case a blank value is passed that must not be ignored). The X extension structures are essential especially in "change" BAPIs.If you want to pass values to the BAPI, you must first initialize these structures:
BAPI_TE_MARA:BAPI_TE_MARAX:Then, you must initialize the two parameters of the BAPI:
EXTENSIONIN(notice that there are 3 spaces inNAME TEXTbecause the technical length ofZZCNAMEis 7 characters and its value "NAME" occupies only 4 characters):EXTENSIONINX:Consequently, your program must:
BAPI_TE_MARAfields together and copy the resulting string into fieldsVALUEPART1toVALUEPART4ofEXTENSIONINas if it was a 960 characters fieldBAPI_TE_MARAXfields together and copy the resulting string into fieldsVALUEPART1toVALUEPART4ofEXTENSIONINXI guess you may use
ToString()to get one concatenated string of characters of all fields of a structure, and to set the value ofVALUEPART1,VALUEPART2, etc., you'll probably need to initialize them individually from the string of characters withSubstring.