Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
0 Kudos


There are several ways to execute an SAP GUI script:

  1. Via SAP GUI recorder, press Alt+F12, now choose the menu item Script Recording and Playback, load the script file and press Playback button.

  2. Via Drag'n'Drop with the script file to the session where the script should be executed.

  3. Via double click on the script file in the Windows Explorer.

  4. Via the command line in a console window with the command wscript.exe or cscript.exe and the name of the script file.


This are four ways but technically this are only two ways. One and two works technically equal, also as three and four.

One and two executes the script via MSScriptControl. This means that the SAP GUI for Windows instanciate the class MSScriptControl.ScriptControl from the msscript.ocx library and executes the SAP GUI Script as statement - I think.

To check it out I create the following test script:
'-Begin-----------------------------------------------------------------

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

session.findById("wnd[0]/tbar[0]/okcd").text = "/nSE16"
session.findById("wnd[0]/tbar[0]/btn[0]").press

WScript.Sleep 500
WScript.Echo "Test"

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

 

The reaction with one and two are



To see reaction in a simulated context of SAP GUI for Windows I create the following test script:
'-Begin-----------------------------------------------------------------

'-Directives----------------------------------------------------------
Option Explicit

'-Variables-----------------------------------------------------------
Dim ScrCtrl, Cmd

'-Main----------------------------------------------------------------
Set ScrCtrl = CreateObject("MSScriptControl.ScriptControl")
If IsObject(ScrCtrl) Then

ScrCtrl.AllowUI = vbTrue
ScrCtrl.Language = "VBScript"

Cmd = "WScript.Echo ""Hello World"""
ScrCtrl.ExecuteStatement Cmd

End If

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

 

The reaction is the same as one and two

 



This knowledge gives us now a good base to understand the behaviour of the different executions forms better. On the one hand via MSScriptControl, on the other hand via WScript.

Hint: If you work with WScript you must define the connection (application.Children(x)) and session (connection.Children(y)) with correct values - here x and y as example. The standard defines always 0 - which means connection 0 and session 0, the first connection and session in the pool of all open connections and sessions.

Labels in this area