在vs2005中使用Com连接SAP系统(一)
???? 我分別以form和web的形式對(duì)SAP中的Function module進(jìn)行了調(diào)用,在form中稍微簡(jiǎn)單一點(diǎn),具體如下:
???? 一,添加對(duì)Interop.SAPFunctionsOCX.dll以及Interop.SAPLogonCtrl.dll這兩個(gè)com組件的引用。
???? 二,通過(guò)SAPLogonCtrl進(jìn)行SAP系統(tǒng)的登錄,輸入登陸SAP系統(tǒng)需要的一些參數(shù),具體參見(jiàn)如下代碼:
??????????? SAPLogonCtrl.SAPLogonControlClass logon = new SAPLogonCtrl.SAPLogonControlClass();
??????????? logon.ApplicationServer = "";???????????????? //SAP system's IP
??????????? logon.Client = "";??????????????????????????????????????????? ?//SAP system'client
??????????? logon.Language = "EN";
??????????? logon.User = "";????????????????????????????? //Username
??????????? logon.Password = "";?????????????????????????????? //Password
??????????? logon.SystemNumber = 00;???????????????????????????????? //System number
??????????? SAPLogonCtrl.Connection conn = (SAPLogonCtrl.Connection)logon.NewConnection();
???? 三,登陸成功后,通過(guò)SAPFunctionsOCX對(duì)SAP中的Function Module進(jìn)行調(diào)用。具體步驟為:首先創(chuàng)建SAPFunctionsOCX.SAPFunctionsClass的實(shí)例func,并設(shè)置其需要使用的Connection;然后使用func的Add方法添加需要調(diào)用的function module的名稱(chēng)(返回一個(gè)SAPFunctionsOCX.IFunction對(duì)象ifunc);再使用ifunc的get_Exports方法獲取function module中的輸入?yún)?shù),最后對(duì)參數(shù)進(jìn)行賦值;然后再調(diào)用ifunc的call方法進(jìn)行調(diào)用;最后使用ifunc的get_Imports或者Tables方法獲取返回值。具體參見(jiàn)如下代碼:
????if (conn.Logon(0, true))??????????????????????????????? //login successful
??????????? {
??????????????? SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
??????????????? func.Connection = conn;
??????????????? SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add("ENQUEUE_READ");?????????? //Call Function module 'ENQUEUE_READ'
??????????????? SAPFunctionsOCX.IParameter? gclient = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("GCLIENT");? //Get the import paremeter
??????????????? gclient.Value = "301";?????????????????????????????????????????????????????????????????????????? //Set value for import paremeter
??????????????? SAPFunctionsOCX.IParameter GUNAME = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("GUNAME");
??????????????? GUNAME.Value = "";
??????????????? SAPFunctionsOCX.IParameter LOCAL = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("LOCAL");
??????????????? LOCAL.Value = "0";
??????????????? ifunc.Call();
??????????????? SAPFunctionsOCX.IParameter NUMBER = (SAPFunctionsOCX.IParameter)ifunc.get_Imports("SUBRC");
??????????????? SAPTableFactoryCtrl.Tables ENQs = (SAPTableFactoryCtrl.Tables)ifunc.Tables;????????????? //get all the tables
??????????????? SAPTableFactoryCtrl.Table ENQ = (SAPTableFactoryCtrl.Table)ENQs.get_Item("ENQ");? //Get table 'ENQ'
??????????????? int n = ENQ.RowCount;
??????????????? DataTable dt = CreateTable();
??????????????? for (int i = 1; i <= n; i++)
??????????????? {
??????????????????? DataRow dr = dt.NewRow();
??????????????????? dr["GNAME"] = ENQ.get_Cell(i, "GNAME").ToString();????????????????????????????????? //Get cell information
??????????????????? dr["GUNAMe"] = ENQ.get_Cell(i, "GUNAME").ToString();
??????????????????? dr["GARG"] = ENQ.get_Cell(i, "GARG").ToString();
??????????????????? dr["GOBJ"] = ENQ.get_Cell(i, "GOBJ").ToString();
??????????????????? dr["GTDATE"] = ENQ.get_Cell(i, "GTDATE").ToString();
??????????????????? dt.Rows.Add(dr);
??????????????? }
??????????????? dataGridView1.DataSource = dt;
??????????????? dataGridView1.Visible = true;
??????????????? label1.Text = "Get data from FM 'ENQUEUE_READ' OK!";
??????????? }
??????????? else
??????????????? label1.Text = "NO";
??????? }
?????這樣就可以在form中調(diào)用SAP ECC中的function module了!至于在web形式下如何調(diào)用將在下篇中進(jìn)行描述!
總結(jié)
以上是生活随笔為你收集整理的在vs2005中使用Com连接SAP系统(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: FM之SO_DOCUMENT_SEND_
- 下一篇: 在vs2005中使用Com连接SAP系统