Hi all,
I'm trying tomake a connectionwithSAPthroughtheSAP.Functionsobject, the connection's propertyRfcWithDialogis setto True,so it ispossible to usetheSAPscreensduring anRFC call,howeverwhen running themethodcallSAP's screen isnot shown as it should,noting that thecodeusedworked perfectlyuntila fewdays ago. Can anyone helpme solvethis problem?
Sub RecordBDC()
Dim SAPConn As Object
Dim rfcFunc As Object
Dim authCheck As Object
Dim tCode As Object
Dim dynTab As Object
Dim mesTab As Object
Dim idx1 As Long
Dim idx2 As Long
'Create the SAP Functions object
Set SAPConn = CreateObject("SAP.Functions")
'Set up Connections parameters
SAPConn.Connection.System = "d4. PD4 - Produção TIM ONE CLIENT"
SAPConn.Connection.client = "203"
SAPConn.Connection.user = "MyUser"
SAPConn.Connection.Password = "MyPassWord"
SAPConn.Connection.Language = "PT"
SAPConn.Connection.RfcWithDialog = True
'Performing the connection
If SAPConn.Connection.IsConnected = 1 Then
SAPConn.Connection.logoff
If SAPConn.Connection.Logon(0, True) <> True Then
MgSapLogOn = vbCancel
Exit Sub
End If
Else
If SAPConn.Connection.Logon(0, True) <> True Then
MgSapLogOn = vbCancel
Exit Sub
End If
End If
End With
'Set up RFC parameters
Set rfcFunc = SAPConn.Add("BDC_RECORD_TRANSACTION")
Set tCode = rfcFunc.exports("TCODE")
Set authCheck = rfcFunc.exports("AUTHORITY_CHECK")
Set dynTab = rfcFunc.tables("DYNPROTAB")
Set mesTab = rfcFunc.tables("MESSTAB")
tCode.Value = "Z_SD_FAT_DET"
'Call the RFC
DoEvents
If rfcFunc.Call = True Then 'SAPshould showthe screenof thetransactiondefinedinparameter tCode
idx2 = 0
conRepl = MsgBox("Do you need BDC_CURSOR/BDC_SUBSCR?", vbYesNo + vbDefaultButton2)
For idx1 = 1 To dynTab.RowCount
If conRepl = vbNo And dynTab.Value(idx1, "FNAM") = "BDC_SUBSCR" Or dynTab.Value(idx1, "FNAM") = "BDC_CURSOR" Then
Else
idx2 = idx2 + 1
ActiveSheet.Cells(idx2 + 1, 1) = idx2
ActiveSheet.Cells(idx2 + 1, 2) = dynTab.Value(idx1, "PROGRAM")
ActiveSheet.Cells(idx2 + 1, 3) = dynTab.Value(idx1, "DYNPRO")
ActiveSheet.Cells(idx2 + 1, 4) = dynTab.Value(idx1, "DYNBEGIN")
ActiveSheet.Cells(idx2 + 1, 5) = dynTab.Value(idx1, "FNAM")
ActiveSheet.Cells(idx2 + 1, 6) = "'" & dynTab.Value(idx1, "FVAL")
End If
Next
MsgBox "Completed"
Else
MsgBox "Transaction cannot be called. " & Chr(13) & "Please check auth. or etc.."
End If
End Sub