using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SAP.Middleware.Connector;
namespace ConsoleApplication2
{
class Program : IDestinationConfiguration
{
static void Main(string[] args)
{
RfcDestinationManager.RegisterDestinationConfiguration(new Program());
RfcDestination destination = RfcDestinationManager.GetDestination("EHP5");
try
{
RfcRepository repo = destination.Repository;
IRfcFunction salesDoc = repo.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT2");
IRfcFunction salesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
IRfcTable salesItems = salesDoc.GetTable("ORDER_ITEMS_IN");
IRfcTable salesPartners = salesDoc.GetTable("ORDER_PARTNERS");
IRfcStructure salesItemsStruct = salesItems.Metadata.LineType.CreateStructure();
IRfcStructure salesPartnersStruct = salesPartners.Metadata.LineType.CreateStructure();
//Sales Header
salesHeader.SetValue("DOC_TYPE", "MOR");
salesHeader.SetValue("DOC_DATE", Convert.ToDateTime("2014-06-20"));
salesHeader.SetValue("SALES_ORG", "M210");
salesHeader.SetValue("DISTR_CHAN", "01");
salesHeader.SetValue("DIVISION", "M1");
salesHeader.SetValue("CURRENCY", "USD");
//Sales Items
salesItemsStruct.SetValue("ITM_NUMBER", "000010");
salesItemsStruct.SetValue("MATERIAL", "MP_SHEET_22");
salesItemsStruct.SetValue("SHORT_TEXT", "Sheet Grade B, BWT 20lb/75gsm");
salesItemsStruct.SetValue("PLANT", "M210");
salesItemsStruct.SetValue("TARGET_QTY", "2000");
salesItemsStruct.SetValue("TARGET_QU","LBR");
salesItemsStruct.SetValue("TARGET_VAL", "11655.67");
salesItems.Append(salesItemsStruct);
// Partner
salesPartnersStruct.SetValue("PARTN_ROLE", "AG");
salesPartnersStruct.SetValue("PARTN_NUMB", "MP-CUST201");
salesPartners.Append(salesPartnersStruct);
RfcSessionManager.BeginContext(destination);
salesDoc.Invoke(destination);
salesDocCommit.Invoke(destination);
string salesDocument = salesDoc.GetString("SALESDOCUMENT");
string orderNo = salesDocument.ToString();
RfcSessionManager.EndContext(destination);
Console.WriteLine("Sales Order " + orderNo + " Created!!");
Console.ReadLine();
}
catch (RfcCommunicationException e)
{
e.ToString();
Console.WriteLine(e);
Console.ReadLine();
}
catch (RfcLogonException e)
{
e.ToString();
Console.WriteLine(e);
Console.ReadLine();
}
catch (RfcAbapRuntimeException e)
{
e.ToString();
Console.WriteLine(e);
Console.ReadLine();
}
catch (RfcAbapBaseException e)
{
e.ToString();
Console.WriteLine(e);
Console.ReadLine();
}
}
public RfcConfigParameters GetParameters(String destinationName)
{
if ("EHP5".Equals(destinationName))
{
RfcConfigParameters parms = new RfcConfigParameters();
parms.Add(RfcConfigParameters.AppServerHost, "xx.xxx.xxx.xx");
parms.Add(RfcConfigParameters.SystemNumber, "00");
parms.Add(RfcConfigParameters.SystemID, "IE1");
parms.Add(RfcConfigParameters.User, "xxxxxx");
parms.Add(RfcConfigParameters.Password, "xxxxxx");
parms.Add(RfcConfigParameters.Client, "000");
parms.Add(RfcConfigParameters.Language, "EN");
return parms;
}
else return null;
}
public bool ChangeEventsSupported()
{
return false;
}
public event RfcDestinationManager.ConfigurationChangeHandler
ConfigurationChanged;
}
}
No comment