Skip to Content
0
Jan 24, 2019 at 09:30 PM

SAP Script Help

547 Views

Hi just as a form of introduction I'm not an SAP developer or scripting expert. I do know how to record scripts via the SAP GUI scripting though.

Currently I have recorded a script that downloads table data. My issue is that it only works when I run it and I need to have it work for anyone with access to z_tabu_dis and the related tables.

I believe the issue to be in the indented part of the code. It is my understanding that this part (indented) is selecting the fields based on their location relative to my screen. I would like to update that so that I can specifically reference the fields by their technical name preferably.

Thank you!

Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
  Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
  Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
  Set session = SAPCon.Children(0) 'Get the first session (window) on that connection


session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "z_TABU_DIS"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtP_TAB").Text = "SKB1"
session.findById("wnd[0]/usr/ctxtP_TAB").caretPosition = 4
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/ctxtI1-LOW").Text = "0001"
session.findById("wnd[0]/usr/ctxtI1-HIGH").Text = "9999"
session.findById("wnd[0]/usr/ctxtI2-LOW").Text = "00115787"
session.findById("wnd[0]/usr/ctxtI2-HIGH").Text = "88005014"
session.findById("wnd[0]/usr/ctxtI2-HIGH").SetFocus
session.findById("wnd[0]/usr/ctxtI2-HIGH").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
	session.findById("wnd[0]/mbar/menu[3]/menu[0]/menu[1]").Select
	session.findById("wnd[1]/usr").verticalScrollbar.Position = 0
	session.findById("wnd[1]/tbar[0]/btn[14]").press
	session.findById("wnd[1]/usr/chk[1,3]").Selected = True 'MANDT Client
	session.findById("wnd[1]/usr/chk[1,4]").Selected = True 'BUKRS Company Code
	session.findById("wnd[1]/usr/chk[1,5]").Selected = True 'SAKNR G/L Account
	session.findById("wnd[1]/usr/chk[1,9]").Selected = True 'ERDAT Created on
	session.findById("wnd[1]/usr/chk[1,10]").Selected = True 'ERNAM Created by
	session.findById("wnd[1]/usr/chk[1,18]").Selected = True
session.findById("wnd[1]/usr/chk[1,18]").SetFocus
session.findById("wnd[1]/usr").verticalScrollbar.Position = 1
session.findById("wnd[1]/usr").verticalScrollbar.Position = 2
session.findById("wnd[1]/usr").verticalScrollbar.Position = 3
session.findById("wnd[1]/usr").verticalScrollbar.Position = 4
session.findById("wnd[1]/usr").verticalScrollbar.Position = 5
        session.findById("wnd[1]/usr/chk[1,20]").Selected = True 'XINTB Post automatically only
        session.findById("wnd[1]/usr/chk[1,20]").SetFocus
session.findById("wnd[1]/usr").verticalScrollbar.Position = 6
session.findById("wnd[1]/usr").verticalScrollbar.Position = 7
session.findById("wnd[1]/usr").verticalScrollbar.Position = 8
session.findById("wnd[1]/usr").verticalScrollbar.Position = 9
session.findById("wnd[1]/usr").verticalScrollbar.Position = 10
session.findById("wnd[1]/usr/chk[1,20]").Selected = True 'XSPEB Blocked for posting
session.findById("wnd[1]/usr/chk[1,20]").SetFocus
session.findById("wnd[1]/tbar[0]/btn[6]").press
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]").sendVKey 45
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "\\PATH\...\"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "SKB1_GUI_EXTRACT.txt"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 16