Skip to Content
Jul 21, 2006 at 12:33 PM

PythonWin and SAPGUI Scripting


I was hoping that somebody else might have posted some examples of SAPGUI scripting and Python(Win) - but I couldn't find any.

Here is a very small example of SAPGUI Scripting with PythonWin. It might serve as a quick start for others who might also share an interest in Python and GUIscripting.

In short - I've got so far as to get basic manipulation working.

import win32com.client

False, True = 0 , -1

app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")

conn = app.OpenConnection("D47", True)

At this point the SAPGUI opens with the initial logon screen of the system. A connection has been created. I enter my user ID and password

>>> print conn.Id

returns /app/con[0]

>>> ses = app.FindById("ses[0]")

>>> ses.CreateSession() "opens up a new session Good!

>>> ses.SendCommand(Command="/nIW31") "starts Tx IW31

>>> ses.StartTransaction(Transaction="IW31") "start IW31 also

>>> window = ses.activeWindow

>>> print window.Id


start SE38...

>>> field = window.FindByName(Name="RS38M-PROGRAMM", Type="GuiCTextField")

>>> print field.Id


So - it seems that basic manipulation works OK

Next step is to try some useful...

I'll let you know how it goes..


Message was edited by: Andrew Barnard

Incorporated successful code and removed some questions which I've now solved myself. (The successful code covers the questions!).