Wednesday, December 21, 2016

Using the Scripting Tracker

So here is a quick how to on the Scripting Tracker by Stefan Schnell. It is no long maintained unfortunately but still works well.


You can download the tracker here.

No need to install just download and extract the zip file. Then run Tracker.exe


Once you open your SAP session you can click the refresh button in the upper left of the scripting tracker window. It will populate the scripting objects from the currently open SAP GUI sessions.


You can now expand the node tree to see the various objects.

If you right click a scripting object from the tree it will be highlighted with a red box in the session.


You can then copy the ID or other info from the scripting tracker to use in your script.

There is also a recorder tab and a Scripting API tab that can be very helpful. The recorder is well a recorder just like the SAP builtin recorder. The Scripting API provides a list of available objects and methods and attributes in SAP for scripting. Note these are for VB and not Python so some syntax changes will be needed.

Also Stefan is not answer any questions related to the Scripting Tracker based on the site so I'd be happen to help in any way possible though I am by no means an expert. There also other tools available but Scripting Tracker is by far the best. You can also use the Script recorder built into SAP and then pull the objects from the vbs file.

Here is some sample code from those vbs recordings so you can compare with the Python code.

 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,25,false  
 session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"  
 session.findById("wnd[0]").sendVKey 0  
 session.findById("wnd[0]/usr/ctxtLIKP-VBELN").text = "xxxxxxxxxx"  
 session.findById("wnd[0]").sendVKey 0  
 session.findById("wnd[0]/tbar[1]/btn[18]").press  
 session.findById("wnd[0]/tbar[0]/btn[3]").press  
 session.findById("wnd[0]/tbar[1]/btn[8]").press  
 session.findById("wnd[0]/usr/lbl[1,1]").setFocus  
 session.findById("wnd[0]/usr/lbl[1,1]").caretPosition = 0  
 session.findById("wnd[0]/tbar[1]/btn[37]").press  
 session.findById("wnd[0]/mbar/menu[5]/menu[5]/menu[2]/menu[2]").select  
 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_FILENAME").text = "testexport.csv"  
 session.findById("wnd[1]/usr/ctxtDY_FILE_ENCODING").text = "4110"  
 session.findById("wnd[1]/usr/ctxtDY_FILE_ENCODING").setFocus  
 session.findById("wnd[1]/usr/ctxtDY_FILE_ENCODING").caretPosition = 4  
 session.findById("wnd[1]/tbar[0]/btn[11]").press  


3 comments:

  1. hi
    I have a question about Scripting Tracker, whene i open sap I notice that just the first page "SAP Logon Pad 730 is not recognized ?Thanks for your help

    ReplyDelete
  2. Hello,
    Many many thanks for your post.

    Could you please let me know how can we click on menu bar buttons on SAP logon with Python

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

    this gives error but works fine with VBA macro ...
    Any help would be deeply appreciated

    ReplyDelete