5

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
flosk8
  • 465
  • 1
  • 6
  • 17
  • SAP NCo 3.0 doesnt have any built in feature sets for IDOC processing like the Java version had or some of the api's like ERP connect have built. One way you can do this without the aid of the SAP NCo is through HTTP, you can see it in this article, http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/01/14/post-idoc-to-sap-erp-over-http-from-any-application you will need your basis to help you with partner profiles and etc but you can post true XML to the web service and generate and IDOC. – Bearcat9425 Feb 02 '16 at 22:26

1 Answers1

6

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.

Dirk Trilsbeek
  • 5,873
  • 2
  • 25
  • 23