cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Scripting and Recording

Former Member
0 Kudos

Hello,

I am trying to complete a repetitive task.  I am going into transaction SP01.  I want to add column 'output device'.  I also want to filter so that any jobs with status of 'Print.', 'Proc.', 'Waiting', and ' <F5>' are filtered out.  The script works when all 4 of those statuses are present in the search but when one isn't I receive the error "The control could not be found by id."  Is there anyway around this?  Not all SP01 searches yield all 4 statuses but I want them to be filtered permanently.  Below is my current script.

Thanks!

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_schnell
Active Contributor
0 Kudos

Hello Andrew,

welcome to the Scripting Language forum.

You can try this to check the existence of a control:


'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------

    Option Explicit

  '-Global Variables----------------------------------------------------

    Dim SapGuiAuto, application, connection, session

  '-Function Check------------------------------------------------------

    Function Check(ByVal Ctrl)

      Dim Result

      On Error Resume Next

      session.findById(Ctrl)

      If Err.Number <> 0 Then

        Result = vbFalse

      Else

        Result = vbTrue

      End If

      On Error Goto 0

      Err.Clear

      Check = Result

    End Function

  '-Main----------------------------------------------------------------

    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 Check("wnd[2]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL-SLOW_E[1,0]") Then

      session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL-SLOW_E[1,0]").text = "Proc."

    End If

    If Check("wnd[2]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL-SLOW_E[1,1]") Then

      session.findById("wnd[2]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL-SLOW_E[1,1]").text = "Waiting"

    End If

'-End-------------------------------------------------------------------

The function Check try to call the ID and if the ID exists the function delivers true, otherwise false. So you have the possiblity to check the existence before you set the text. The On Error Resume Next command disables the error message box and the On Error Goto 0 enables it.

Let us know your results.

Cheers

Stefan

Former Member
0 Kudos

Programatically you could use on error resume next so that if the control is not found the script will carry on, regardless

if possible with SP01 a simpler solution would be to just use a selection screen variant  and layout variant to achieve the same effect.