Create Purchase Orders using Batch Input and Background Processing
This sample shows how to execute the SAP transaction ME21 (create purchase order) as a background process.
Tip
The installation package of ERPConnect includes the Transaction-Recorder tool. This tool records transactions and implements them to code, see Transaction-Recorder.
using(R3Connectioncon=newR3Connection("SAPServer",00,"SAPUser","Password","EN","800")){con.Open();Transactiontrans=newTransaction();trans.Connection=con;trans.TCode="ME21";//Begin a new Dynprotrans.AddStepSetNewDynpro("SAPMM06E","0100");trans.AddStepSetCursor("EKKO-EKGRP");trans.AddStepSetOKCode("/00");// Entertrans.AddStepSetField("EKKO-LIFNR","1070");// Vendortrans.AddStepSetField("RM06E-BSART","NB");// Order Typetrans.AddStepSetField("RM06E-BEDAT","01.01.2006");//Purch.Datetrans.AddStepSetField("EKKO-EKORG","1000");// Purchase Orgtrans.AddStepSetField("EKKO-EKGRP","010");// Purchase Grouptrans.AddStepSetField("RM06E-LPEIN","T");//Begin a new Dynprotrans.AddStepSetNewDynpro("SAPMM06E","0120");trans.AddStepSetCursor("EKPO-WERKS(01)");trans.AddStepSetOKCode("=BU");trans.AddStepSetField("EKPO-EMATN(01)","B-7000");// Materialtrans.AddStepSetField("EKPO-MENGE(01)","20");// Quantitytrans.AddStepSetField("EKPO-WERKS(01)","1000");// Planttrans.Execute();foreach(ERPConnect.Utils.BatchReturnbrintrans.Returns)MessageBox.Show(br.Message);if(trans.Returns.Count==0)MessageBox.Show("No Messages");}
At the end the code loops over the Returns collection to check the BatchReturn objects that contain the return messages of the Batch Input transaction.