[英]No RFC authorization for function module RFC PING during SAP logon from VBA
大家早上好!
最近幾天我一直在尋找解決方案,但我真的沒有成功:我正在嘗試制作一個 VBA 代碼:
但即使是“登錄 SAP”部分也不行!
我嘗試了幾個代碼,下面的一個打開 SAP 登錄屏幕,但沒有填寫任何字段。
在第一次嘗試中,我使用了CreateObject("Sapgui.ScriptingCtrl.1")
:
Sub Entrar_SAP()
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("xxxxxxx)", True)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "user"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "pass"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"
session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
session.findById("wnd[0]").sendVKey 0
在第二次嘗試中,我嘗試了CreateObject("SAP.Functions")
,它顯示:
“收到 RFC 錯誤。功能模塊 RFC PING 沒有 RFC 授權”
代碼是:
'Declaration
Dim objBAPIControl As Object 'Function Control (Collective object)
Dim sapConnection As Object 'Connection object
Set objBAPIControl = CreateObject("SAP.Functions")
Set sapConnection = objBAPIControl.Connection
sapConnection.Client = "xxxxx"
sapConnection.User = "xxxxxx"
sapConnection.Language = "PT"
sapConnection.hostname = "xxxxx"
sapConnection.Password = "xxxxxxxx" 'Fake password
sapConnection.SystemNumber = "4"
sapConnection.System = "xxxxxx)"
sapConnection.Logon
If sapConnection.Logon(1, True) <> True Then
MsgBox "No connection to R/3!"
Exit Sub 'End program
End If
有人可以幫幫我嗎? 謝謝!!
首先,RFC 是一種非常好的與 SAP 交互的方法。 這不是不支持。
其次,您沒有足夠的授權,因此即使您的語法正確,您的代碼也無法運行。 “收到 RFC 錯誤。功能模塊 RFC PING 沒有 RFC 授權”。 請您的 SAP 團隊授予您遠程執行 RFC 的權限。 請求SAP_S_RFCACL 。
附帶說明一下,運行一些事務並導出到 Excel 的主要對象在 SAP 中很容易完成。 也許你應該讓你的 SAP 團隊為你做這件事,而不是在 VBA 中開發它?
我假設您通過 RFC 讀取表進行拉取。 這個連接對那些人來說很好用。
Dim LogonControl As Object
Dim conn As Object
Dim retcd As Boolean
Set LogonControl = CreateObject("SAP.LogonControl.1")
Set conn = LogonControl.NewConnection
conn.System = "strSystemName"
conn.Client = "100"
conn.Language = "EN"
conn.User = "sUserName"
conn.Password = "strPassword"
retcd = conn.Logon(0, True) 'True = No logon GUI 'False = logon GUI
If retcd <> True Then
MsgBox "Login failed for- " & strSystemName & " -UserName or Password are incorrect, check them and run try again ."
Exit Sub
End If
Set funcControl = CreateObject("SAP.Functions")
funcControl.Connection = conn
從現在開始,您可以毫無問題地進行 RFC 調用。
但說實話,上面幾乎就是你作為第二個例子所擁有的。 您收到的 RFC 錯誤似乎沒有 SAP 的安全設置,無法對您從中提取的任何表進行 RFC 調用,而您的登錄代碼沒有問題。
免責聲明:RFC_READ_TABLE不是由SAP支持,更多的是一種后門程序,然后進行日常方法提取數據的。
編輯 1:為了覆蓋評論而不是將其變成討論,我將嘗試在這里總結它們。
首先
彈窗:如果你想要登錄的彈窗,那么你需要改變這行代碼
retcd = conn.Logon(0, True)
到
retcd = conn.Logon(0, False) 'This one DISPLAYS the pop-up
其次
權限:RFC_Read_Table 使用非常不同的安全設置,然后使用 SAP t-Code,技術差異很難解釋,但根據經驗,如果您無法訪問 SAP 表(t-Code SE16),您很可能無法訪問從 RFC 讀取表中提取它
第三
如果你的公司有多個SAP盒(DEV,生產,試驗)的SYSTEMNAME會正是SAP的名義下框選屏幕上顯示出來。 假設您從第二個代碼塊中收到 RFC 錯誤,那么您在該代碼中使用的框名稱將是正確的。
您可以繞過 RFC 控制,只需使用模擬人類用戶並手動引入用戶名和密碼的普通腳本即可。 歸功於 SAP 論壇中的腳本人:
Sub SapLogin()
'Logs onto SAP system
Dim SapGuiApp As Object
Dim oConnection As Object
Dim session As Object
Dim SAPCon As Object, SAPSesi As Object
Dim SAPGUIAuto As Object, SAPApp As Object
Dim system As String
system = "XX" 'SAP system you will log on to like "01. ENGINEERING PRODUCTION [EG1]
If SapGuiApp Is Nothing Then
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If oConnection Is Nothing Then
Set oConnection = SapGuiApp.OpenConnection(system, True)
End If
If SAPSesi Is Nothing Then
Set SAPSesi = oConnection.Children(0)
End If
Application.DisplayAlerts = FALSE
With SAPSesi
.FindById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"
.FindById("wnd[0]/usr/txtRSYST-BNAME").Text = "USERNAME"
.FindById("wnd[0]/usr/pwdRSYST-BCODE").Text = "PASSWORD"
.FindById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
.FindById("wnd[0]").SendVKey 0
'start extraction
.FindById("wnd[0]").Maximize
.FindById("wnd[0]/tbar[0]/okcd").Text = "/TCODEYOUWANTTORUN"
.FindById("wnd[0]").SendVKey 0
'...
'etc
'...
End With
Application.DisplayAlerts = True
MsgBox "After clicking OK, this SAP session is terminated."
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.