cancel
Showing results for 
Search instead for 
Did you mean: 

The control could not be found by id

Former Member
0 Kudos

Hi all,

I'm new to VBscripts and I'm trying to develop a script that allows a user to enter a specific date, then SAP can pull the data for the user. But when I run the code, it stops at line 51 (in bold). Thank you in advance, I'm really looking forward to your ideas!

dim shell1

set shell1=createobject("wscript.shell")

errTrap = shell1.run("\\ihnph3\Auto_Scripts\Task_Batch\Close_SAP.vbs", 1, True)

set shell1=nothing

WScript.Sleep 5000

set WshShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe") Then

  Set proc = WshShell.Exec("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe")

ElseIf objFSO.FileExists("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe") Then

  Set proc = WshShell.Exec("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")

Else

  WScript.Quit

End If

WScript.Sleep 5000

WshShell.SendKeys "{ENTER}"

WScript.Sleep 6000

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

'OpenConnection("Daily_Scrap_Job [PUBLIC]", True)

If IsObject(WScript) Then

   WScript.ConnectObject session,     "on"

   WScript.ConnectObject application, "on"

End If

dtmFirstDay = InputBox("Enter the date you wish to view. (MM/dd/yyyy)", "Scrap Date")

dtmLastDay = dtmFirstDay

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "zfi340"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[2]").Select

session.findById("wnd[0]/tbar[1]/btn[17]").press

session.findById("wnd[1]/tbar[0]/btn[8]").press

session.findById("wnd[0]/usr/ctxtSP$00005-LOW").text = dtmFirstDay

session.findById("wnd[0]/usr/ctxtSP$00005-HIGH").text = dtmLastDay

session.findById("wnd[0]/usr/ctxtSP$00005-HIGH").setFocus

session.findById("wnd[0]/usr/ctxtSP$00005-HIGH").caretPosition = 6

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[1]/btn[8]").press

session.findById("wnd[0]/tbar[1]/btn[45]").press

session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select

session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[1]/usr/ctxtDY_PATH").text = "\\ihnph3\nphsaplive"

session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "US14_Daily_Scrap.txt"

session.findById("wnd[1]/usr/ctxtDY_FILE_ENCODING").setFocus

session.findById("wnd[1]/usr/ctxtDY_FILE_ENCODING").caretPosition = 0

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

session.findById("wnd[0]/tbar[0]/btn[3]").press

session.findById("wnd[0]/tbar[0]/btn[3]").press

session.findById("wnd[0]").resizeWorkingPane 139,27,false

session.findById("wnd[0]/tbar[0]/okcd").text = "KSB1"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").text = "1000"

session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").caretPosition = 4

session.findById("wnd[1]").sendVKey 0

session.findById("wnd[0]/tbar[1]/btn[17]").press

session.findById("wnd[1]/tbar[0]/btn[8]").press

session.findById("wnd[0]/usr/ctxtR_BUDAT-LOW").text = dtmFirstDay

session.findById("wnd[0]/usr/ctxtR_BUDAT-HIGH").text = dtmLastDay

session.findById("wnd[0]/usr/ctxtR_BUDAT-HIGH").setFocus

session.findById("wnd[0]/usr/ctxtR_BUDAT-HIGH").caretPosition = 6

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[1]/btn[8]").press

'Check for error'

If Session.findById("wnd[0]/sbar/pane[0]").Text = "No actual line items were selected" Then

Dim objFSO

Dim objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("\\ihnph3\nphsaplive\US14_Daily_Scrap_2.txt", 2, True)

objFile.WriteLine("")

Else

session.findById("wnd[0]/tbar[1]/btn[45]").press

session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select

session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[1]/usr/ctxtDY_PATH").text = "\\ihnph3\nphsaplive"

session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "US14_Daily_Scrap_2.txt"

session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 22

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

session.findById("wnd[0]/tbar[0]/btn[3]").press

session.findById("wnd[1]/usr/btnSPOP-OPTION1").press

End If

session.findById("wnd[0]/tbar[0]/btn[3]").press

WshShell.SendKeys "%{F4}"

WScript.Sleep 2000

WshShell.SendKeys "{TAB}{ENTER}"

WScript.Sleep 2000

WshShell.SendKeys "%{F4}"

dim shell

set shell=createobject("wscript.shell")

errTrap = shell.run("\\ihnph3\Auto_Scripts\SQL_Batch\Daily_Scrap_Job.bat", 1, True)

set shell=nothing

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Kurt,

welcome in this Forum and the SAP GUI Scripting.

It is a little bit difficult to help you, because you are using an individual TAC zfi340.

However, you can use Scripting Tracker to analyze your GUI objects. On this way you can easily find out, whether the object exists.

Cheers

Stefan

Answers (2)

Answers (2)

Former Member
0 Kudos

Script man, Stefan:

Thank you both very much! I'm going to try your approaches right now and see what I can get. Now when I did run this script, I have a warning that displays at the bottom of SAP that says "No user exists with SNC name "..." Do you think this could contribute to the error as well? Or is it unrelated? Thank you again for your help!

Best,

Kurt

script_man
Active Contributor
0 Kudos

Please see the following link: 

Regards,

ScriptMan

stefan_schnell
Active Contributor
0 Kudos

Hello Kurt,

perhaps the following information can help you:

Cheers

Stefan

script_man
Active Contributor
0 Kudos

Hi Kurt,

You can try also the following:

. . .

wscript.sleep 1000

session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[2]").Select

. . .

Regards,

ScriptMan