Private Sub Command1_Click() ' 定义R/3用户名和密码变量(用户名应由SAP管理员开运行函数的权限) Dim logname As String * 22, password As String * 22 Call logonr3(logname, password) ' 调用SAP登录界面程序 If logflag Then ' 调用生产、开发系统开关 StatusBar1.Visible = True StatusBar1.SimpleText = "正在登录SAP R/3系统..." Dim R3AppServer As String, R3Client As String, R3SystemNo As String If Form2.opPRD.Value Then ' 以下服务器参数请根据客户配置情况更改 R3AppServer = "10.3.1.4" ' 生产系统服务器IP R3Client = "800" '生产系统集团代码 R3SystemNo = "00" '生产系统号 Else R3AppServer = "10.3.3.1" ' 开发系统服务器IP R3Client = "101" R3SystemNo = "00" End If Unload Form2 ' 释放 Form2 , 所有控件及值不可用 Set Functions = CreateObject("Sap.Functions") ' 创建RFC的本地对象 Set Connect = Functions.Connection ' 设置连接 Connect.ApplicationServer = R3AppServer ' 赋值服务器IP Connect.Client = R3Client ' 赋值SAP集团代码 Connect.Language = "ZH" ' 置SAP系统界面中文 Connect.User = Trim(logname) ' 赋值SAP登录用户名 Connect.password = Trim(password) ' 赋值SAP登录用户密码 Connect.SystemNumber = R3SystemNo ' 赋值SAP系统号 If Not Connect.Logon(0, True) Then ' 软件登录SAP并判断 MsgBox "登录SAP R/3失败,请重新登录!", vbOKOnly + vbExclamation, "系统提示" Command1.SetFocus Else ' 登录SAP成功 Command1.Enabled = False Command2.Enabled = True test.Enabled = True End If StatusBar1.SimpleText = "" StatusBar1.Visible = False End If End Sub Private Sub Command2_Click() ' 注销SAP登录 Connect.LogOff Command2.Enabled = False Command1.Enabled = True test.Enabled = False End Sub Private Sub Command3_Click() ' 退出SAP接口演示程序 If Form1.Command2.Enabled Then MsgBox "退出前请断开SAP R/3系统!", vbOKOnly + vbInformation, "系统提示" Else End End If End Sub Private Sub Form_Load() Command2.Enabled = False test.Enabled = False logoflag = False End Sub Private Sub test_Click() ' SAP RFC远程调用处理主演示 Dim GetCustomers As Object Dim Customers As Object Dim i As Integer ' 通过RFC接口远程运行SAP内部函数RFC_CUSTOMER_GET ' 赋要调用的SAP内建函数名 Set GetCustomers = Functions.Add("RFC_CUSTOMER_GET") GetCustomers.Exports("KUNNR") = "0000000103" ' 向函数入口赋值(客户代码) ' 向函数入口赋查询表名称 Set Customers = GetCustomers.Tables("CUSTOMER_T") If GetCustomers.Call Then ' 调用成功遍历显示客户所有信息条目 For i = 1 To Customers.rowcount MsgBox Customers(i, "KUNNR") Next i Else MsgBox " 搜索出错! 出错信息: " + GetCustomers.Exception End If End Sub |