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” |
Aug 31, 2014 SAP GUI Scripting can be used for many small and intermediate batches for mass maintenance tasks (P-/Q- and D-Systems) and quality testing (Q-Systems) in SAP. To reduce development workload or modify a lot of code for different SAP GUI recordings I saw a need for having an Excel VBA template which can cover a lot of requirements. Mar 27, 2018 SAP Script Excel VBA - Entrevista com Marcio Ribeiro - Duration: 38:57. Guia do Excel 10,320 views. SAP GUI Scripting - Extract Data from SAP GUI Transaction to Excel. Enabling SAP GUI (client) for Windows. Start the SAP Logon and log in to the SAP server. Click the Customizing of Local Layout toolbar button. Click Options and click the Scripting tab. Select the Enable Scripting check box. Clear the Notify When a Script Attaches to a Running GUI check box and the Notify When a Script Opens a.
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!
![Scripting Scripting](https://i.ytimg.com/vi/oPPhA14Pm-8/maxresdefault.jpg)
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- Dixell ic121 manual.
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.
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.
Sap Scripting Tool
- Start transaction RZ11
- On the Maintain Profile Parameters screen, enter “sapgui/user_scripting.”
- Choose Display.
- In the Display Profile Parameter Attributes screen, choose Change value.
- Enter “TRUE” in the new value field.
- 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!
Introduction:
SAP GUI Scripting can be used for many small and intermediate batches for mass maintenance tasks (P-/Q- and D-Systems) and quality testing (Q-Systems) in SAP.
Sap Scripting Tool Excel Download
To reduce development workload or modify a lot of code for different SAP GUI recordings I saw a need for having an Excel VBA template which can cover a lot of requirements.
Features:
- Easy to use (One-Button-Solution).
- Excel functions and options can be used for data preparation and consolidation in front of starting update procedure.
- During initialization all existing and non-busy SAP sessions got displayed (UI-Listbox). So we are able to select a specific session for Excel VBA adoption.
- Data from SAP can easily imported into Excel worksheet (Data from ALV-list, fields, result list, status messages, error messages,… and so on).
- Only SAP GUI Scripting recording code need to integrate into VBA module ‘SAP_1_PROCESS’.
- More columns as data source or destination for field data can be added. Last two columns are reserved for procedure usage. This is achieved by using a data-array which got ‘Redim’ during process according to used rows and columns.
- Log-function is integrated (for SAP messages like statusbar Messages or free-text).
Prepare Excel VBA template:
- Step: Create folder on your desktop (or somewhere else) => folder name is up to you.
- Step: Store below text-files into this folder: Please be aware that text-file ‘Modules_All.txt’ need to split into four text-files named ‘SAP_1_Process’, ‘SAP_2_Functions’. SAP_3_Public_Subs’ and ‘Module1’! Start and end of module specific coding is marked and must removed before saving of single text-file. First line in this files must be Attribute VB_Name = “SAP_1_Process”, Attribute VB_Name = “SAP_2_Functions” and Attribute VB_Name = “SAP_3_Public_Subs”. As I can´t upload more than three files you Need to split Modules_All.txt on your own and save files in folder.
- SAP_1_Process.txt
- SAP_2_Functions.txt
- SAP_3_Public_Subs.txt
- Userform1_frm.txt
- Userform1_frx.txt
- Module1.txt
- Step: Create a new Excel workbook and store this in same folder as text-files. You can choice every name you want. My suggestion is ‘Prepare_WB.xlsx’.
- Step: Now go into VBE of Excel ( ALT + F11) => insert Module => open text-file ‘Module1.txt’ => Select all and copy => paste into new module from Excel workbook.
- Step: Execute macro ‘prepare_worksheet’ (Reference to sapfewse.oxs will done utomatically. This require Folder-structure ENVIRON(“PROGRAMFILES”) & “SAPFRONTENDSAPguisapfewse.oxs”). If you have an different Destination please add manual.
- Step: Remove ‘Module1’ from macro-enabled workbook and save.
- Done
Usage of Excel VBA template (MM03_VBA_SAP_SCRIPTING_V1.xlsm):
This Excel template have for demonstration purposes SAP GUI Scripting integrated for getting MM03 data from ‘stor. loc. stck’-tab => ‘Qty. Unrestricted’ + “UoM’ + ‘Material description’ data.
- Step: Fillin ‘Materialnumber’ + ‘Company Code’ + ‘Storage location’ combination used in your system. As error handling is integrated for ‘Company Code’ + ‘Storage location’ combination you can test this as well.
- Step: Press button ‘Run macro ‘SAP_PROCESS’’
- Step: All open and Scripting-enabled SAP sessions got displayed in a Userform-Listbox
- Step: Select one session and press ‘Enter’ or Commandbutton
- Done: Script got executed and you will get data into Excel according to your input data combination (Materialnumber/CoCode/Storage location).
Important data structure information:
All data from Excel worksheet ‘SAP_PROCESS’ got stored into data-array ‘arr_SAP_Data’. This Array is defined with same number range as our used worksheet range. Starting from row ‘2’ up to last used row and all used columns (remember that last two columns are reserved for procedure process).
arr_SAP_Data(lngCounter, (lng_Col + 0))
=> lngCounter is current executed row in worksheet. (lng_col +0) define column ‘1’
=> (lng_col +1) is second column
=> and so on.
Sap Scripting Tool
When you add or delete columns please save workbook immediately.
Conclusion:
Sap Scripting Examples
Feel free to use this template for your requirements by modify coding in ‘SAP_1_Process’-module. But be aware that I am not responsible for any issues, inconsistencies or other incidents which can cause by using this template. Feel free to ask if you Need any additional information. But do not expect any support for your purposes and requirements. Hope this will give you some lights how SAP GUI Scripting can make your daily tasks much smoother.