You can send IDocs to SAP with the help of LINQ to SAP. The segments can be used in the SAP context.

To use an IDoc in .NET, drag the IDoc component from the toolbox to the data context. The selection of the IDoc is done in the search dialog.


In the following dialog you can find in the left area the structure of the IDoc. In the lower area the fields are shown of the segment that is selected in the treeview. Uncheck unused fields or rename them. In the upper right corner you will find the class names and the collection names (names are generated automatically). If you like, just rename them.


The checkbox selected can be used to deactivate segments which are not used later in the code. Deactivated segments are shown in italic in the treeview.

The following code shows how to use the generated classes. First an IDoc object is generated (MATMAS05) and the most important header information is filled (e.g. sender and receiver information like RCVPRN or SNDPRN).

Two Segments are created: E1MARAM (Basicdata) and E1MAKTM (Shorttext), filled with the required fields and added to the IDoc. The IDoc is sent with Send().

Click to open C# example.
static void Main(string[] args) 
      SAPContext sc = new SAPContext("User", "password"); 
      SAPContext.MATMAS05 MATMAS5 = new SAPContext.MATMAS05(sc.Connection); 
      SAPContext.E1MARAM E1MARAM = new SAPContext.E1MARAM(); 
      SAPContext.E1MAKTM E1MAKTM = new SAPContext.E1MAKTM(); 
      MATMAS5.RCVPRN = "T90CLNT090"; 
      MATMAS5.RCVPRT = "LS"; 
      MATMAS5.SNDPRT = "LS"; 
      E1MARAM.MATNR = "100-890"; 
      E1MARAM.MEINS = "KG"; 
      E1MARAM.MATKL = "001"; 
      E1MARAM.GEWEI = "KG"; 
      E1MARAM.MTART = "ROH"; 
      E1MAKTM.MAKTX = "TestMat"; 
      Console.WriteLine("IDoc sent successfully"); Console.ReadLine(); 
      catch (Exception e1) 
         Console.WriteLine(e1.Message); Console.ReadLine(); 

In the transaction WE02 we can see the incoming IDocs, and if the status is green they are successfully processed.