1.初始 SAP 連接介面
2.設定 SAP 連接參數
3.初始 SAP RFC 來源
4.呼叫 SAP RFC 函數
5.取得 SAP RFC 返回值
實際上透過程式碼的實作如下:
using SAP.Middleware.Connector;
using System;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;
namespace csSAP
{
class Program
{
static void Main(string[] args)
{
// 1.初始 SAP 連接介面
RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());
//2.設定 SAP 連接參數
RfcDestination prd = RfcDestinationManager.GetDestination("JTC_000");
try
{
//3.初始 SAP RFC 來源
RfcRepository repo = prd.Repository;
//4.呼叫 SAP RFC 函數
IRfcFunction stfcReader = repo.CreateFunction("BAPI_COMPANY_GETDETAIL");
// 設定要傳入的參數
stfcReader.SetValue("COMPANYID", "1010");
stfcReader.Invoke(prd);
//5.取得 SAP RFC 返回值
string strRet = stfcReader.GetStructure("COMPANY_DETAIL").GetString("NAME1");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
public class MyBackendConfig : IDestinationConfiguration
{
public RfcConfigParameters GetParameters(String destinationName)
{
if ("JTC_000".Equals(destinationName))
{
RfcConfigParameters parms = new RfcConfigParameters();
parms.Add(RfcConfigParameters.AppServerHost, "192.168.1.1");
parms.Add(RfcConfigParameters.SystemNumber, "00");
parms.Add(RfcConfigParameters.User, "UserName");
parms.Add(RfcConfigParameters.Password, "UserPassword");
parms.Add(RfcConfigParameters.Client, "100");
parms.Add(RfcConfigParameters.PoolSize, "5");
parms.Add(RfcConfigParameters.MaxPoolSize, "10");
parms.Add(RfcConfigParameters.IdleTimeout, "600");
parms.Add(RfcConfigParameters.SystemID, "JTC");
return parms;
}
else return null;
}
// The following two are not used in this example:
public bool ChangeEventsSupported()
{
return false;
}
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
}
沒有留言:
張貼留言