C# 如何調(diào)用SAP RFC
結(jié)構(gòu):
安裝NuGet包:
using SAP.Middleware.Connector; using System.Data; namespace DFDN.SDK.ServiceInterface { public class RfcDemo { public void Loading() { RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(GetParameters()); //連接字符串 RfcDestination SapRfcDestinationForConfig = RfcDestinationManager.GetDestination("dad"); //連接字符串 從App.config配置 RfcRepository SapRfcRepository = SapRfcDestination.Repository; DataTable dt = new DataTable(); //數(shù)據(jù)源 dt.Columns.Add("DATA1", typeof(string)); dt.Columns.Add("DATA2", typeof(string)); dt.Columns.Add("DATA3", typeof(string)); IRfcFunction func = SapRfcRepository.CreateFunction("Z_RFC_XXXX"); IRfcTable tSAP = func.GetTable("INPUT_TABLE"); for (int i = 0; i < dt.Rows.Count; i++) { string str1 = dt.Rows[i][0].ToString(); string str2 = dt.Rows[i][1].ToString(); string str3 = dt.Rows[i][2].ToString(); IRfcStructure struSAP = tSAP.Metadata.LineType.CreateStructure(); struSAP.SetValue("str1", str1); struSAP.SetValue("str2", str2); struSAP.SetValue("str3", str3); tSAP.Append(struSAP); } func.SetValue("INPUT_TABLE", tSAP); //table 參數(shù) func.SetValue("WERKS", "A"); //單個(gè)參數(shù) func.SetValue("STATUS", "B"); //單個(gè)參數(shù) func.Invoke(SapRfcDestination); //調(diào)用 IRfcTable SAPDataTable = func.GetTable("RETURN_TABLE"); //獲取表格結(jié)果 DataTable table = ToDataTable(SAPDataTable); //轉(zhuǎn)換DataTable string result = func.GetValue("X").ToString(); //獲取指定返回結(jié)果 } /// <summary> /// RfcTable 轉(zhuǎn)換為 DataTable /// </summary> /// <param name="myrfcTable"></param> /// <returns></returns> public DataTable ToDataTable(IRfcTable myrfcTable) { DataTable loTable = new DataTable(); int liElement; for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); loTable.Columns.Add(metadata.Name); } foreach (IRfcStructure Row in myrfcTable) { DataRow ldr = loTable.NewRow(); for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); ldr[metadata.Name] = Row.GetString(metadata.Name); } loTable.Rows.Add(ldr); } return loTable; } /// <summary> /// SAP RFC 連接信息設(shè)置 /// </summary> /// <returns></returns> public RfcConfigParameters GetParameters() { RfcConfigParameters parms = new RfcConfigParameters(); parms.Add(RfcConfigParameters.AppServerHost, "192.168.0.114"); //SAP主機(jī)IP parms.Add(RfcConfigParameters.SystemNumber, "01"); //SAP實(shí)例 parms.Add(RfcConfigParameters.User, "RFC_EDI"); //用戶名 parms.Add(RfcConfigParameters.Password, "init1"); //密碼 parms.Add(RfcConfigParameters.Client, "300"); // Client parms.Add(RfcConfigParameters.Language, "ZH"); //登陸語(yǔ)言 parms.Add(RfcConfigParameters.PoolSize, "10"); parms.Add(RfcConfigParameters.IdleTimeout, "600"); parms.Add(RfcConfigParameters.Name, "DAP"); return parms; } } }
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="SAP.Middleware.Connector"> <sectionGroup name="ClientSettings"> <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration,sapnco"/> </sectionGroup> </sectionGroup> </configSections> <SAP.Middleware.Connector> <ClientSettings> <DestinationConfiguration> <destinations> <add NAME="dad" USER="ddac" PASSWD="qwe" CLIENT="110" SYSNR="00" ASHOST="192.168.0.111" LANG="ZH" GROUP="PUBLIC" MAX_POOL_SIZE="10" IDLE_TIMEOUT="600"></add> </destinations> </DestinationConfiguration> </ClientSettings> </SAP.Middleware.Connector> </configuration>
以上就是C# 如何調(diào)用SAP RFC的詳細(xì)內(nèi)容,更多關(guān)于C# 調(diào)用SAP RFC的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#實(shí)現(xiàn)用戶自定義控件中嵌入自己的圖標(biāo)
這篇文章主要介紹了C#實(shí)現(xiàn)用戶自定義控件中嵌入自己的圖標(biāo),較為詳細(xì)的分析了C#實(shí)現(xiàn)自定義控件中嵌入圖標(biāo)的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-03-03C#語(yǔ)法相比其它語(yǔ)言比較獨(dú)特的地方(一)
這篇文章主要介紹了C#語(yǔ)法相比其它語(yǔ)言比較獨(dú)特的地方(一),本文講解了switch語(yǔ)句可以用來(lái)測(cè)試string型的對(duì)象、多維數(shù)組、foreach語(yǔ)句、索引器和Property等內(nèi)容,需要的朋友可以參考下2015-04-04C#使用Equals()方法比較兩個(gè)對(duì)象是否相等的方法
這篇文章主要介紹了C#使用Equals()方法比較兩個(gè)對(duì)象是否相等的方法,涉及C#操作對(duì)象的相關(guān)技巧,需要的朋友可以參考下2015-04-04HttpWebRequest出錯(cuò).Section=ResponseHeader Detail=CR
HttpWebRequest出錯(cuò).Section=ResponseHeader Detail=CR...2007-03-03c#實(shí)現(xiàn)最簡(jiǎn)潔的快速排序(你絕對(duì)可以看懂)
這篇文章主要給大家介紹了關(guān)于利用c#實(shí)現(xiàn)如何最簡(jiǎn)潔的快速排序,實(shí)現(xiàn)的方法你絕對(duì)可以看懂,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用c#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05C#設(shè)置程序開機(jī)啟動(dòng)的實(shí)現(xiàn)示例
本文主要介紹了C#設(shè)置程序開機(jī)啟動(dòng)的實(shí)現(xiàn)示例,可以通過(guò)修改注冊(cè)表將啟動(dòng)信息寫入注冊(cè)表來(lái)實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01C#多線程之Thread中Thread.IsAlive屬性用法分析
這篇文章主要介紹了C#多線程之Thread中Thread.IsAlive屬性用法,實(shí)例分析了C#判斷線程可用狀態(tài)的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04