日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

利用NCO 3.0 调用SAP中的函数

發布時間:2025/3/11 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 利用NCO 3.0 调用SAP中的函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

.Net Connector 3.0,簡稱 Nco3.0。Nco3.0 是 SAP 針對 .net 平臺提供的編程接口,由 Nco1.0/Nco2.0 演變而來。如果使用 .net 平臺編程,推薦使用 NCo3.0。3.0 版與之前1.0/2.0 版本比較,不管是 API 還是架構,都重新設計過,也借鑒了 Jco3.0 的設計,所以相對來說更為成熟,也為程序員提供更好的控制性和方便性。

.Net connector 3.0 下載和安裝

下載地址:NCO 3.0

安裝無非就是放了幾個DLL, 選擇安裝目錄,安裝后,可以看到目錄下有這幾個文件,如下圖所示:

? ? ? ? ??


?

新建一個WinForm程序,引用兩個DLL:sapnco.dll 和 sapnco_utils.dll,如下圖所示:?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??


?根據下圖中SAP的配置,配置C#代碼:

? ?


?

首先修改App.config文件中的代碼,在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="Conn" USER="15970" PASSWD="369369" CLIENT="410" SYSNR="00" ASHOST="192.168.1.221" LANG="ZH" GROUP="PUBLIC" MAX_POOL_SIZE="10"></add></destinations></DestinationConfiguration></ClientSettings></SAP.Middleware.Connector>

然后在測試的Form中增加如下圖的代碼:?

public partial class Form1 : Form{private RfcDestination _rfcDestination = null;public DataTable dtr = new DataTable();public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){ RegisterDestination();MyInvokeRFCFunctionGetCompanyID();}public void RegisterDestination() //注冊客戶端{try{if (_rfcDestination == null){_rfcDestination = RfcDestinationManager.GetDestination("Conn");}}catch (Exception ex){MessageBox.Show(ex.Message);}}public string MyInvokeRFCFunctionGetCompanyID(){IRfcFunction function = null;string str = string.Empty;try{function = _rfcDestination.Repository.CreateFunction("Z_MES_MATQTY_LIST");//調用服務器函數function.SetValue("E_BUKRS","1001");//傳入參數function.SetParameterActive(0, true);function.Invoke(_rfcDestination);//執行服務器調用的函數IRfcTable myrfcTable = function.GetTable("ET_ITEM");//rfc server function 返回值table結構名稱int liElement = 0;for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++){RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);dtr.Columns.Add(metadata.Name);//循環創建列}foreach (IRfcStructure dr in myrfcTable)//循環table結構表{DataRow row = dtr.NewRow();//創建新行for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++){RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);row[metadata.Name] = dr.GetString(metadata.Name).Trim();}dtr.Rows.Add(row);}this.dataGridView1.DataSource = dtr;}catch (Exception ex){MessageBox.Show(ex.ToString());}return str;}}

點擊查詢按鈕即可得出結果。?

?

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的利用NCO 3.0 调用SAP中的函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。