Skip to Content

If you connect a SAP GUI for Windows session via the SAP GUI Scripting API a little barber pole begins to rotate on the lower right side of the window. This signalizes that this session is busy with a SAP GUI script.

It begins to rotate with the execution of the command

$session = Get-Property $connection "Children" @(0)

and it stops to rotate with the exectuion of the command

Free-Object $session

Here my test script:

#-Begin-----------------------------------------------------------------

  #-Includes------------------------------------------------------------
  ."$PSScriptRoot\COM.ps1"

  #-Main----------------------------------------------------------------
  $SapGuiAuto = Get-Object( , "SAPGUI")
  If ($SapGuiAuto -isnot [__ComObject]) {
    Exit
  }

  $application = Invoke-Method $SapGuiAuto "GetScriptingEngine"
  If ($application -isnot [__ComObject]) {
    Free-Object $SapGuiAuto
    Exit
  }

  $connection = Get-Property $application "Children" @(0)
  If ($connection -eq $Null) {
    Free-Object $application
    Free-Object $SapGuiAuto
    Exit
  }

  $session = Get-Property $connection "Children" @(0)
  If ($session -eq $Null) {
    Free-Object $connection
    Free-Object $application
    Free-Object $SapGuiAuto
    Exit
  }

  Throw [System.ApplicationException] "Error"

  Free-Object $session
  Free-Object $connection
  Free-Object $application
  Free-Object $SapGuiAuto

  #-Error routine-------------------------------------------------------
  Trap {
    Free-Object $session
    Free-Object $connection
    Free-Object $application
    Free-Object $SapGuiAuto
    Exit
  }

#-End-------------------------------------------------------------------

 

If you execute in the same session an ABAP report which calls the method IS_SCRIPTING_ACTIVE from the class CL_GUI_FRONTEND_SERVICES it delivers 1 if the barber pole rotates and 0 if doesn’t.

Here my test report:

"-Begin-----------------------------------------------------------------
REPORT zsapguiscript.

DATA:
  lg_result TYPE i
  .

lg_result = cl_gui_frontend_services=>is_scripting_active( ).

WRITE: lg_result.

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

So far so well, all as expected.

And now I throw an exception and the trap routine doesn’t frees the session object. Now the barber pole rotates for the rest of the window life. Also delivers the IS_SCRIPTING_ACTIVE method the result that scripting is active – but it is¬†definitely not. That is very irritating. It seems that the method IS_SCRIPTING_ACTIVE, which calls IsScriptingActive from the library sapfewin.ocx, only check if the barber pole is active or not.

It is very important to free the session object, on the one hand if the script terminates normal and on the other hand if the script terminates via an error. In this case the barber pole stops the rotating immediately.

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