"-Begin-----------------------------------------------------------------
Report zVBScript.

Type-Pools OLE2.

Constants CrLf(2) Type c Value %_CR_LF.

Data:
  ScriptCtrl Type OLE2_OBJECT,
  Command Type String Value '',
  Line Type String Value '',
  Module Type String Value '',
  Result Type Integer.

Define AddLine.
  Concatenate Module &1 CrLf Into Module.
End-Of-Definition.

"-Main------------------------------------------------------------------
Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.

If sy-subrc = 0.

  "-Allow to display UI elements----------------------------------------
  Set Property Of ScriptCtrl 'AllowUI' = 1.

  "-Intialize the VBScript language-------------------------------------
  Set Property Of ScriptCtrl 'Language' = 'VBScript'.

  "---------------------------------------------------------------------
  "-
  "- Execution of a single VBScript command
  "-
  "---------------------------------------------------------------------
  Command = 'MsgBox "This is a test", vbOkOnly, "MessageBox"'.
  Call Method Of ScriptCtrl 'ExecuteStatement'
    Exporting #1 = Command.

  "---------------------------------------------------------------------
  "-
  "- Execution of a VBScript procedure
  "-
  "---------------------------------------------------------------------
  AddLine 'Sub foo()'.
  AddLine 'MsgBox "This is a test", vbOkOnly, "MessageBox"'.
  AddLine 'End Sub'.
  Call Method Of ScriptCtrl 'AddCode' Exporting #1 = Module.
  If sy-subrc = 0.
    Call Method Of ScriptCtrl 'Run' Exporting #1 = 'foo'.
  EndIf.

  "---------------------------------------------------------------------
  "-
  "- Execution of a VBScript function
  "-
  "---------------------------------------------------------------------
  Clear Module.
  AddLine 'Function foo2()'.
  AddLine 'foo2 = MsgBox("This is a test", vbOkCancel, "MessageBox")'.
  AddLine 'End Function'.
  Call Method Of ScriptCtrl 'AddCode' Exporting #1 = Module.
  If sy-subrc = 0.
    Call Method Of ScriptCtrl 'Eval' = Result
      Exporting #1 = 'foo2'.
    Write: / Result.
  EndIf.

  "---------------------------------------------------------------------
  "-
  "- Execution of a VBScript function with parameters
  "-
  "---------------------------------------------------------------------
  Clear Module.
  AddLine 'Function foo3(Text)'.
  AddLine 'foo3 = MsgBox("This is" & Text, vbOkCancel, "MessageBox")'.
  AddLine 'End Function'.
  Call Method Of ScriptCtrl 'AddCode' Exporting #1 = Module.
  If sy-subrc = 0.
    Call Method Of ScriptCtrl 'Eval' = Result
      Exporting #1 = 'foo3(" a test")'.
    Write: / Result.
  EndIf.

  "-Free the object-----------------------------------------------------
  Free Object ScriptCtrl.

EndIf.

"-End-------------------------------------------------------------------