Quantcast
Channel: SCN : Blog List - All Communities
Viewing all articles
Browse latest Browse all 2548

How to Restart SAP Logon From an ABAP Program

$
0
0

Hello community,

 

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.

       Data lv_WorkDir Type String.

       Data 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 = 'ZRESTARTSAPLOGON'

             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.

 

Enjoy it.

 

Cheers

Stefan


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>