"- Hint: It is necessary to disable the security rule for SAPROTWrapper
"-       in the SAP Logon, otherwise it is not allowed to create the
"-       object SapROTWr.SapROTWrapper.
"- Hint: You can not use the same session to execute this program
"-       and to record it via SAP GUI Scripting. Run this program e.g.
"-       in session 0 and record session 1.
Report zGUIScripting.

  Include OLE2INCL.

    ROTEntry Type OLE2_OBJECT,
    application Type OLE2_OBJECT,
    connections Type OLE2_OBJECT,
    connection Type OLE2_OBJECT,
    sessions Type OLE2_OBJECT,
    session Type OLE2_OBJECT.

  PerForm StartRecording Using 'SU01' 'TestScript.vbs'.

  Wait Up To 30 Seconds.

  PerForm StopRecording.


"-SubRoutines begin-----------------------------------------------------

Form StartRecording Using TAC Type String FileName Type String.

  Create Object SAPROT 'SapROTWr.SapROTWrapper'.
  Check sy-subrc Is Initial.

  Get Property Of SAPROT 'GetROTEntry' = ROTEntry
    Exporting #1 = 'SAPGUI'.
  Check sy-subrc Is Initial.

  Get Property Of ROTEntry 'GetScriptingEngine' = application.
  Check sy-subrc Is Initial.

  Get Property Of application 'Connections' = connections.
  Check sy-subrc Is Initial.

  "-Connection 0--------------------------------------------------------
  Call Method Of connections 'Item' = connection Exporting #1 = 0.
  Check sy-subrc Is Initial.

  Get Property Of connection 'Sessions' = sessions.
  Check sy-subrc Is Initial.

  "-Session 1-----------------------------------------------------------
  Call Method Of sessions 'Item' = session Exporting #1 = 1.
  Check sy-subrc Is Initial.

  "-Set file name-------------------------------------------------------
  "-  The file was stored in your SAP work directory
  Set Property Of session 'RecordFile' = FileName.
  "-Enable recording----------------------------------------------------
  Set Property Of session 'Record' = 1.
  "-Start transaction---------------------------------------------------
  Call Method Of session 'StartTransaction' Exporting #1 = TAC.


Form StopRecording.

  "-Disable recording---------------------------------------------------
  Set Property Of session 'Record' = 0.

  "-Frees all objects---------------------------------------------------
  If session Is Not Initial.
    Free Object session.
  If sessions Is Not Initial.
    Free Object sessions.
  If connection Is Not Initial.
    Free Object connection.
  If connections Is Not Initial.
    Free Object connections.
  If application Is Not Initial.
    Free Object application.
  If ROTEntry Is Not Initial.
    Free Object ROTEntry.
  If SAPROT Is Not Initial.
    Free Object SAPROT.


"-SubRoutines end-------------------------------------------------------