I'm trying to use RFC_CALL_TRANSACTION_USING
to get the SAP ERP software run the transaction code FTE_BSM
and print the result of the report to spool. The transaction I am trying to use is FTE_BSM
, but in the end I want to be able to use it with any transaction code that can print output to spool.
I am able to connect to SAP using the following code:
If iConnectionStatus <> 1 Then
Set ObjR3 = CreateObject("SAP.Functions")
Set ObjR3_Connection = ObjR3.Connection
With ObjR3_Connection
.System = SAP_SystemID
.SystemNumber = SAP_SystemNumber
.ApplicationServer = SAP_ApplicationServer
.Client = SAP_Client
.USER = Environ("Username")
.password = UserPassword_Temp '
.Language = SAP_Language
End With
If ObjR3.Connection.Logon(1, False) <> True Then
GoTo LogInFailed
Exit Sub
End If
ObjR3_Connection.RFCWithDialog = 1
Call GetIDFromSAP
End If
In a separate routine, I call the RFC Function Module:
Dim aExecutionMap As Variant
aExecutionMap = ws_map_FTE_BSM.Range("mask_FTE_BSM").Value
Set ObjR3_Call_RFC_Transaction = ObjR3.Add("RFC_CALL_TRANSACTION_USING")
'Define SAP interal Tables
With ObjR3_Call_RFC_Transaction
.Exports("TCODE") = sReportName
.Exports("MODE") = sMode
Set ObjR3_Call_RFC_Para = .Tables("BT_DATA")
Set ObjR3_Call_RFC_Errors = .Tables("L_ERRORS")
End With
'Load Map
r = 0
For i = LBound(aExecutionMap, 1) To UBound(aExecutionMap, 1)
r = r + 1
ObjR3_Call_RFC_Para.AppendRow
c = 0
For f = LBound(aExecutionMap, 2) To UBound(aExecutionMap, 2)
c = c + 1
ObjR3_Call_RFC_Para(r, c) = aExecutionMap(i, f)
Next f
Next i
CallResult = False
CallResult = ObjR3_Call_RFC_Transaction.Call
The aExecutionMap is an Array that is loaded from a named table range containing the rows of the BT_DATA
table parameter as recorded using SAP's transaction SHDB
. I recorded the transaction twice, once with "Simulate Background Mode" switched on, once with it switched off. This did not seem to make a difference.
In the "Simulate Background Mode" switched ON, the table is:
Note that an empty cell means that the field is left blank. Also, the date is in the same format as the dialog user would input it. For debugging, I looped through the BT_DATA
table to double-check the parameters. The parameters are as follows:
Program | Dynpro | DynBegin | FNam | FVal |
---|---|---|---|---|
RFEBKAMON01 | 1000 | X | ||
0000 | BDC_OKCODE | =/BDA | ||
0000 | S_BUKRS-LOW | 0105 | ||
0000 | P_STDAT | 2020.11.30 | ||
0000 | P_VARI | /STATMONI | ||
SAPMSSY0 | 0120 | X | ||
0000 | BDC_OKCODE | =&RNT |
In the "Simulate Background Mode" switched OFF, the table is:
The parameters sent to built up the BT_DATA
table are as follows:
Program | Dynpro | DynBegin | FNam | FVal |
---|---|---|---|---|
RFEBKAMON01 | 1000 | X | ||
0000 | BDC_OKCODE | =/BDA | ||
0000 | S_BUKRS-LOW | 0105 | ||
0000 | P_STDAT | 2020.11.30 | ||
0000 | P_VARI | /STATMONI | ||
SAPLSPRI | 0100 | X | ||
0000 | BDC_OKCODE | =PRIN | ||
0000 | RADIO0500_1 | X | ||
0000 | PRI_PARAMS-PRCOP | 1 | ||
0000 | BDC_SUBSCR | SAPLSPRI 0600SUBSCREEN |
I do get a True result on the CallResult, so clearly I do get Excel to communicate with SAP, however, I do get errors as well and the spooljob is never created.
I keep getting errors regardless of whether I run the transaction using .Exports("MODE") = "N"
or .Exports("MODE") = "E"
or .Exports("MODE") = "A"
:
The errors I'm getting are:
TCODE | DYNAME | DYNUMB | MSGTYP | MSGSPRA | MSGID | MSGNR | MSGV1 |
---|---|---|---|---|---|---|---|
FTE_BSM | RFEBKAMON01 | 1010 | A | E | 00 | 341 | RAISE_EXCEPTION |
or:
TCODE | DYNAME | DYNUMB | MSGTYP | MSGSPRA | MSGID | MSGNR | MSGV1 |
---|---|---|---|---|---|---|---|
FTE_BSM | SAPMSSY0 | 1000 | A | E | 00 | 341 | DYNPRO_SEND_IN_BACKGROUND |
Examining the errors in ST22 gives me "RAISE_EXCEPTION CL_GUI_CUSTOM_CONTAINER=======CP" if run in "N" mode or "DYNPRO_SEND_IN_BACKGROUND CX_SY_SEND_DYNPRO_NO_RECEIVER RFEBKAMON01" if run in "E" or "A" mode.
Does anyone know what I'm doing wrong? Or alternatively: Does anyone maybe have a working example of how to run an SAP transaction with RFC_CALL_TRANSACTION_USING
and save the results to spool that I could analyze to learn from?