cancel
Showing results for 
Search instead for 
Did you mean: 

Refreshing queries daily through Scripting

Isamu_Haynes
Newcomer
0 Kudos
189

Hello, 

I have created a script to run a query within SAP, but the script does not work until I go through the action itself. When I try to run the script without going through the action it gets stuck after loading into the SQ00, it's not able to select the query with the variant, it always returns "The control could not be found by ID".  I believe this has to do with refreshing the query, but I could not find a solution to refresh the query in these forums for my situation. 

My action is SQ00--ZINV_SCHD_CC_1 (query name)-- ZBER_CC_1 (variant)

This is the code that I am running, this is pulled straight from the script record within SAP. 

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]").maximize
session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00073"
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]").sendVKey 4
session.findById("wnd[2]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellColumn = "TEXT"
session.findById("wnd[2]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"
session.findById("wnd[2]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "Tag Download"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 12
session.findById("wnd[1]/tbar[0]/btn[11]").press
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").setCurrentCell 7,"LGTYP"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectedRows = "7"

 

So ideally I would like to come in each day run the script and have it refresh the query, run the query, then export to excel under the name "Tag Download"

If there is a post that has the solution to this please link it here.

Thank you,

 

Accepted Solutions (0)

Answers (0)