SAP接口编程-RFC系列02 : Connection对象
来源:互联网 发布:芒果tv mac 缓存在哪 编辑:程序博客网 时间:2024/04/30 09:14
Connection对象
Connection对象负责连接至SAP系统,其他对象,比如SAPFunctions都要指定Connection对象作为其属性。上篇的编程模型,图示如下:
如何查看Connection对象的属性和方法
在VBE中添加引用后,按下F2键转到对象浏览器界面(或者使用菜单【视图】-【对象浏览器】),可以看到SAPLogonCtrl包括SAPLongonControl和Connection两个类。在这里可以看到它们的各自的方法和属性。
Connection对象的重要属性
ApplicationServer:应用程序服务器,为IP地址或者字符串,String类型
System:GUI登陆界面设置的系统标识,String类型
SystemNumber:GUI登陆界面设置的实例编号,Long类型
SAPRouter:GUI登陆界面设置中的SAPRouter字符串,外网访问需要设置的路由字符串,String类型
Client、User、Password、Language,很直观,不多说。
IsConnected: 连接的状态。使用Logon方法后,可以使用IsConneced属性判断连接的状态,共有5个值:
- Const tloRfcNotConnected = 0
- Const tloRfcConnected = 1
- Const tloRfcConnectCancel = 2
- Const tloRfcConnectParameterMissing = 4
- Const tloRfcConnectFailed = 8
Connection对象的重要方法
Logon()方法
功能:登陆SAP
语法:Function Logon(hWnd, bSilent As Boolean) As Boolean
说明:Silent登陆是指在登陆的时候,不出现登陆对话框。需要在程序中指定登录到SAP系统的完整的信息:Application Server, System number, user, password, client, language
Logoff()方法
功能:注销SAP
语法:Sub Logoff()
晚绑定
代码中,我们使用了Set logonControl = New SAPLogonControl语句。这是早绑定的使用方法。也可以用Set sapLogon = CreateObject(“SAP.LogonControl.1”)进行晚绑定。晚绑定允许在VBE中不添加SAPLogonControl,也可以使用。原理是系统注册表中存放了组件的CLASSID。
晚绑定示例
Dim sapLogon As ObjectDim sapConnection As ObjectPublic Sub Logon_LateBinding() Set sapLogon = CreateObject("SAP.LogonControl.1") Set sapConnection = sapLogon.NewConnection() Call sapConnection.Logon(0, False) Debug.Print sapConnection.IsConnectedEnd Sub
Silent Logon
Silent logon使用代码中指定的用户名和密码,登录到指定的SAP系统,在代码中必须填充完整的登陆信息。示例如下:
Dim sapLongonControl As SAPLogonCtrl.SAPLogonControlDim sapConnection As SAPLogonCtrl.ConnectionPublic Sub ConnectSAP() Set sapLongonControl = CreateObject("SAP.LogonControl.1") Set sapConnection = sapLongonControl.NewConnection ' Fill all required properties With sapConnection .System = "XXX" '系统标识 .ApplicationServer = "sap-dev" '应用服务器,一般为IP地址 .SAPRouter = "/H/XXX.XX.XXX.XX/H/" '外网连接的SAP路由 .SystemNumber = "00" '实例编号 .Client = "800" .User = "xxxx" .Password = "xxxx" End With Call sapConnection.Logon(0, True) ' hWnd, Silent Logon If sapConnection.IsConnected = tloRfcConnected Then MsgBox "OK" Else MsgBox "Error code:" & sapConnection.IsConnected End If sapConnection.LogoffEnd Sub
参考资料
http://scn.sap.com/docs/DOC-52886
SAP NetWeaver RFC SDK – RFC Client Programs
http://scn.sap.com/docs/DOC-47152
如何在Excel中使用VB宏连接SAP系统
- SAP接口编程-RFC系列02 : Connection对象
- SAP接口编程-RFC系列03 : RFC调用SAP函数
- SAP接口编程-RFC系列01 : RFC Hello World
- SAP接口编程-RFC系列11:C#语言调用RFC
- SAP接口编程-RFC系列04 : 动态调用SAP函数
- SAP接口编程-RFC系列05 : Table作为输出参数
- SAP接口编程-RFC系列06 : Table作为输入参数
- SAP接口编程-RFC系列09 : 使用BAPI
- SAP接口编程-RFC系列15 : 调用自定义FM
- SAP接口编程之 NCo3.0系列(02) : RFC Client Programs
- SAP接口编程-RFC系列08 : 获取SAP DDIC的数据字段
- SAP接口编程-RFC系列14 : 获取SAP DDIC的数据字段
- SAP接口编程-RFC系列07 : 通用的数据库表读取
- SAP接口编程-RFC系列10 : BAPI控件的DimAs方法
- SAP接口编程-RFC系列12 : Table Parameter作为输出参数
- SAP接口编程-RFC系列13 : Table Parameter作为输入参数
- RFC调用sap接口
- java调SAP RFC接口
- shuoj1962 Water and Fire Maze
- 论文笔记] Amazon推荐系统——基于item的协同过滤
- ArcGIS的基础知识(01)
- JAVA中获取用户的真实IP
- numpy的安装
- SAP接口编程-RFC系列02 : Connection对象
- Struts2国际化其一
- Android GridView
- POJ 题目2114 Boatherds(树的点分治)
- Leetcode | Climbing Stairs
- unity项目知识点记录
- android入门(九) 常用UI组件
- bin2dec函数
- C++两个栈实现队列