SAP Jobsuche bei DV-Treff


Suchen
SAP-Claudi
vor 6 Jahre
Hallo Scriptman, hallo in die Runde,

ich habe in Access ein Tool entwickelt, das Dateien in ein bestimmtes Format konvertiert damit sie in SAP eingelesen werden können (FB01-Buchungen). Nun möchte ich in einer Art Jobmonitor aus VBA heraus die Möglichkeit haben, direkt in die Batch-Input-Verarbeitung in SAP zu springen.

Dazu habe ich folgenden Code in Access:

********************

Sub SapGui()

Dim oSapGui As Object

Dim oApp As SAPFEWSELib.GuiApplication

Dim oConn As SAPFEWSELib.GuiConnection

Dim oSession As SAPFEWSELib.GuiSession

Set oSapGui = GetObject("SAPGUI")

If IsObject(oSapGui) Then

Set oApp = oSapGui.GetScriptingEngine

If IsObject(oApp) Then

Set oConn = oApp.OpenConnection("....", False)

If IsObject(oConn) Then

' 1. Session der Connection

Set oSession = oConn.Children(0)

oSession.FindById("wnd[0]/usr/txtRSYST-BNAME").Text = "....."

oSession.FindById("wnd[0]/usr/pwdRSYST-BCODE").Text = "....."

oSession.FindById("wnd[0]").SendVKey 0

oSession.StartTransaction ("SM35")

End If

End If

End If

Set oSession = Nothing

Set oConn = Nothing

Set oApp = Nothing

Set oSapGui = Nothing

End Sub

************************

Das funktioniert auch, nur gibt es 2 Probleme:

1. Ich hätte gerne, dass sich das Skript "dunkel" anmeldet, d.h. die Zwischendynpros nicht sichtbar sind.

2. Wie realisiere ich, dass bei schon angemeldetem Benutzer nicht nochmal das Anmeldefenster durchlaufen wird ?

Vielen Dank schonmal vorab für die Lösung, denn ich bin mir sicher, Scriptman hat da was auf Lager 🙂...Ich hab auch schon das Forum durchsucht, aber leider nichts passendes gefunden...

sap_claudi

Förderer

ScriptMan
vor 6 Jahre
Hallo SAP-Claudi,

wie sollte ich da stehen, wenn ich nach dieser Ankündigung von dir passen müsste? Unvorstellbar! ;-)

1. Ich hätte gerne, dass sich das Skript "dunkel" anmeldet, d.h. die Zwischendynpros nicht sichtbar sind.

Das geht im SAP GUI Scripting nicht 100%-ig auf. Ein kurzeitiges Aufflackern ist nicht ganz zu vermeiden. Die SAP-Session wird einfach in die Taskleiste geschickt. Statt maximize oder überhaupt muss iconify verwendet werden.

2. Wie realisiere ich, dass bei schon angemeldetem Benutzer nicht nochmal das Anmeldefenster durchlaufen wird ?

In dem man sich an einer richtigen Stelle im Script/ VBA davon überzeugt.

Deine VBA-Anmeldung funktioniert nur, wenn das SAP Logon - Fenster (saplogon.exe) bereits aktiv ist. Ist das nicht der Fall, erscheint bei dir ein Fehler. Daher kommt an dieser Stelle auch noch eine zusätzliche Erweiterung von mir, sozusagen als Bonus. :-)

Sub SapGui()

Dim oSapGui As Object

Dim oApp As SAPFEWSELib.GuiApplication

Dim oConn As SAPFEWSELib.GuiConnection

Dim oSession As SAPFEWSELib.GuiSession

Set wshell = CreateObject("Wscript.Shell")

On Error Resume Next

Set oSapGui = GetObject("SAPGUI")

Set oApp = oSapGui.GetScriptingEngine

myError = Err.Number

On Error GoTo 0

If myError <> 0 Then

wshell.Run Chr(34) & "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe" & Chr(34), 6, False

Application.Wait (Now + TimeValue("00:00:04"))

myError = 0

On Error Resume Next

Set oSapGui = GetObject("SAPGUI")

Set oApp = oSapGui.GetScriptingEngine

myError = Err.Number

On Error GoTo 0

If myError <> 0 Then

MsgBox "SAP Logon ist nicht installiert.", vbInformation

End If

End If

On Error Resume Next

Set oConn = oApp.Children(0)

myError = Err.Number

' 1. Session der Connection

Set oSession = oConn.Children(0)

myError = Err.Number

On Error GoTo 0

If myError <> 0 Then

Set oConn = oApp.OpenConnection("...", False)

Set oSession = oConn.Children(0)

oSession.findById("wnd[0]").iconify

'oSession.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "..."

oSession.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "..."

oSession.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "..."

oSession.findById("wnd[0]").SendVKey 0

oSession.StartTransaction ("SM35")

Else

MsgBox "Sie sind bereits in SAP angemeldet.", vbInformation, "SAP - Anmeldung"

End If

Set oSession = Nothing

Set oConn = Nothing

Set oApp = Nothing

Set oSapGui = Nothing

End Sub

Grüße,

ScriptMan

SAP-Claudi
vor 6 Jahre
Guten Morgen Scriptman,

was soll ich sagen....DANKE !!!!!😍

Ich werds gleich mal einbauen !

Viele Grüße,

sap_claudi