Scripting SAP GUI with python !! 🙅‍♂️🐍 Automation

Vamos a hacer scripting sap en una máquina de SAP R/3, para ello primero tenemos que configurar el sistema para que nos permita hacer script y luego usaremos Visual Studio Code para ejecutar un código simple de Python para realizar un scripting.

We’re going to script on an SAP R/3 machine, for this we first have to configure the system to allow us to script and then we’ll use Visual Studio Code to run a simple Python code to script.

Para ver si tenemos el Script activado en SAP, basta con ver las opciones y fijarnos en si está habilitada opción:

To see if we have Script enabled in SAP, just look at the options and see if it is enabled option:

scripting sap python

Si está deshabilitada tenemos que ir a la transacción RZ11 donde introduciremos el siguiente valor en el parámetro de búsqueda:

If it is disabled we have to go to transaction RZ11 where we will enter the following value in the search parameter:

scripting sap python

Nos muestra información a nivel de metadatos y nos da la posibilidad de cambiar el valor actual de false a true:

It shows us information at the metadata level and gives us the ability to change the current value from false to true:

scripting sap python
scripting sap python

Una vez modificado el valor, cerramos la sesión y volvemos a entrar y ya tendremos habilitada la opción;

Once the value has been changed, we close the session and re-enter and we will have the option enabled;

scripting sap python

Si pulsamos nos saldrá el grabador que generará el fichero de script en la ruta que especifiquemos:

If you press we will get the recorder that will generate the script file in the path that we specify:

scripting sap python

Una vez tenemos configurado el sistema ya podemos atacarlos desde Visual Code con Python. Hay que instalar python, crear un fichero .py e instalar la libreria de win32 para python, esta es la que nos permite capturar la sesion abierta de SAP y manejarla. Para instalar win32 podéis usar:

Once we have configured the system we can already attack them from Visual Code with Python. You have to install python, create a .py file and install the win32 library for python, this is the one that allows us to capture the open sap session and handle it. To install win32 you can use:

pip install pywin32

El siguiente código abre sesión de sap para una máquina específica, hace login con user y pass, y por último entra en la SE16n para visualizar la tabla MARA.

The following code logs in sap for a specific machine, logins with user and pass, and finally enters the SE16n to display the MARA table.

scripting sap python

Normalmente el scripting hacia SAP se realiza con VBA desde Excel, pero es un entorno/lenguaje de desarrollo débil si queremos realizar un tratamiento de la información importante, con Python tenemos un lenguaje muy potente con el que podemos hacer lo que queramos.

Normally scripting to SAP is done with VBA from Excel, but it is a weak development environment/language if we want to perform a treatment of important information, with Python we have a very powerful language with which we can do whatever we want.

Saludos. Best regards.

más cosas en : https://setevalapinsap.com

Enlace relacionado: https://blogs.sap.com/2017/09/19/how-to-use-sap-gui-scripting-inside-python-programming-language/

Añadir un comentario

Tu dirección de correo electrónico no será publicada.