usingSystem;usingERPConnect;Console.Write("Vendor: ");stringvendor=Console.ReadLine();Console.Write("Material: ");stringmaterial=Console.ReadLine();Console.Write("Plant: ");stringplant=Console.ReadLine();Console.Write("Quantity: ");decimalquantity=decimal.Parse(Console.ReadLine()??string.Empty);// 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();// Create an RFC-Function objectRFCFunctionfunc=connection.CreateFunction("BAPI_PO_CREATE");// Fill header structureRFCStructureheader=func.Exports["PO_HEADER"].ToStructure();header["DOC_TYPE"]="NB";header["PURCH_ORG"]="1000";header["PUR_GROUP"]="010";header["DOC_DATE"]=DateTime.Now.ToString("yyyyMMdd");header["VENDOR"]=vendor;// Create an ItemRFCTableitems=func.Tables["PO_ITEMS"];RFCStructureitem=items.AddRow();item["PO_ITEM"]="1";item["PUR_MAT"]=material;item["PLANT"]=plant;// Create and fill schedulesRFCTableschedules=func.Tables["PO_ITEM_SCHEDULES"];RFCStructureschedule=schedules.AddRow();schedule["PO_ITEM"]="1";schedule["DELIV_DATE"]=DateTime.Now.ToString("yyyyMMdd");schedule["QUANTITY"]=quantity;// Execute Bapi and process return messagesfunc.Execute();varreturnMessage=func.Tables["RETURN"].Rows[0,"MESSAGE"].ToString();Console.WriteLine($"Message: {returnMessage}");
Output:
Message: Standard PO created under the number 4500018292