Skip to Content
http://www.microsoft.com/global/en-us/news/PublishingImages/exec/billg/web/billg1_web.jpg
As Bill Gates once said: “I will always choose a lazy person to do a difficult job… because, he will find an easy way to do it”


Scripting can be used to make repetitive time consuming tasks quick and easy. It takes some time and dedication to write a script but in the end your investment can really pay off. Your script can be faster and more accurate than you! So you have to ask yourself: Should I spend a few hours getting a script to work? If you’re only going to do something once then it’s probably not worth the time. However remember two things; when you do write a script for something, you have that script forever and you’re sharpening your scripting skills with every script you write. So go ahead – Think like a lazy person and you might end up more productive!

Starting Out

First you will need a primer on VBScripting – SAP GUI Scripting is written in Microsoft’s VBScript language. This Scripting language is easy to learn is able to handle most simple tasks. It has been included in Windows since Windows 98 so it’s fairly well documented. Microsoft’s VBScript User’s Guide can be found here: [http://msdn.microsoft.com/en-us/library/sx7b3k7y(v=vs.85).aspx]

For more complicated tasks I’ve wrote front ends in Visual Basic and then built and run a VBScript on the fly. Remember the sky is the limit with scripting so if you can imagine it, it can be done.

Of course you’ll also need to know about SAP Gui Scripting. In order for your VBscripts to access the SAP GUI and manipulate data you’ll need to use an API provided by SAP. You can find documentation for the SAP Gui API here:  SAP Gui Scripting API [http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a034a16b-3bfe-2a10-e2bb-8bd880db0b3c]

Once you’ve gathered the proper documentation you can start to develop scripts!

Keep a few things in mind when you write your scripts-

Make it reusable – Think about other possibilities for your scripts. Spending an extra 5 min writing in an extra feature can end up saving you an hour or two down the road when you might need it. Example – I once wrote a script to lock users. Two extra minutes of coding and it also could unlock them. These two minutes saved me an hour of work a few months later.

Do a good job with the comments – I routinely come back to scripts that I wrote one or two years ago. I can’t remember the specifics of what I was working on at the time so good comments help you understand what you were doing at the time. Some programmers say that good comments are more important than the actual code!

Scripting is dangerous! – Everyone makes mistakes. Automation gives you the ability to make mistakes. Many mistakes… very quickly. So be careful! Make sure to test your script on a sandbox before you decide to run it in Production. I cringe whenever someone asks me to run a script in production because it can be very dangerous. So for your own sake, Be Careful! Or at least make sure your Resume is up to date.

And finally – Start small – Do something simple before you take on something crazy, like scripting system refreshes. You must crawl before you can walk young grasshopper!

Setting up your Environment for SAP Gui Scripting

There are two things you’ll need to setup in order to run Gui Scripts. First you’ll need to configure your client, then the system that you are connecting to.

Step 1: Setup your Client

First, you’ll need to setup the SAP Gui Client to allow scripting on your local machine.  I’ll be working with SAPGUI 7.30 on Windows.

In the options panel of your GUI, you’ll need to select “Accessibility & Scripting” and then “Scripting” in the left hand column. Then you are presented with three checkboxes.

Screenshot1.png

To start, I would suggest selecting all three check boxes. Here is a description of what they do: 

Enable Scripting – This box simply allows scripting on your GUI. (Has nothing to do with the server)

Notify when a script attaches to SAP GUI – Pops up a yes/no box when a script attempts to use the GUI. This is useful to have on because it give you a point to make sure you want to run what you are running. If you don’t have this on, the script will run without any confirmation.

Notify when a script opens a connection – This setting pops up a confirmation when your script connects to a system. I generally turn this off when I run a script that connects to the system multiple times to do what it does. Otherwise I leave this setting on.

Once you’ve checked “enable scripting” you’re ready to run scripts on the client side. Next, you’ll need to check your settings on the server side.

Step 2: Setup your SAP System

You can enable scripting by setting the profile parameter sapgui/user_scripting to TRUE. The value set using this procedure will be lost when the system is restarted. If the administrator edits the application server profile of the SAP System to include sapgui/user_scripting = TRUE, scripting will be enabled by default when the server is restarted.

REMEMBER: ENABLING SCRIPTING IN PRODUCTION SYSTEMS IS GENERALLY A BAD IDEA.

Screenshot2.png

Screenshot3.png

  1. Start transaction RZ11
  2. On the Maintain Profile Parameters screen, enter “sapgui/user_scripting.
  3. Choose Display.
  4. In the Display Profile Parameter Attributes screen, choose Change value.
  5. Enter “TRUE” in the new value field.
  6. Click the Save Button.

Once you’ve done these two things – You’re ready to run scripts.

I’ll continue to add to this series on SAP GUI Scripting. Stay tuned!

To report this post you need to login first.

11 Comments

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

  1. Osvaldo Lopez

    Hello Joe! Excellent post!

    Excellent explanation and very good links to expand knowledge.

    I appreciate a blog like this.

    Thank you very much!

    Please keep posting about these topic! 😛

    I love your “Bill Gates” quote too, quite true!

    Regards,

    Oswald

    (0) 
  2. Ian Fleming

    I am trying to execute the SAP GUI from scripts in ‘silent mode’ which is like running browsers ‘headless’, so I can perform some simple load tests with running multiple SAP GUI scripts in parallel. Do you know the setting to execute the scripts without the GUI showing on the screen?

    Thanks for the article.

    Ian

    (0) 
  3. Gunnar Ásgeirsson

    Hi

    I’m using SAP GUI Scripting for automating SAP GUI 720 from another application. A user marks one or many dokuments id’s in one system, klicks a button and the SAP GUI is opened showing a list of documents in SAP DMS.

    This is all working fine but the SAP GUI does not look the same when using the GUI Scripting as when opened the normal way. It does not have the correct theme, SAP Signature Theme. It looks like it is using the Classic Theme. When running under Windows 7 the SAP Gui is even worse. Buttons and tabs are invisible.

    Is there some way to change so it uses the SAP Signatur Theme or another theme when SAP GUI Scripting is used?

     

    Gunnar

    (0) 
    1. José Donizeth Rodrigues

      Hi,

      The deal is too good to be bad.

      It is a way to use standard, or perhaps much smaller cost and zero-risk.

      Read some materials on SAP scripting and what SAP recommends realized by the fact that you can run a very long process via scripting, not the fact that the scripting enabled will change performance. Another point is that if it were as problematic by the SAP standard way stops, including 1441550 SAP provides recorders scripting.

      Even learned to use the scripting in SDN and SCN but not in the forums, but in the SAP distributes itself.

      From what I understand there are also objects of authorizations that may make further restrictions on users as to what will run in scripting.

      Below is some information from SAP and notes:

      http://scn.sap.com/docs/DOC-8971#section12

      http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80aaac18-2dfe-2a10-bbb1-ec9b3760ea4c?QuickLink=index&overridelayout=true&28385438934341

      http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e00d6fd4-eaf4-2a10-90a5-db931026edc8?QuickLink=index&overridelayout=true&27801323333531

      Note 1441550

      https://websmp130.sap-ag.de/sap(bD1wdCZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=1441550

      (0) 
  4. José Donizeth Rodrigues

    Hi,

    The deal is too good to be bad.

    It is a way to use standard, or perhaps much smaller cost and zero-risk.

    Read some materials on SAP scripting and what SAP recommends realized by the fact that you can run a very long process via scripting, not the fact that the scripting enabled will change performance. Another point is that if it were as problematic by the SAP standard way stops, including 1441550 SAP provides recorders scripting.

    Even learned to use the scripting in SDN and SCN but not in the forums, but in the SAP distributes itself.

    From what I understand there are also objects of authorizations that may make further restrictions on users as to what will run in scripting.

    Below is some information from SAP and notes:

    http://scn.sap.com/docs/DOC-8971#section12

    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80aaac18-2dfe-2a10-bbb1-ec9b3760ea4c?QuickLink=index&overridelayout=true&28385438934341

    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e00d6fd4-eaf4-2a10-90a5-db931026edc8?QuickLink=index&overridelayout=true&27801323333531

    Note 1441550

    https://websmp130.sap-ag.de/sap(bD1wdCZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=1441550

    (0) 
  5. Daniel Martin

    Very nice post. Thank you.

    I was wondering if is there a solution for those new SAP web interfaces, like the one used in some transactions in Solution Manager, or the Fiori used in SAP HANA.

    I was very happy with VBScripts and suddenly I couldn’t use them for some transactions in SolMan.

    (0) 

Leave a Reply