转载出处:http://blog.csdn.net/stone0823 https://blog.csdn.net/stone0823/article/details/50240749
动态调用FM
对于Function module(FM)的调用,VB语言可以使用动态调用的方法,代码看起来比较简洁。其他语言是否可以用这种方式,没有测试过。
动态调用FM,Exception必须作为第一个参数。直接看代码吧。
Public Sub GetCompanyCodeData_Method2()
Dim functions As SAPFunctionsOCX.SAPFunctions
' FM的输出参数,都是structure
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
' 登陆SAP
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
' Logoff
Call Logoff
End Sub
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44