CreateIdoc creates an IDoc with all segments located in the segment collections. This is useful for sending simple IDocs.
CreateEmptyIdoc and CreateSegment create only the needed segments.
Send an IDoc
Follow the steps below to send IDocs:
Connect to the SAP system using R3Connection.
Use CreateIdoc or CreateEmptyIdoc to instance a valid IDoc object. Provide an object type for the IDocs, e.g., "SYSTAT01", "MATMAS01", "ORDERS01", etc.
Provide receiver and sender information.
Fill in the fields in the IDoc segments.
Send the IDoc using Send.
Run the program and check the result.
Tip
Use SAP transaction WE60 to look up the segment documentation of IDocs.
Note
Make sure to configure your SAP system to receive IDocs.
usingSystem;usingERPConnect;usingERPConnect.Utils;// Set your ERPConnect licenseLIC.SetLic("xxxx");usingvarconnection=newR3Connection(host:"server.acme.org",systemNumber:00,userName:"user",password:"passwd",language:"EN",client:"001"){Protocol=ClientProtocol.NWRFC,};connection.Open();// Inquire the IDoc number of the IDoc to be manipulated and read the input. Console.WriteLine("Which IDoc number would you like to manipulate?");stringIdocNo=Console.ReadLine();Idoci=connection.CreateIdoc("SYSTAT01","");// Fill Message Type i.MESTYP="STATUS";// Fill Information about IDoc Reciever i.RCVPRN="PT4_800";// Partner number i.RCVPRT="LS";// Partner type // Fill information about IDoc sender i.SNDPOR="ERPCONNECT";// Partner port i.SNDPRN="ERPCONNECT";// Partner number i.SNDPRT="LS";// Partner type// Fill the right fields in the segments i.Segments["E1STATS",0].Fields["LOGDAT"].FieldValue="20210901";i.Segments["E1STATS",0].Fields["LOGTIM"].FieldValue="152301";i.Segments["E1STATS",0].Fields["STATUS"].FieldValue="12";i.Segments["E1STATS",0].Fields["DOCNUM"].FieldValue=IdocNo;i.Send();Console.WriteLine("IDoc sent");Console.ReadLine();
Output:
The status code of the manipulated IDoc increases from 3 (Data passed...) to 12 (Dispatch OK).
usingSystem;usingERPConnect;// Set your ERPConnect licenseLIC.SetLic("xxxx");usingvarconnection=newR3Connection(host:"server.acme.org",systemNumber:00,userName:"user",password:"passwd",language:"EN",client:"001"){Protocol=ClientProtocol.NWRFC,};connection.Open(false);ERPConnect.Idocs.Idocid=con.CreateEmptyIdoc("MATMAS01","");// Fill header dataid.SNDPRN="ERPCONNECT";id.SNDPOR="ERPCONNECT";id.SNDPRT="LS";id.RCVPRN="ECW_00_800";id.RCVPRT="LS";id.MESTYP="MATMAS";// Fill basic dataERPConnect.Idocs.IdocSegmente1maram=id.CreateSegment("E1MARAM");e1maram.Fields["MATNR"].FieldValue="DEV003";// Material Numbere1maram.Fields["MTART"].FieldValue="FERT";// Material Typee1maram.Fields["MATKL"].FieldValue="001";// Material Groupe1maram.Fields["MEINS"].FieldValue="PCE";// Base Unit of Measuree1maram.Fields["MBRSH"].FieldValue="M";// Industry sectore1maram.Fields["BRGEW"].FieldValue="1";// Gross Weighte1maram.Fields["NTGEW"].FieldValue="1";// Net Weighte1maram.Fields["GEWEI"].FieldValue="KG";// Weight Unitid.Segments.Add(e1maram);// Fill text dataERPConnect.Idocs.IdocSegmente1maktm=id.CreateSegment("E1MAKTM");e1maktm.Fields["SPRAS"].FieldValue="E";// Language Keye1maktm.Fields["MAKTX"].FieldValue="my Article";// Description Texte1maram.ChildSegments.Add(e1maktm);// Send IDocid.Send();Console.WriteLine("Ready..");Console.ReadLine();
usingSystem;usingERPConnect;// Set your ERPConnect licenseLIC.SetLic("xxxx");usingvarconnection=newR3Connection(host:"server.acme.org",systemNumber:00,userName:"user",password:"passwd",language:"EN",client:"001"){Protocol=ClientProtocol.NWRFC,};connection.Open(false);Idocidoc=connection.CreateEmptyIdoc("ORDERS01","");idoc.MESTYP="ORDERS";// Fill information about idoc senderidoc.SNDPRN="1172";// Partner numberidoc.SNDPRT="KU";// Partner type// Create document header segmentIdocSegmente1edk01=idoc.CreateSegment("E1EDK01");idoc.Segments.Add(e1edk01);// Create item segmentIdocSegmente1edp01=idoc.CreateSegment("E1EDP01");e1edp01.Fields["MENGE"].FieldValue=txtQty.Text;idoc.Segments.Add(e1edp01);// Create Object identification (material number in this case)IdocSegmente1edp19=idoc.CreateSegment("E1EDP19");e1edp19.Fields["QUALF"].FieldValue="002";// 002 for material numbere1edp19.Fields["IDTNR"].FieldValue=txtMaterialNumber.Text;// material numbere1edp01.ChildSegments.Add(e1edp19);idoc.Send();this.lblInfo.Text="Idoc sent";