Hello,
I am running a macro that creates documents in SAP, so the user is already logged on in the system.
I want to call a RFC. I have this code that is already working, but my question is, as the user is already logged on, do I always need to make this logon again?
Is it possible to take credentials from active SAP Session or similar?
If not, each time my script saves a document and RFC is called, another loggon will happen.
Regards,
Brian
I am running a macro that creates documents in SAP, so the user is already logged on in the system.
I want to call a RFC. I have this code that is already working, but my question is, as the user is already logged on, do I always need to make this logon again?
Is it possible to take credentials from active SAP Session or similar?
If not, each time my script saves a document and RFC is called, another loggon will happen.
Code:
Public Sub RFC_Read_Table()Dim Functions As Object
Dim RfcCallTransaction As Object
Dim Messages As Object
Dim BdcTable As Object
Dim tblOptions
Dim tblData
Dim tblFields
Dim strExport1
Dim strExport2
Dim filOutput
Dim intRow As Integer
Dim conn As Object
Dim sap As Object
Set Functions = CreateObject("SAP.Functions")
Functions.Connection.System = "RR1"
Functions.Connection.client = "010"
Functions.Connection.user = "confob1"
Functions.Connection.Password = "xxx"
Functions.Connection.Language = "EN"
If Functions.Connection.logon(0, True) <> True Then
Exit Sub
End If
Set RfcCallTransaction = Functions.Add("RFC_READ_TABLE")
Set strExport1 = RfcCallTransaction.exports("QUERY_TABLE")
Set strExport2 = RfcCallTransaction.exports("DELIMITER")
Set tblOptions = RfcCallTransaction.Tables("OPTIONS") '
Set tblData = RfcCallTransaction.Tables("DATA") '
Set tblFields = RfcCallTransaction.Tables("FIELDS") '
strExport1.Value = "VBFA"
strExport2.Value = ";"
tblOptions.AppendRow
tblOptions(1, "TEXT") = "VBELV EQ '0050015909' and VBTYP_N EQ 'I' "
tblOptions.AppendRow
tblFields.AppendRow
tblFields(1, "FIELDNAME") = "VBELN"
If RfcCallTransaction.Call = True Then
If tblData.RowCount > 0 Then
For intRow = 1 To tblData.RowCount
OutputTxt1 = tblData(intRow, "WA")
Next
Else
MsgBox "No records returned"
End If
Else
MsgBox "Error"
End If
Set filOutput = Nothing
Functions.Connection.Logoff
End Sub
Regards,
Brian