cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Use VBScript to Export Data From New Windows Using Dashboard

0 Kudos
1,269

My company uses a dashboard T-Code called Prometheus Navigator (T-Code: /PROGROUP/NAV), wherein I can assign specific T-Codes and Variants to run fully executed off an assigned command button. I am looking to take this one step further and automate the exporting of that data into Excel. Whenever a button is clicked, a new window/session is created. Running the SAP Script Record and Playback, the record always ends with

<session.findById("wnd[0]").resizeWorkingPane 88,16,false

session.findById("wnd[0]/usr/btnDASH_ALL-BO1-BU5-LABEL").press>

If I run a second script the long way, the code for exporting the data is recorded. However, when I combine the code, I get the "The control could not be found by id -" error message. Adding

<If Not IsObject(connection1) Then

Set connection1 = application.Children(0 + 1)

End If

If Not IsObject(session1) Then

Set session1 = connection1.Children(0 + 1)

End If>

before the export code, included with the original set codes, or any combination I can think of generates either the "The enumerator of the collection cannot find an element with the specified index -" or the "Object required: 'connection1' -"/ "Object required: session1' -" error message boxes.

It seems like my issue is how do I tell SAP to start running the script on the new session after the current session opens a new window?

Once I get that question answered, how can I identify specific sessions? My end goal is to have SAP trigger multiple sessions, export the data, the close that session.

Here is all of the script I am currently working with.

<If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.Children(0)

Set connection1 = application.Children(0 + 1)

End If

If Not IsObject(session) Then

Set session = connection.Children(0)

Set session1 = connection1.Children(0 + 1)

End If

If IsObject(WScript) Then

WScript.ConnectObject session, "on"

WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").resizeWorkingPane 88,16,false

session.findById("wnd[0]/usr/btnDASH_ALL-BO1-BU5-LABEL").press

If Not IsObject(session1) Then

Set session1 = connection1.Children(0 + 1)

End If

session1.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").select

session1.findById("wnd[1]/usr/ctxtDY_PATH").text = "Z:\Rebar Fab Planning\DSI & Inventory Data Dumps"

session1.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "Inventory - MB52.XLSX"

session1.findById("wnd[1]/usr/ctxtDY_PATH").setFocus

session1.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 48

session1.findById("wnd[1]/tbar[0]/btn[11]").press>

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

In order not to make it too complicated at the beginning, I would first consider only two consecutive sessions.

for example:

If Not IsObject(application) Then
   Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If

If Not IsObject(connection) Then
Set connection = application.Children(0)
End If

If Not IsObject(session) Then
Set session = connection.Children(0)
End If

If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").resizeWorkingPane 88,16,false
session.findById("wnd[0]/usr/btnDASH_ALL-BO1-BU5-LABEL").press
wscript.sleep 4000 '4 seconds wait for a new session
Set session = connection.Children(0 + 1)
session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").select
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "Z:\Rebar Fab Planning\DSI & Inventory Data Dumps"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "Inventory - MB52.XLSX" 'unnecessary
'session.findById("wnd[1]/usr/ctxtDY_PATH").setFocus
'session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 48 session.findById("wnd[1]/tbar[0]/btn[11]").press>

In a further step, it could be expanded to include any number of sessions.

Regards, ScriptMan

0 Kudos

Thank you very much. A couple odd things have happened. If I try running the code with SAP's Playback, I get an error message box asking for the Object "WScript". However, if I double click the file while in File Explorer, it works perfectly. Do you understand what is happening here?

script_man
Active Contributor
In this case I only know of one workaround. Instead of a direct call from the wscript.sleep command, a following construction is used.

for example:

...

set wshell = CreateObject("Wscript.Shell")

wshell.run "c:\tmp\sleep_4000.vbs",1,true

...

sleep_4000.vbs in c:\tmp 'This VB script only contains a single line.

wscript.sleep 4000

After that, it should work in both cases.

Regards, ScriptMan

0 Kudos

Thank you very much for all your help. Would by chance also know how to close the exported files, or, even better, prevent them from opening in the first place? I'm going to create a new post with the question more in depth.