Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
One month ago I present here the possibility to use the Scripting Language AutoIt via a runtime environment (RTE) from the application server. Here now an example how to restart the SAP Logon on the presentation server from an ABAP program and after the restart the ABAP program will execute again.

Here the ABAP program which provides the AutoItRTE on the frontend server and starts the script.

 
"-Begin------------------------------------------------------------------
Program ZRESTARTSAPLOGON.

"-Variables---------------------------------------------------------
Data:
lo_AutoIt Type Ref To ZCL_AUTOIT,
lv_WorkDir Type String,
lv_Str Type String
.

"-Main--------------------------------------------------------------
Try.
Create Object lo_AutoIt.
lv_Str = lo_AutoIt->GetClipBoard( ).
If lv_Str <> 'Restart SAP Logon successful'.
lo_AutoIt->ProvideRTE( i_DeleteExistRTE = ABAP_FALSE ).
lv_WorkDir = lo_AutoIt->GETWORKDIR( ).
lo_AutoIt->StoreInclAsFile( i_InclName = 'ZRESTARTSAPLOGONAU3'
i_FileName = lv_WorkDir && '\RestartSAPLogon.au3').
lo_AutoIt->Execute( i_FileName = 'RestartSAPLogon.au3'
i_WorkDir = lv_WorkDir ).
EndIf.
lo_AutoIt->PutClipBoard( '' ).
Write: / 'Restart successful'.
Catch cx_root.
Write: / 'An error occured'.
EndTry.

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

Here the AutoIt script which restarts the SAP Logon, reconnects the application server and restart the ABAP program. The most steps uses SAP GUI Scripting API.

 
;-Begin------------------------------------------------------------------

;-Sub RestartProcess--------------------------------------------------
Func RestartProcess($ProcessName)

$PID = ProcessExists($ProcessName)
If $PID Then
$oWMI = ObjGet("winmgmts:\\.\root\CIMV2")
If IsObj($oWMI) Then
$Process = $oWMI.ExecQuery("Select * From win32_process " & _
"Where Name = '" & $ProcessName & "'")
If IsObj($Process) Then
$ProcessPath = $Process.ItemIndex(0).ExecutablePath
EndIf
EndIf
ProcessClose($PID)
ProcessWait($PID)
Run($ProcessPath)
EndIf

EndFunc

;-Sub Main------------------------------------------------------------
Func Main()

RestartProcess("saplogon.exe")
WinWait("SAP Logon ")
Sleep(4096)
ClipPut("Restart SAP Logon successful")

$SAPROT = ObjCreate("SapROTWr.SAPROTWrapper")
If Not IsObj($SAPROT) Then
Exit
EndIf

$SapGuiAuto = $SAPROT.GetROTEntry("SAPGUI")
If Not IsObj($SapGuiAuto) Then
Exit
EndIf

$application = $SapGuiAuto.GetScriptingEngine()
If Not IsObj($application) Then
Exit
EndIf

$connection = $application.Openconnection("NSP", True)
If Not IsObj($connection) Then
Exit
EndIf

$session = $connection.Children(0)
If Not IsObj($session) Then
Exit
EndIf

$session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "BCUSER"
$session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = InputBox("Password", "Enter your password", "", "*")
$session.findById("wnd[0]").sendVKey(0)
$session.findById("wnd[0]/tbar[0]/okcd").text = "/nse38"
$session.findById("wnd[0]").sendVKey(0)
$session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "ZRESTARTSAPLOGON"
$session.findById("wnd[0]").sendVKey(8)

EndFunc

;-Main----------------------------------------------------------------
Main()

;-End--------------------------------------------------------------------

The interprocess communication between the AutoIt script and the ABAP program is via clipboard. All necessary modules are available on the application server. As you can see, with the combination of ABAP, AutoIt and SAP GUI Scripting you can create amazing solutions.