Search code examples
c#.netsap-dotnet-connector

Create a material .NET Connector SAP


Please tell me somebody out there has done this. I am trying to interface with SAP via .NET Connector 3.0. I can read data fine with the remote function calls, but I cannot figure out how to write anything, creating or editing a material for example. Through some research I have determined that BAPI_MATERIAL_SAVEDATA is the RFC I need to be using, but cannot for the life of me figure out how. Here's what I'm trying:

function = destination.Repository.CreateFunction("BAPI_MATERIAL_SAVEDATA");
IRfcStructure structure = function.GetStructure("HEADDATA");
structure.SetValue("material", "000000000000000888");
structure.SetValue("ind_sector", "U");
structure.SetValue("matl_type", "ERSA");
structure.SetValue("basic_view", "X");

structure = function.GetStructure("CLIENTDATA");
structure.SetValue("matl_group", "01");
structure.SetValue("base_uom", "EA");

structure = function.GetStructure("CLIENTDATAX");
structure.SetValue("matl_group", "X");
structure.SetValue("base_uom", "X");
function.Invoke(destination);

I cobbled this together based on a various VB and ABAP examples. The problem is it does nothing. When function.Invoke() is called, it doesn't create a material, it doesn't throw an exception, it just does nothing. Clearly I am not doing something right be I haven't the slightest idea what. Somebody please help!


Solution

  • I have no access to a SAP system at the moment, but as far as I know, you have to call the bapi within a transactional scope, e.g. call BAPI_TRANSACTION_COMMIT after creating the material. But maybe the .net connector has another approach for that...

    Hope this helps.