定义:
Public SapLogin As Object
Public SapFC As Object
Public GetSapValue As String
Public ReturnFunction As Boolean
Public TheFunction As Object
Public SAPFunction As Object
Public GetData As Object
连接:
Function GetSap() As String
SapFC = CreateObject("SAP.Functions")
SapLogin = SapFC.Connection
'----------------810-----------------
GetSapValue = "PRD"
SapLogin.ApplicationServer = "11.11.11.11"
SapLogin.Client = "800"
SapLogin.User = "user"
SapLogin.Password = "123456"
SapLogin.SystemNumber = "00"
SapLogin.Language = "en"
SapLogin.AutoLogon = True
If SapLogin.Logon(0, True) <> True Then
MsgBox("登陆SAP/R3失败!")
Else
End If
Return Nothing
End Function
使用:
TheFunction = SapFC.Add("YRFC") 'Function FROM SAP
TheFunction.Exports("P_MATNR") = TxtMateNO.Text.ToUpper '输入:MATNR
GetData = TheFunction.Tables("YTABLE") '输出:Table
ReturnFunction = TheFunction.Call '调用
If ReturnFunction = True Then '返回数据为真
If GetData.rowcount < 1 Then
MsgBox("SAP系统内没有相关数据!")
Exit Sub
End If
materialDesc = GetData(1, "MAKTX") 'MAKTX - Material Desccription 得到物料描述
standardWorkingHour = GetData(1, "VGW02") 'VGW02 - Working Hour 得到SAP标准工时
End If