Automate system analysis with SAP GUI scripts

Reading time: 2 min.
Tomasz Jurgielewicz

SAP GUI Scripts

SAP enables the automation of reverse repeatability by making scripting easier.
To be able to run them on the system, you need to prepare the environment accordingly:

  •        SAP GUI – enable scripting in Settings

  • System SAP – set the sapgui / user_scripting parameter to TRUE on the system

Creating SAP GUI Scripts

By default, SAP GUI scripts are written in Visual Basic for Applications (VBA). VBA allows you to create a session with the sap GUI, and then perform the corresponding operations on it. Such a script consists of lines that find the corresponding element in the sap GUI according to its predetermined path, and then perform an action on such an element, for example, typing text or clicking a button.

For example, the path might look like this:

wnd[0]/tbar[0]/okcd

The first element is the WND (window). The zero index means the main application window, the next indexes can be, for example, pop-ups that appear after performing some actions. The ‘/’ character is followed by the tbar [0], which is the first toolbar in the sap GUI. After the next character ' / ' there is already a specific element, in this case okcd, which is the field to which TCODE is written.

Automagica

In that case, do you need to learn VBA to write scripts for SAP GUI? The answer is NO. The opensource Automagica library comes to our aid. Automagica allows you to perform the same actions on the sap GUI using Python.

In addition to sap GUI support, Automagica also allows you to perform mouse movements, use Microsoft Excel, send emails and much more.

Application

Thanks to the Automagica library, it is possible to automate many repetitive processes.

For example, in conjunction with the SAST tool, you can automate the analysis of transactions used by the user. You can automatically run the dedicated SAST functionality and then download the data to Excel. Below is a sample code that implements this:

#init SAPGUI
sap = SAPGUI()
#login
sap.login(sap_system_name, sap_mandant, sap_username, sap_pass)

#enter tcode
sap.set_text('/app/con[0]/ses[0]/wnd[0]/tbar[0]/okcd’, '/n/sast/us_user_activ')
#run transaction
sap.click('/app/con[0]/ses[0]/wnd[0]/tbar[0]/btn[0]')

#input user name
sap.set_text('/app/con[0]/ses[0]/wnd[0]/usr/ctxtSO_USER-LOW', 'suspect')
#execute
sap.click("/app/con[0]/ses[0]/wnd[0]/tbar[1]/btn[8]")

#result to spreadsheet
sap.click("/app/con[0]/ses[0]/wnd[0]/tbar[1]/btn[46]")
sap.click("/app/con[0]/ses[0]/wnd[0]/tbar[1]/btn[43]")
press_key('enter')
sap.click("/app/con[0]/ses[0]/wnd[1]/tbar[0]/btn[11]")

Then, such a script could run another SAST functionality, showing the SoD conflicts used by the same user, and downloaded them to another Excel file.

Finally, operating on Excel alone, the script could perform operations on cells to generate a final report on the conflicting transactions in a form that allows the authorization team in a convenient and transparent way to review the conflicts and make a decision to revoke permissions or mitigating the conflict.

author: Filip Starobrat/Sast Polska Team/

------------------------------------------------------------------------------------------------

READ ALSO:

If you find this article valuable, please share it.
This will allow us to reach new people. Thank you in advance!

We will take care of the digital transformation of your business

Do you want to protect your business against cyber attacks? Or maybe you are planning a digital transformation or looking for IT specialists for a project? We are happy to help. We are here for you. Let's talk about professional IT services for your company.
Contact Us
Darmowy e-book

Wszystko, co musisz wiedzieć
o migracji z SAP ERP na SAP S/4HANA

Nasz zespół ekspertów przygotował dla Ciebie
e-poradnik, dzięki któremu zrobisz to łatwo, bezboleśnie i bez szkody dla bezpieczeństwa
Twojej firmy.

To praktyczna wiedza podana w przystępnym
języku - zupełnie za darmo.
Pobierz darmowego e-booka
Contact
contact@lukardi.com
+ 48 508 400 203
Address Information
ul. Tęczowa 3 , 60-275 Poznań
NIP: 5213683072
REGON: 360098885
Visit our Social Media:
Address Information
ul. Tęczowa 3 , 60-275 Poznań
NIP: 5213683072
REGON: 360098885
Visit our Social Media:
Lukardi 2022. All Rights Reserved. 
Made with