Skip to Content
0
Aug 27, 2018 at 03:33 PM

SAP Logon view is different when launched with Python script

1972 Views

Hi,

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.StartTransaction(“PA20”)
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”)
window.wm_state(‘zoomed’)
window.configure(bg=’red’)
b1 = Button(window,text=”Run SAP GUI Script”,font=(“Helvetica”, 16),command=run_my_sap_script)
b1.grid(row=0, column=0)
window.mainloop()


# Call Main
main()

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

thanks!

Attachments

capture1.png (5.5 kB)
capture2.png (10.4 kB)