Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and send Idocs to SAP using SAP .Net Connector 3

I want to create and send idocs to SAP using the SAP. Net Connector 3.x.

And I have a configured RFC Destination in my application:

 _rfcDestination = RfcDestinationManager.GetDestination(_destinationName);

But I can not find any examples on how to create and send idocs.

Can anybody give some sample code on how to create and send an idoc?

like image 693
flosk8 Avatar asked Jan 20 '16 09:01

flosk8


People also ask

How is IDoc created in SAP?

In case of outbound flow, IDoc is triggered in SAP through document message control which is then sent to EDI subsystem. EDI converts the data from IDoc into XML or equivalent format and then sends the data to partner system through Internet. For inbound flow, EDI converts partner data and IDoc is created in SAP.

What is SAP .NET Connector?

SAP Connector for Microsoft . NET 3.0 (NCo 3.0) allows developers to use BAPIs and remote-enabled function modules in any . NET application (inside-out). You can also access . NET components from any ABAP application by implementing an RFC server in .

How are IDocs sent?

Send an IDOC from SAPStart the SAP GUI. Create a logical system using BD54 transaction. Create an RFC destination in TCP/IP connections using SM59 transaction. Create a port using WE21 transaction and attach it to the RFC destination created in the last step.


1 Answers

One way to submit idocs to the SAP system using NCo is function module IDOC_INBOUND_ASYNCHRONOUS. The function module has several table parameters containing your idoc data. Table IDOC_CONTROL_REC_40 contains the control record, IDOC_DATA_REC_40 contains the idoc data segments.

IDOC_DATA_REC_40 contains a field called SDATA. That field contains the idoc segment data as a single concatenated string with fixed field lengths.

var fnc = destination.Repository.CreateFunction("IDOC_INBOUND_ASYNCHRONOUS");
var controlTable = fnc.GetTable("IDOC_CONTROL_REC_40");
var dataTable = fnc.GetTable("IDOC_DATA_REC_40");

// control segment
controlTable.Append();
controlTable.CurrentRow.SetValue("TABNAM", "EDI_DC40  ");
...


// here you add the data segments
dataTable.Append();
dataTable.CurrentRow.SetValue(...);

fnc.Invoke(destination);

the construction of the idoc data for IDOC_DATA_REC_40-SDATA has to be done manually in your code - you need to know the field lengths, including digits for numerical fields. There may be a way to get that information from the SAP system and use it in your code, but i've never tried that.

like image 153
Dirk Trilsbeek Avatar answered Sep 29 '22 11:09

Dirk Trilsbeek