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:
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.
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.
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: