Skip to Content

SAP Logon view is different when launched with Python script


I am trying to automate SAP GUI with python. If I open manually SAP GUI, the SAP Logon has different Connections and a different layout than when done from Python:

SAP Logon when opened manually:

SAP Logon when opened with Python:

My program uses as based this (it was taken from here)

# import libraries
import win32com.client
from win32com import *
from win32api import *
from win32com.client import *
import win32com.client as win32
import win32gui, win32con
import pyautogui, time, webbrowser, datetime
from Tkinter import *

# create a reuseable connection class
class cls_SAP_Gui_Scripting:
def __init__(self, api, conn):
self.SAPguiAPP = win32com.client.Dispatch(api)
self.Connection = self.SAPguiAPP.OpenConnection(conn,1)
self.Session = self.Connection.Children(0)

# Create Different SAP Script Functions
def run_my_sap_script():
# instantiate the class inside the function
MySapGui = cls_SAP_Gui_Scripting(“Sapgui.ScriptingCtrl.1”, “75 – NSP – Production Simple SAP Access”)
MySapGui.Session.FindById(“wnd[0]/usr/ctxtRP50G-PERNR”).Text = ‘9999999’
# Loop through excel workbook here with excel.application

# Create a main window with Tkinter and add button to run SAP Script Function
def main():
window = Tk()
window.title(“SAP Script Automation”)
b1 = Button(window,text=”Run SAP GUI Script”,font=(“Helvetica”, 16),command=run_my_sap_script)
b1.grid(row=0, column=0)

# Call Main

how can I make sure that script opens the correct SAP GUI? why is not loading the proper connections?


capture1.png (5.5 kB)
capture2.png (10.4 kB)
Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Posted on Aug 30, 2018 at 06:22 AM

    Hello David,

    I assume when you use Sapgui.ScriptingCtrl it works independently from and without the SAP Logon. That could be the reason why the selected theme in the SAP Logon was ignored.

    Here an example, I tried it with VBScript and the front end session is part of the Windows Scripting Host.

    Best regards

    scriptctrl.jpg (36.2 kB)
    Add comment
    10|10000 characters needed characters exceeded