大家好,又见面了,我是你们的朋友全栈君。
一,创建Function Module
1,在SE11,创建需要的structure (必须为flat类型,否则会出现Reference parameters are not allowed with RFC)
2,在SE80,建Function group
3,在SE37,创建Function Module(import的参数入药是value传值)
Note:一个Function
Group只能包含一个BAPI;参数传值;必须有有一个BAPIRETURN类型的EXPORT参数
二,封装
1,在SWO1,建Object Type
2,把Function Module作为一个Method加入,utilities->API
Methods->Add Method
3,release Object和Module。使在BAPI Browser 中可以看到。也就是外部能够调用。
三,调用
1,如在另一系统中用ABAP调用,先在SM59中建RFC联到有BAPI的R/3,(ZGOGO)
在SE38的程序中调用,Call Function “ZBAPIXXXXX” DESTINATION ZGOGO
EXPORTING …
2,如用JAVA调用
引入包;(不一定要用IBM的)
import com.sap.rfc.*;
import com.sap.rfc.exception.*;
import com.ibm.sap.bapi.*;
import com.ibm.sap.bapi.generated.*;
建立连接;调用。。。(See CALL_BAPI.java)
VBA for SAP
Private Sub CommandButton1_Click()
Set oFunction = CreateObject(“SAP.LogonControl.1”)
Set oConnection = oFunction.NewConnection
oConnection.Client = “500”
oConnection.Language = “EN”
oConnection.User = “user”
oConnection.Password = “pasword”
oConnection.ApplicationServer = “sap1.yok.com.cn”
oConnection.SystemNumber = “01”
result = oConnection.Logon(0, True)
Set ofun = CreateObject(“SAP.FUNCTIONS”)
Set ofun.Connection = oConnection
Set func = ofun.Add(“RFC_READ_TABLE”)
func.Exports(“QUERY_TABLE”) = “MARA”
If func.Call = True Then
Set oline = func.tables.Item(“DATA”)
Row = oline.rowcount
i = 1
Do While i <= Row
Cells(i, 1) =
Mid(Trim(oline.Value(i, 1)), 4, 22)
i = i + 1
Loop
Else
MsgBox “FAIL”
End If
End Sub
VBA2
Private Sub CommandButton1_Click()
Dim sapFunctionCtrl As
Object ‘Function Control (Collective object)
Dim sapConnection As
Object ‘Connection object
Dim theFunc As
Object ‘Function object
Set sapFunctionCtrl = CreateObject(“SAP.Functions”)
Set sapConnection = sapFunctionCtrl.Connection
sapConnection.Client = “800”
sapConnection.user = “user”
sapConnection.Language = “EN”
If sapConnection.logon(0, False) <>
True Then
MsgBox “No connection to R/3!”
End If
Set theFunc = sapFunctionCtrl.Add(“ZRFCPING”)
If theFunc.call Then ‘ call the RFC FM
MsgBox “RFC call is okay”
End If
sapFunctionCtrl.Connection.logoff
Set sapConnection = Nothing
Set sapFunctionCtrl = Nothing
End Sub
———————
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/163915.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...