SAP Jobsuche bei DV-Treff


Suchen
SAP-Claudi
vor 5 Jahre
Hallo lieber Scriptman !

In "meinem" Access-Tool bin ich dabei ein "Batchreporting" zu realisieren bei dem hintereinander mehrere Transaktionen mit benutzereingenen Vorgaben in SAP mittels SAP-Scripting abgerufen werden.

Nun eine Frage zur VBA-Technik: Mein Gedanke war, innerhalb des "Grundgerüstes", d.h. Öffnen der SAP-Session, pro Transaktion ein Sub oder Function aufzurufen mit den Variablen Transaktion, Variante etc.

Wie muß ich dann die Objecte deklarieren, damit ich sie auch in der Function verwenden kann ?

Wahrscheinlich hab ich mich nicht ganz verständlich ausgedrückt daher hier ein Auszug aus dem Code:

'************

Public Function SAPGUI......

'**************************************************************************

' Voraussetzung soll momentan sein, dass der User im SAP angemeldet ist ***

'**************************************************************************

Dim oSapGui As Object

Dim oApp As SAPFEWSELib.GuiApplication

Dim oConn As SAPFEWSELib.GuiConnection

Dim oSession As SAPFEWSELib.GuiSession

Dim wshell As Object

Dim myError As String

Set wshell = CreateObject("Wscript.Shell")

On Error Resume Next

' Ref auf SAPGUI

Set oSapGui = GetObject("SAPGUI")

Set oApp = oSapGui.GetScriptingEngine '

myError = Err.Number

If myError <> 0 Then

MsgBox "Bitte erst SAPLogon öffnen !", , "Information"

GoTo ExitFunction

End If

Set oConn = oApp.Children(0)

myError = Err.Number

If myError <> 0 Then

MsgBox "Bitte erst in SAP anmelden !", , "Information"

GoTo ExitFunction

End If

' 1. Session der Connection

Set oSession = oConn.Children(0)

myError = Err.Number

If myError <> 0 Then

MsgBox "Bitte erst in SAP anmelden !", , "Information"

GoTo ExitFunction

End If

'Aufruf Skript

Select Case sTcode

Case Is = "FBL1N"

Call Script_FBL1N(sTcode, sBeschreibung, sVar, sLayout, sStidat)

Case Is = "XYZ"

'Call Script_XYZ

Case Else

End Select

....

Im Call Script_FBL1N soll dann das eigentliche Script stehen, das aber so im Moment nicht funktioniert:

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

oSession.FindById("wnd[0]/tbar[0]/okcd").Text = "/n" & sTcode

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

oSession.FindById("wnd[0]/tbar[1]/btn[17]").Press

oSession.FindById("wnd[1]/usr/txtV-LOW").Text = sVar

oSession.FindById("wnd[1]/usr/txtENAME-LOW").Text = ""

oSession.FindById("wnd[1]/usr/txtENAME-LOW").SetFocus

oSession.FindById("wnd[1]/usr/txtENAME-LOW").CaretPosition = 0

oSession.FindById("wnd[1]/tbar[0]/btn[8]").Press

oSession.FindById("wnd[0]/tbar[1]/btn[16]").Press

oSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/ssubSUBSCREEN_CONTAINER:SAPLSSEL:1106/btn%_%%DYN006_%_APP_%-VALU_PUSH").Press

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL").Select

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL/ssubSCREEN_HEADER:SAPLALDB:3020/tblSAPLALDBINTERVAL/ctxtRSCSEL_255-IHIGH_I[2,0]").Text = sStidat

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL/ssubSCREEN_HEADER:SAPLALDB:3020/tblSAPLALDBINTERVAL/ctxtRSCSEL_255-IHIGH_I[2,0]").SetFocus

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL/ssubSCREEN_HEADER:SAPLALDB:3020/tblSAPLALDBINTERVAL/ctxtRSCSEL_255-IHIGH_I[2,0]").CaretPosition = 10

oSession.FindById("wnd[1]/tbar[0]/btn[8]").Press

oSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/ssubSUBSCREEN_CONTAINER:SAPLSSEL:1106/btn%_%%DYN007_%_APP_%-VALU_PUSH").Press

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL").Select

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL/ssubSCREEN_HEADER:SAPLALDB:3020/tblSAPLALDBINTERVAL/ctxtRSCSEL_255-IHIGH_I[2,0]").Text = sStidat

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL/ssubSCREEN_HEADER:SAPLALDB:3020/tblSAPLALDBINTERVAL/ctxtRSCSEL_255-IHIGH_I[2,0]").SetFocus

oSession.FindById("wnd[1]/usr/tabsTAB_STRIP/tabpINTL/ssubSCREEN_HEADER:SAPLALDB:3020/tblSAPLALDBINTERVAL/ctxtRSCSEL_255-IHIGH_I[2,0]").CaretPosition = 6

oSession.FindById("wnd[1]/tbar[0]/btn[8]").Press

oSession.FindById("wnd[0]/usr/ctxtPA_VARI").Text = sLayout

oSession.FindById("wnd[0]/usr/ctxtPA_VARI").SetFocus

oSession.FindById("wnd[0]/usr/ctxtPA_VARI").CaretPosition = 12

'oSession.FindById("wnd[0]/tbar[1]/btn[8]").Press

'oSession.FindById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select

'im Hintergrund ausführen

oSession.FindById("wnd[0]/mbar/menu[0]/menu[2]").Select

oSession.FindById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/cmbPRIPAR_DYN-PRIMM2").SetFocus

oSession.FindById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/cmbPRIPAR_DYN-PRIMM2").Key = ""

oSession.FindById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/txtPRI_PARAMS-PRTXT").Text = sBeschreibung

oSession.FindById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/txtPRI_PARAMS-PRTXT").SetFocus

oSession.FindById("wnd[1]/usr/subSUBSCREEN:SAPLSPRI:0600/txtPRI_PARAMS-PRTXT").CaretPosition = 13

oSession.FindById("wnd[1]/tbar[0]/btn[13]").Press

oSession.FindById("wnd[1]/usr/btnSOFORT_PUSH").Press

oSession.FindById("wnd[1]/tbar[0]/btn[11]").Press

Ich danke Dir schonmal !!!

Liebe Grüße,

sap_claudi

Förderer

SAP-Claudi
vor 5 Jahre
Hat sich erledigt !!!!

Ich muß das gesamte Object oSession by val übergeben - es funktioniert !!

ScriptMan
vor 5 Jahre
Hallo SAP-Claudi,

wie man sieht, du konntest dir selbst helfen. In "meinem" VBA-Projekt im Excel habe eine ähnliche Konstellation mit

Public oSession as Object

gelöst.

Grüße,

ScriptMan