对于Function module(FM)的调用,VB语言可以使用动态调用的方法,代码看起来比较简洁。其他语言是否可以用这种方式,没有测试过。
动态调用FM,Exception必须作为第一个参数。直接看代码吧。
Public Sub GetCompanyCodeData_Method2()
Dim functions As SAPFunctionsOCX.SAPFunctions
Dim ret As SAPFunctionsOCX.Structure 'return'
Dim coCdDetail As SAPFunctionsOCX.Structure 'company code detail'
Dim addrData As SAPFunctionsOCX.Structure 'address data'
Dim ex As String 'exception'
Call Logon
' 如果连接成功,调用BAPI'
If sapConnection.IsConnected <> tloRfcConnected Then
MsgBox "连接失败."
Exit Sub
End If
Set functions = New SAPFunctionsOCX.SAPFunctions
Set functions.Connection = sapConnection
' 动态调用BAPI_COMPANYCODE_GETDETAIL'
' exception必须放在第一个参数位置'
functions.BAPI_COMPANYCODE_GETDETAIL _
ex, _
COMPANYCODEID:="0001", _
RETURN:=ret, _
COMPANYCODE_DETAIL:=coCdDetail, _
COMPANYCODE_ADDRESS:=addrData
' 确定没有Exceptions'
If ex <> "" Then
Exit Sub
End If
' 输出company code detail'
Dim i As Integer
For i = 1 To coCdDetail.ColumnCount
Debug.Print coCdDetail.ColumnName(i) & ":" & coCdDetail.Value(i)
Next
Call Logoff
End Sub
网友评论