<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: PythonWin and SAPGUI Scripting in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403454#M610191</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Further to the above, I've now been able to translate and run VBS recordings within Python with only a few minor changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the approach I've taken:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"// Some introductory setup..&lt;/P&gt;&lt;P&gt;import win32com.client&lt;/P&gt;&lt;P&gt;False, True = 0, -1&lt;/P&gt;&lt;P&gt;app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")&lt;/P&gt;&lt;P&gt;con = app.OpenConnection("D47", True)&lt;/P&gt;&lt;P&gt;session = app.FindById("ses[0]")&lt;/P&gt;&lt;P&gt;"// Some input steps (reading from CSV files or other sources...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;"// Then the actual GUI scripting steps..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some "translation" hints: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(1) A VBS recording writes session.findById. In Python it is more accurately written as session.FindById&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(2) A VBS statement such as session.findById("wnd[0]").resizeWorkingPane 132,25,false&lt;/P&gt;&lt;P&gt;would be written as session.FindById("wnd[0]").resizeWorkingPane( 132, 25, False) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;similarly: &lt;/P&gt;&lt;P&gt;session.findById("wnd[0]").sendVKey 0 from VBS would be written session.FindById("wnd[0]").sendVKey( 0 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other than that - all seems pretty straight forward..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 22 Jul 2006 10:31:53 GMT</pubDate>
    <dc:creator>AndrewBarnard</dc:creator>
    <dc:date>2006-07-22T10:31:53Z</dc:date>
    <item>
      <title>PythonWin and SAPGUI Scripting</title>
      <link>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaq-p/1403453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was hoping that somebody else might have posted some examples of SAPGUI scripting and Python(Win) - but I couldn't find any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In short - I've got so far as to get basic manipulation working. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import win32com.client&lt;/P&gt;&lt;P&gt;False, True = 0 , -1&lt;/P&gt;&lt;P&gt;app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")&lt;/P&gt;&lt;P&gt;conn = app.OpenConnection("D47", True)&lt;/P&gt;&lt;P&gt;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 &lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; print conn.Id &lt;/P&gt;&lt;P&gt;returns /app/con[0]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; ses = app.FindById("ses[0]")&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; ses.CreateSession() "opens up a new session Good!&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; ses.SendCommand(Command="/nIW31") "starts Tx IW31&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; ses.StartTransaction(Transaction="IW31") "start IW31 also&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; window = ses.activeWindow&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; print window.Id&lt;/P&gt;&lt;P&gt;/app/con[0]/ses[0]/wnd[0]&lt;/P&gt;&lt;P&gt;start SE38...&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; field = window.FindByName(Name="RS38M-PROGRAMM", Type="GuiCTextField")&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; print field.Id&lt;/P&gt;&lt;P&gt;/app/con[0]/ses[0]/wnd[0]/usr/ctxtRS38M-PROGRAMM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So - it seems that basic manipulation works OK&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next step is to try some useful...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll let you know how it goes..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Andrew Barnard&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Incorporated successful code and removed some questions which I've now solved myself. (The successful code covers the questions!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2006 12:33:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaq-p/1403453</guid>
      <dc:creator>AndrewBarnard</dc:creator>
      <dc:date>2006-07-21T12:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: PythonWin and SAPGUI Scripting</title>
      <link>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403454#M610191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Further to the above, I've now been able to translate and run VBS recordings within Python with only a few minor changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the approach I've taken:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"// Some introductory setup..&lt;/P&gt;&lt;P&gt;import win32com.client&lt;/P&gt;&lt;P&gt;False, True = 0, -1&lt;/P&gt;&lt;P&gt;app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")&lt;/P&gt;&lt;P&gt;con = app.OpenConnection("D47", True)&lt;/P&gt;&lt;P&gt;session = app.FindById("ses[0]")&lt;/P&gt;&lt;P&gt;"// Some input steps (reading from CSV files or other sources...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;"// Then the actual GUI scripting steps..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some "translation" hints: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(1) A VBS recording writes session.findById. In Python it is more accurately written as session.FindById&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(2) A VBS statement such as session.findById("wnd[0]").resizeWorkingPane 132,25,false&lt;/P&gt;&lt;P&gt;would be written as session.FindById("wnd[0]").resizeWorkingPane( 132, 25, False) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;similarly: &lt;/P&gt;&lt;P&gt;session.findById("wnd[0]").sendVKey 0 from VBS would be written session.FindById("wnd[0]").sendVKey( 0 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other than that - all seems pretty straight forward..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Jul 2006 10:31:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403454#M610191</guid>
      <dc:creator>AndrewBarnard</dc:creator>
      <dc:date>2006-07-22T10:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: PythonWin and SAPGUI Scripting</title>
      <link>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403455#M610192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I' have been wondering quite a while.&amp;nbsp; Now your posting got me started using Python to automate some SAP routine work.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just one question.&amp;nbsp; How do you do translate this VBS line to python?&lt;/P&gt;&lt;P&gt;session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see its value on python console. but could not figure how to assign a value to that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2013 17:55:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403455#M610192</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-08-28T17:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: PythonWin and SAPGUI Scripting</title>
      <link>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403456#M610193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should try this.&lt;/P&gt;&lt;P&gt;obj = session.findById("wnd[0]/usr/txtRSYST-MANDT")&lt;/P&gt;&lt;P&gt;obj.text = "100"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Nov 2015 02:32:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403456#M610193</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-11-30T02:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: PythonWin and SAPGUI Scripting</title>
      <link>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403457#M610194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andrew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having a problem with opening the SAP GUI using the python script.&lt;/P&gt;&lt;P&gt;I am using the below code,&lt;/P&gt;&lt;P&gt;import win32com.client&lt;/P&gt;&lt;P&gt;app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")&lt;/P&gt;&lt;P&gt;conn = app.OpenConnection("EGD", True)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting the error message 'Error 605,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The SAP GUI component could not instantiated.'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please help me, as to how you could open the SAP GUI with the python script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Laxman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 May 2016 15:54:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/pythonwin-and-sapgui-scripting/qaa-p/1403457#M610194</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-05-29T15:54:23Z</dc:date>
    </item>
  </channel>
</rss>

