Skip to Content

Hello community,

since Windows Scripting Host (WSH) 2.0 offers Microsoft with the Windows Script File (WSF) the possibility to combine different scripting languages in one script file. The WSF files containes an Extensible Markup Language (XML) structure with one package tag and different job tags. Below the job tag we can define different script sections with different scripting languages. Here an easy exmaple how to combine VBScript and JScript:

<?xml version="1.0" standalone="yes"?>
<package id="test">
  <comment>
    This is a test script
  </comment>
  <job id="001">

    <runtime>
      <description>
        This script shows the using of VBScript and JScript in one
        script file
      </description>
      <example>
        wscript Test.wsf
      </example>
    </runtime>

    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

  function JSHelloWorld() {
    return("Hello World from JScript");
  }

//-End------------------------------------------------------------------
      ]]>
    </script>

    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

  MsgBox "Hello World from VBScript"
  MsgBox JSHelloWorld()

'-End-------------------------------------------------------------------
      ]]>
    </script>

  </job>
</package>

Now an example how to use the shift operators from JScript inside VBScript:

<?xml version="1.0" standalone="yes"?>
<package id="shift">
  <comment>
    This is a test script
  </comment>
  <job id="001">

    <runtime>
      <description>
        This script shows the using of JScript shift operators with
        VBScript
      </description>
      <example>
        wscript Shift.wsf
      </example>
    </runtime>

    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

  function ShiftLeft(Value, Shift) {

    //-Variables--------------------------------------------------------
      var Result;

    Result = Value << Shift
    return(Result);
  }

  function ShiftRight(Value, Shift) {

    //-Variables--------------------------------------------------------
      var Result;

    Result = Value >> Shift
    return(Result);
  }

//-End------------------------------------------------------------------
      ]]>
    </script>

    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

  MsgBox CStr(ShiftLeft(14, 2))                 '1110 << 2 = 111000 (56)
  MsgBox CStr(ShiftRight(14, 2))                '1110 >> 2 =     11 ( 3)

'-End-------------------------------------------------------------------
      ]]>
    </script>

  </job>
</package>

It is also possible to implement your SAP GUI script, from the SAP GUI Scripting recorder, inside the VBScript section and to combine it with a JScript section too.

<?xml version="1.0" standalone="yes"?>
<package id="test">
  <comment>
    This is a test script
  </comment>
  <job id="001">

    <runtime>
      <description>
        This script shows the using of SAP GUI Scripting as VBScript
        and JScript in one script file
      </description>
      <example>
        wscript SAPGUIScript.wsf
      </example>
    </runtime>

    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

  function getJScriptEngine() {
    return ScriptEngine();
  }

//-End------------------------------------------------------------------
      ]]>
    </script>

    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

  MsgBox ScriptEngine()

  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]/usr/txtRSYST-MANDT").text = "001"
  session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "bcuser"
  session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "minisap"
  session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "EN"
  session.findById("wnd[0]").sendVKey 0

  MsgBox getJScriptEngine()

'-End-------------------------------------------------------------------
      ]]>
    </script>

  </job>
</package>

 

On this way you can use different Active Scripting Engines with SAP GUI Scripting. So you can mix, beside VBScript and JScript, e.g. Python with Windows Extensions , PerlScript or OOREXX (use version 3.20). You can use the best from each scripting language. And you have the possibility to use great archives from a few scripting languages. Use existing and consolidated solutions, it is often not necessary to invent the wheel again.

Cheers
Stefan

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply