Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

win32com and SAP-GUI

My SAP-GUI has Scripting installed and Scripting is enabled.

Like in this screenshot:

sap-gui-config--scripting-enabled

In this Introduction to SAP GUI Scripting in "Step 2: Setup your SAP System" you need to call RZ11.

I don't have permissions to call RZ11.

Is there a way to detect this (sapgui/user_scripting on or off) via a script?

At the moment I use below code, but the list of connections is always empty:

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
sapgui = win32com.client.GetObject("SAPGUI")
system = query.get('system')
client = query.get('mandant')
session = False
application = sapgui.GetScriptingEngine
seen = []
for i_conn in range(0, application.Connections.Count):
    seen.append('i_conn=%s session_count=%s' % (i_conn, application.Connections.Item(i_conn).Sessions.Count))
    for i_sess in range(0, application.Connections.Item(i_conn).Sessions.Count):
        session_info = application.Connections.Item(i_conn).Sessions.Item(i_sess).Info
        system_of_session = session_info.SystemName
        client_of_session = session_info.Client
        if system_of_session == system and client_of_session == client:
            connection = application.Connections.Item(i_conn).Children(i_sess)
            session = connection.Children(i_sess)
            break
        seen.append('system=%s client=%s' % (system_of_session, client_of_session))
    if session:
        break

else:
    info_popup('You are not logged into system %s in Client %s! Seen:\n%s' % (
        system, client, '\n'.join(seen)))
    return
like image 778
guettli Avatar asked Nov 12 '18 10:11

guettli


People also ask

What is the SAP GUI for Windows?

SAP GUI known as front-end for mySAP & R/3 is the SAP Interface for Windows. It is available for all platforms running Microsoft Windows 32-bit. The unique set of functions is the advantage of the SAP GUI for Windows.

How to use SAP GUI scripting in Python?

To use SAP GUI Scripting in the context of Python you need PyWin32 extension. Adding a Note tab as textual memory. Minor bug fixing. Scripting Tacker includes now AutoItX to use it seamlessly in the context of SAP GUI Scripting. It is a fabulous addition e.g. to control non SAP GUI dialogs.

What are the types of SAP GUI customers?

There are three types of SAP GUI customers: SAP GUI known as front-end for mySAP & R/3 is the SAP Interface for Windows. It is available for all platforms running Microsoft Windows 32-bit. The unique set of functions is the advantage of the SAP GUI for Windows.

Is it possible to open SAP GUI from the beginning?

The script you shared at the beginning works fine, but it requires SAP GUI to be already opened. We would like to automate everything from the beginning, including opening SAP GUI, selecting the desired connection, login and so on. However, everytime we try to do that, the SAP GUI interface we get is very different than when we open it manually.


1 Answers

When you don't have sufficient priviledges in sap, the fact that you can't connect is a pretty good indication that the user does not have scripting enable (assuming the user has a active sap session running), other wise you could just test with 'session.findById("wnd[0]/usr/tblSAPLCMDITCTRL_3500").getAbsoluteRow(3).selected = true' and check for errors. Also, I suggest you factor in "SAPGUISERVER' in your sapgui = win32com.client.GetObject("SAPGUI") connection if "SAPGUI" fails.

like image 57
OzzyMiner Avatar answered Jan 02 '23 12:01

OzzyMiner