cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

PythonWin and SAPGUI Scripting

AndrewBarnard
Contributor
0 Likes
4,915

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

/app/con[0]/ses[0]/wnd[0]

start SE38...

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

>>> print field.Id

/app/con[0]/ses[0]/wnd[0]/usr/ctxtRS38M-PROGRAMM

So - it seems that basic manipulation works OK

Next step is to try some useful...

I'll let you know how it goes..

Andrew

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!).

View Entire Topic
Former Member
0 Likes

Hi Andrew,

I am having a problem with opening the SAP GUI using the python script.

I am using the below code,

import win32com.client

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

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

I am getting the error message 'Error 605,      The SAP GUI component could not instantiated.'

Can you please help me, as to how you could open the SAP GUI with the python script.

Regards,

Laxman