Beispiel #1
0
        private static void SendIDoc(R3Connection con, string matname, bool async)
        {
            using (con)
            {
                con.Open(false);

                ERPConnect.Idocs.Idoc id = con.CreateEmptyIdoc("MATMAS05", "");

                id.SNDPRN = "ERPTEST";
                id.SNDPRT = "LS";
                id.SNDPOR = "ERPTEST";
                id.RCVPRN = "BW_STDCLNT";
                id.RCVPRT = "LS";
                id.MESTYP = "MATMAS";

                // Idoc Segement E1MARAM
                ERPConnect.Idocs.IdocSegment e1maram = id.CreateSegment("E1MARAM");
                e1maram.Fields["MATNR"].FieldValue = matname;
                e1maram.Fields["MTART"].FieldValue = "FERT";
                e1maram.Fields["MEINS"].FieldValue = "PCE";
                e1maram.Fields["MBRSH"].FieldValue = "M";
                e1maram.Fields["BRGEW"].FieldValue = "1";
                e1maram.Fields["NTGEW"].FieldValue = "1";
                e1maram.Fields["GEWEI"].FieldValue = "KG";
                id.Segments.Add(e1maram);

                // Idoc Segement E1MAKTM
                ERPConnect.Idocs.IdocSegment e1maktm = id.CreateSegment("E1MAKTM");
                e1maktm.Fields["SPRAS"].FieldValue = "E";
                e1maktm.Fields["MAKTX"].FieldValue = "my Article";
                e1maram.ChildSegments.Add(e1maktm);

                if (async)
                {
                    id.SendAndWait();
                    IdocStatus status = id.GetCurrentStatus();
                    Console.WriteLine(status.Status + "-> " + status.Description);
                }
                else
                {
                    id.Send();
                    Console.WriteLine("IDoc sent");
                }

                con.Close();
                Console.ReadLine();
            }
        }