Skip to Content

Hello community,

AutoIt is a powerful freeware scripting language with BASIC syntax. It is primarly designed for automating operations on the Windows GUI. But it also provides a full set of commands to use it as programming language. It is possible to build GUI applications and to create standalone executables. You find AutoIt here.

AutoIt offers, beside the ability to use DLL calls, a COM interface. With these interface it is possible to use SAP GUI Scripting inside AutoIt. You can take the code from the SAP GUI Scripting recorder, it only has a $ sign before the session variable to be set.

Here an AutoIt Script example to login:

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

  ;-Variables-----------------------------------------------------------
    Dim $SAPROT, $SapGuiAuto, $application, $connection, $session

  $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.Children(0)
  If Not IsObj($connection) Then
    Exit
  EndIf

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

$session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "099"
$session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Hugo"
$session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "Bambi"
$session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "DE"
$session.findById("wnd[0]/tbar[0]/btn[0]").press()

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

2016/11/25: Here an addition how to use AutoIt and SAP GUI Scripting without the ROT wrapper.

Good scripting.

Cheers
Stefan

To report this post you need to login first.

21 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    Hi Stefan and Mic,

    I tried to use the above script example script but when I run it it pops up a window saying that “A script is trying to attach to the GUI” and that’s it..nothing happen.

    can you help?

    thanks

    (0) 
    1. Stefan Schnell Post author

      Hello Adelina,

      sure. Open your SAP Logon, go to the system menu and open the menu item “Options…”. Open the node “Accessibility & Scripting” and then the node “Scripting”. On the right side you see “Installation” and below “Scripting is installed” and below the “User Settings”. Enable the check box “Enable Scripting” and disable the check boxes “Notify when a script attaches to SAP GUI” and “Notify when a script opens a connection”. If you disable the check boxes no requester will come up when you executes a script. Try it and tell us your results.

      The AutoIt example script below connects an open session with a logon screen. To execute the script successful close all SAP connections and open only one with the logon screen (connection = 0 and session = 0). If you execute the script, it fills the client, user, password and language field and try to logon – but I think without success, because the values are made-up.

      Good luck, cheers

      Stefan

      (0) 
      1. Former Member

        Hi Stefan,

        thank you so much for your help. It worked. Now I have another question and wondering if you know.

        I need to automate the whole process from openning sapgui and run a transaction on sap easy access.

        I found commandline options where I can use either sapgui.exe or sapshcut.exe to make a connection and specify which transaction to run. Then from there I can use Autoit to send in the key to complete the test.

        my issue is that, when running sapgui.exe and sapshcut to make connection for the first time, it has the security dialog box pops up where it will ask if user allow that action. I monitor the process and notice it edit a xml file called “saprules.xml” I tried to play with it but it seems that that’s not the only place I should be edit to make the rules to work.

        I need to do all this using script and so if you know how to manipulate the sap rules remotely. Please let me know.

        thanks

        Adelina

        (0) 
          1. Former Member

            Thanks Stefan, There were 2 registry keys that needs to be created to supress the security dialog boxes.

            then you can simply start the connection without having to create connection in the saplogon.ini file and also can start the transaction with command line.

            But now I have another issue with the script to complete the sgen test.

            session.findById(“wnd[0]”).resizeWorkingPane 148,32,false

            session.findById(“wnd[0]/tbar[0]/okcd”).text = “sgen”

            session.findById(“wnd[0]”).sendVKey 0

            session.findById(“wnd[0]/usr/radINS”).select

            session.findById(“wnd[0]/usr/btnCONT”).press

            session.findById(“wnd[0]/usr/cntlCC0170/shellcont/shell”).currentCellColumn = “FLAG”

            session.findById(“wnd[0]/usr/cntlCC0170/shellcont/shell”).clickCurrentCell

            session.findById(“wnd[0]/usr/btnCONTINUE”).press

            session.findById(“wnd[0]/usr/btnCONTINUE”).press

            session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).currentCellColumn = “”

            session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).selectedRows = “0”

            session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton “RELEASE”

            session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton “RELEASE”

            I changed the last line to $session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton

            and to

            $session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton=’RELEASE”

            but Autoit is giving me the error

            SAPGUI_login.au3 (44) : ==> The requested action with this object has failed.:

            $session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton

            $session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton^ ERROR

            ->13:25:49 AutoIt3.exe ended.rc:1

            Do you know why?

            (0) 
            1. Stefan Schnell Post author

              Hello Adelina,

              unfortunately I can’t retrace your example completely, because I can’t execute the SAP Load Generator with any software component, so I can’t use the release button really. I hope you get any full support from another member.

              As far as I can see is the release button part of CC0100_1 control from screen 100 from report RSPARAGENJOBM. Hmm, I will try it…

              My Recorder from Scripting Tracker gets this result, though with an error message if I execute the script:

              $session.findById(“wnd[0]/usr/cntlCC0100_1/shellcont/shell”).pressToolbarButton(“RELEASE”)

              Try it and let us know the results.

              Cheers

              Stefan

              (0) 
  2. Former Member

    Hi Stefan,

    I found your post on AutoIT forum about the Script tracker ๐Ÿ™‚ very cool tool. I went thru the link the downloaded the script tracker lite. This version does not have recording in autoit right? is possible if I can download the full version with recording? ๐Ÿ™‚

    I also download the Bebo tool but not sure how to use both tools together.

    some help would be much appreciated.

    thank you

    -A

    (0) 
    1. Stefan Schnell Post author

      Hello Adelina,

      Bebo is tool to store activities and information in a well structured form. It contains your SAP knowledge like transaction codes, table names, function modules, reports etc. also as links to local files like PDF, Word etc. or in the WWW. Behind each entry in Bebo is an activity defined, e.g. the table name opens the table via SE16. Also you can integrate SAP GUI Scripting or any other script. Bebo offers possibilities for organized automatisation.

      Scripting Tracker is a tool for SAP GUI Scripting. You can analyze the SAP GUI and record your activities in different scripting languages like AutoIt, PowerShell and MiniRobot. Scripting Tracker extends the possibilities of SAP GUI Scripting.

      Bebo and Scripting Tracker goes hand in hand. With Scripting Tracker you generate the steps for automation, which you can use with Bebo.

      Hope this little overview shows the potentials.

      Cheers

      Stefan

      (0) 
      1. Former Member

        Hi Stefan,

        the Bebo that I downloaded asked for a password when I open the program. Which password should I put there?

        as for the Scripting Tracker, I downloaded the version available which is the lite version does not have recording mode. is that correct?

        thank you

        Adelina

        (0) 
        1. Stefan Schnell Post author

          Hello Adelina,

          the password for Bebo is only for your password collection in the Bebo.pwd.zip file. The standard password is test. If you press Abort button Bebo will work without password collection functionality.

          Scripting Tracker Lite is without the recording function. Scripting Tracker includes it.

          Cheers

          Stefan

          (0) 
  3. Former Member

    Hi Stefan,

    I used your code snippet to login to SAP gui and it worked very well thank you. I also downloaded the ‘Scripting Tracker lite’ but it has only the ‘analyzer’ component. Is it possible to the ‘recorder’  component also so that I could try to record SAP GUI  transactions?

    Thanks in advance,

    Hema

    (0) 
  4. Former Member

    Hi Stefan,

    You told me that you had trouble attaching the ‘Scripting Tracker’ to my SAP email. Adelina Pechard and I work in the same office. Is it ok if I get it from her?

    Thank you,

    Hema

    (0) 
  5. Former Member

    Hi Stefan, is it possible to automate entry into the SAP Dialog boxes such as SAPTreeList? I have software which I’m able to look at the windows of SAP but I cannot enter information into SAP’s Advanced TreeList for example….

    (0) 
    1. Stefan Schnell Post author

      Hello David,

      welcome in the Scripting Languages forum.

      Basically I would say it is possible, what are your specific problems?

      Cheers

      Stefan

      (0) 
      1. Former Member

        Hi Stefan, i don’t have SAP scripting enabled, so I’m using the Wind libraries to Get Child Windows, With some windows in SAP I can’t get the windows handles on some components as they are proprietary SAP window components,  such as SAPTreeList. Is it possible to decode these and drive the SAP window?

        (0) 
        1. Stefan Schnell Post author

          Hello David,

          six years ago I tried the same way and I gave up. Technically I think it is possible somehow, but I lose myself in many irrelevant details.

          Here WinSpy with the control hierarchy of the Tree in the SE80 transaction.

          /wp-content/uploads/2015/10/001_802897.jpg

          As you can see WinSpy can’t find any more levels below the treelist.

          My advice to you, enable SAP GUI Scripting, otherwise you will lose many time.

          Cheers

          Stefan

          (0) 
  6. Former Member

    Hi Stefan. Thanks for your quick response.  If I don’t have SAP scripting enabled on the SAP instance is it still possible to automate data entry into SAP?

    (0) 
  7. Former Member

    Hi

    What i would like to do, is control SAP from Excel via “AutoIt”, but i don’t know

    how to start. somebody please help me out !

    (0) 

Leave a Reply