在vs2005中使用Com连接SAP系统-Form方式
2009-01-22 09:37
274 查看
原文地址:/article/5727947.html
一,添加对Interop.SAPFunctionsOCX.dll以及Interop.SAPLogonCtrl.dll这两个com组件的引用。
二,通过SAPLogonCtrl进行SAP系统的登录,输入登陆SAP系统需要的一些参数,具体参见如下代码:
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();
三,登陆成功后,通过SAPFunctionsOCX对SAP中的Function Module进行调用。具体步骤为:首先创建SAPFunctionsOCX.SAPFunctionsClass的实例func ,并设置其需要使用的Connection;然后使用func的Add方法添加需要调用的function module的名称(返回一个SAPFunctionsOCX.IFunction对象ifunc);再使用ifunc的get_Exports方法获取function module中的输入参数,最后对参数进行赋值;然后再调用ifunc的call方法进行调用;最后使用ifunc的get_Imports或者Tables方法获取返回值。具体参见如下代码:
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中调用SAP ECC中的
一,添加对Interop.SAPFunctionsOCX.dll以及Interop.SAPLogonCtrl.dll这两个com组件的引用。
二,通过SAPLogonCtrl进行SAP系统的登录,输入登陆SAP系统需要的一些参数,具体参见如下代码:
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();
三,登陆成功后,通过SAPFunctionsOCX对SAP中的Function Module进行调用。具体步骤为:首先创建SAPFunctionsOCX.SAPFunctionsClass的实例func ,并设置其需要使用的Connection;然后使用func的Add方法添加需要调用的function module的名称(返回一个SAPFunctionsOCX.IFunction对象ifunc);再使用ifunc的get_Exports方法获取function module中的输入参数,最后对参数进行赋值;然后再调用ifunc的call方法进行调用;最后使用ifunc的get_Imports或者Tables方法获取返回值。具体参见如下代码:
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中调用SAP ECC中的
相关文章推荐
- 在vs2005中使用Com连接SAP系统-Web方式
- 在vs2005中使用Com连接SAP系统-
- 在vs2005中使用Com连接SAP系统(一)
- 在vs2005中使用Com连接SAP系统(二)
- 在vs2005中使用Com连接SAP系统(一)
- 在vs2005中使用Com连接SAP系统(一)
- 在vs2005中使用Com连接SAP系统(二)
- 在vs2005中使用Com连接SAP系统(二)
- wget提示 要以不安全的方式连接至 dev.mysql.com,使用‘--no-check-certificate’ 解决。
- ThinkPHP3.0使用pdo方式连接sqlserver 2000、mssql 2000的配置,直接上配置文件,php版本是php5.2,服务器环境是ComsenzEXP
- VirtualBox 使用 NAT 方式网络的 SSH 连接
- HttpWebRequest 下载网页Html代码 POST方式(站内使用了form方式) System.Net.WebException (417) Expectation failed
- VM连接外网三种方式以及使用cecureCRT连接Linux.
- 常见数据库使用JDBC连接方式
- windows 2003下asp.Net站点无法使用用户名+密码的方式连接SQLSERVER的问题
- java连接数据库方式(二):单独使用MyBatis 框架实现
- Java_JDBC连接数据库_使用读取配置文件的方式
- ADO.NET使用集成方式连接