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

Further to the above, I've now been able to translate and run VBS recordings within Python with only a few minor changes:
Here is the approach I've taken:
"// Some introductory setup..
import win32com.client
False, True = 0, -1
app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")
con = app.OpenConnection("D47", True)
session = app.FindById("ses[0]")
"// Some input steps (reading from CSV files or other sources...
"// Then the actual GUI scripting steps..
Some "translation" hints:
(1) A VBS recording writes session.findById. In Python it is more accurately written as session.FindById
(2) A VBS statement such as session.findById("wnd[0]").resizeWorkingPane 132,25,false
would be written as session.FindById("wnd[0]").resizeWorkingPane( 132, 25, False)
similarly:
session.findById("wnd[0]").sendVKey 0 from VBS would be written session.FindById("wnd[0]").sendVKey( 0 )
Other than that - all seems pretty straight forward..

Similar Messages

  • Delphi and SAPGUI-Scripting

    In order to produce a connection to the SAPGUI, following code is executed from a Delphi-Programm:
    rotentry:=createoleobject('SAPGUI');
    RotApp:=rotentry.GetScriptingEngine;
    As presentation served from the documentation :
    sapgui = GetObject("SAPGUI");
    application = sapgui.GetScriptingEngine;
    It is shown with the implementation, that is not registered the class.
    "However, SAPGUI" is not registered as Autmationsserver. If I can, and how I can make up the registration.

    Further to the above, I've now been able to translate and run VBS recordings within Python with only a few minor changes:
    Here is the approach I've taken:
    "// Some introductory setup..
    import win32com.client
    False, True = 0, -1
    app = win32com.client.Dispatch("Sapgui.ScriptingCtrl.1")
    con = app.OpenConnection("D47", True)
    session = app.FindById("ses[0]")
    "// Some input steps (reading from CSV files or other sources...
    "// Then the actual GUI scripting steps..
    Some "translation" hints:
    (1) A VBS recording writes session.findById. In Python it is more accurately written as session.FindById
    (2) A VBS statement such as session.findById("wnd[0]").resizeWorkingPane 132,25,false
    would be written as session.FindById("wnd[0]").resizeWorkingPane( 132, 25, False)
    similarly:
    session.findById("wnd[0]").sendVKey 0 from VBS would be written session.FindById("wnd[0]").sendVKey( 0 )
    Other than that - all seems pretty straight forward..

  • EEM: SAPGUI scripting not enabled on server

    Hi Gurus,
    I have setup SAPGUI EEM monitoring via SOLMAN 7.1 but after deployment there's an error message "SAPGUI scripting not enabled on server()-214722150:disabledByServer=True". I already checked the backend system, and the paramater of sapgui/user_scripting is set to TRUE.
    Please advise what else do I need to check in order for the SAPGUI scripting to be working in EEM? Is there any additional parameter that I need to change in the backend system?
    Thanks,
    Virgilio

    Hi Virgilio,
    See this link is usefully
    Security for the Use of SAP GUI Scripting - eCATT Security Guide - SAP Library
    Regards,
    Deva

  • Sapgui scripting

    Happy to meet Mr Cohr here.
    Let me tell you some comments on Sapgui scripting.
    a) The code generated is really different depending if your are using a slow or a regular lan connection. It is not that fun, I made some developments to use indexed fields instead of using names.
    schnick.schnack.scnock
    /1/2/0
    where schnick was the second control available
    schnack the third son of schnick
    schnock the first son of schnack
    it remains valid in any case.
    b) the management of session number  and connnection is not easy.
    how do you do that on your own?
    regards
    Didier

    Hi Didier,
    the problem with the low-speed-connection is a documented 'feature'. Unfortunately during a low-speed- connection the server does not send us the field names that we use to identify objects. I think according to the documentation Scripting doesn't work at all in low-speed-connection. As you noticed it's not quite that bad. The Scripting will work, but you get different Ids for your elements. These Ids follow the same concept as your solution: We use an index to identify objects on the same level of the hierarchy.
    Session and connection numbers are meaningless most of the time. They depend so much on what else you are or were doing in SAP GUI that a script relying on them will fail most of the time.
    The sample recorder generates code that will always access the first session of the first connection using app.children(0).children(0). All Ids in the scripts are then relative to this session and do not contain a session or connection number. That's ok if you work with one open session most of the time.
    We also have a property app.ActiveSession, which will return the session that is currently the topmost.
    If you need to access several sessions then it becomes difficult. You can distinguish sessions by checking the connection information in session.info or the window title, but that requires some code writing.
    Best regards,
    Christian

  • SAPGUI Scripting - Connection in Delphi/Lazarus

    Hi,
    i tried to convert my autoitscript projects to Delphi/Lazarus because i need a few things autoit can´t offer. I have a few scripts written that interact with the SAP GUI that work quite well, e.g. Excel data import, specific label printing (p-touch) automated data change/correction etc.
    I thought the simple connection to the SAP-GUI scripting wouldn´t be that difficult to migrate but in fact i´m not able to just do the simple task to connect to the running SAP session in Delphi/Lazarus.
    Perhaps anyone has already done this and could share the code in Delphi/Lazarus that does the following that works perfectly well in Visual Studio VBA:
    Dim sapgui, sapapp, sap_connection, sap_session As Object
            sapgui = GetObject("SAPGUI")
            sapapp = sapgui.GetScriptingEngine
            sap_connection = sapapp.Children(0)
            sap_session = sap_connection.Children(0)
            MsgBox(sap_session.findById("wnd[0]").Text)
    I tried a few things in Lazarus but it always sticks at the "Children(0)" connection with a ole type error
    Thanks
    Thomas

    Hopefully i found the answer
    i just referenced the  activex file "SAPFEWINSE.OCX"   which is part of the SAPGUI Scripting API  project SAPFEWINSELIB
    feel free to comment  if u have better ideas

  • SAPGUI Scripting Developer needed

    I need someone capable of doing some VB coding for me related to SAPGUI scripting.....I need tight login scripts covering every scenario (user already logged on, max # of sessions, single-signon, etc.) and I need help with the systemfocus statements and understanding how it actually works (see my other post). 
    I am developing a commercial program and need it to behave as such, and unfortunately my scripting skills and programming skills in general are lacking.
    Thanks,
    Mike

    Standard Excel VBA uses UCASE to convert text to upper case.

  • SAPGUI scripting via. Excel

    We have a inhouse SAPGUI scripting tool (not really sure if it is Inhouse or SAP delivered it) that we currently use to perform Mass updates via. Excel. The person who created this has left the company but now we have a need to update this. I have no idea of how it was developed. It just seems like it was customized from available scripting functions alread yavalable. This was created in 2003 and obviously it is outdated.
    How it works:
    We install this tool/plugin, and it creates a menu item in the Excel called SAP Scripting and it has Connect to SAP, Play, Record, Stop, Generate Input Sheet as options. Wehn you click connect to SAP, it brings up the Logon pad and allows the user to select a system and logon. Then yo ucan click Record and it will capture all the transcations and when you hit stop and click generate input sheet, the script is ready. The script looks something like the below but below is not complete.
    Issue:
    The script is converting all the Input Values to UpperCase but when we use this to populate some paramets which are case sensitive, we are having issues. We need to figure out a way so that the script doesn't convert the input values to UpperCase.
    have nayone seen this type os scripting tool? Any advice?
    IsInput     ID     ScriptCode
    START     001     
         002     MySession.findById("wnd[0]").resizeWorkingPane 95,25,false
         003     MySession.findById("wnd[0]/tbar[0]/okcd").text = "/nsu01"
         004     MySession.findById("wnd[0]/tbar[0]/btn[0]").press
    X     005     MySession.findById("wnd[0]/usr/ctxtUSR02-BNAME").text =
         006     MySession.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 6
         007     MySession.findById("wnd[0]/tbar[1]/btn[7]").press
         008     MySession.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select
         009     MySession.findById("wnd[0]/usr/tabsTABSTRIP1/tabpSNC").select
         010     MySession.findById("wnd[0]/tbar[1]/btn[19]").press
    X     011     MySession.findById("wnd[0]/usr/tabsTABSTRIP1/tabpSNC/ssubMAINAREA:SAPLSNCB:1002/txtUSRACL-PNAME").text =
         012     MySession.findById("wnd[0]/usr/tabsTABSTRIP1/tabpSNC/ssubMAINAREA:SAPLSNCB:1002/txtUSRACL-PNAME").caretPosition = 21
         013     MySession.findById("wnd[0]/tbar[0]/btn[11]").press
    STOP     014

    Standard Excel VBA uses UCASE to convert text to upper case.

  • SAPGUI Scripting - What is required?

    We are just starting to used SAP R/3 4.6C. Is SAPGUI Scripting an application/development add on to be installed in addition to the SAP GUI client ?. I try the script examples (....GetObject("SAPGUI")...etc) but Visual Basic raise the infamous "cannot create object error" which I understand that I dont have the ActiveX needed installed in my PC. (I check saplogon.exe and I dont have it on my PC). What do I need to installed and from where I can get it ?

    Hello Victor,
    SAP GUI Scripting is a subcomponent of the SAP GUI installation that you have to select during the installation process (or during the definition phase of your packages if you are using an installation server). It is part of SAP GUI as of release 6.20 so you need at least this release (but all the older releases are no longer supported anyway).
    In the SAP system itself note 480149 has to be applied. You need a minimum level of SAP Kernel.
    Here is the text of the note:
    Symptom                                                                   
    The sapgui/user_scripting parameter is imported again. If this parameter  
    is set to TRUE, the scripting functions can be used with a GUI as of      
    version 6.20 on the front end.                                                                               
    The default value of the parameter is FALSE so that scripting to the      
    system is not possible.                                                                               
    Note that you must enter the values in upper case;                                                                               
    There are 2 options for setting the parameter: In transaction rz11 and    
    in the server profile. If the parameter is only set in rz11, the change   
    is lost when you restart the server.                                                                               
    Setting the parameter in the SAP system                                   
    ===============================================                                                                               
    If possible, dynamic setting of the parameter is executed using           
    transaction rz11. Specify the parameter name sapgui/user_scripting and    
    select 'Display'.                                                         
    Provided that the current value is set to FALSE, select the 'Change       
    value' button in the toolbar. A window now appears, in which you can      
    enter the new value TRUE. When you save the change, the window closes     
    and the current value of the parameter changes to TRUE. This change only  
    becomes effective when you log onto the system again.                                                                               
    If the parameter is not found, you must import the relevant Support       
    Package in accordance with the list below.                                
    If the current value does not change accordingly after you have saved  
    the change, it means that the kernel is too old. In this case, import  
    the required kernel patch, as specified below.                                                                               
    Setting the parameter in the server profile                            
    ======================================                                                                               
    If you have not imported the Support Package, you can switch the       
    scripting on if you set the parameter in the profile file of the       
    application server with the following line:                              
    sapgui/user_scripting = TRUE                                             
    This procedure only requires the specified kernel patch level, however,  
    you must restart the application server.                                 
    Other terms                                                                               
    Reason and Prerequisites                                                                               
    Solution                                                                 
    The parameter is delivered with the following kernel patches:                                                                               
    o  6.10: 360                                                                               
    o  4.6D: 948                                                                               
    o  4.5B: 753                                                                               
    o  4.0B: 903                                                                               
    o  3.1I: 650                                                                               
    The parameter can be dynamically activated in the following kernel       
    versions, that is, without having to restart the application server:                                                                               
    o  6.20 Release 6.20 and subsequent versions                                                                               
    o  6.10 Release 6.10 as of patch 391                                                                               
    o  Release 4.6D as of patch 972                                                                               
    Best regards,
    Frank

  • Difference between TCD and SAPGUI

    Hi all,
    What are the differences between TCD and SAPGUI in ecatt?
    And also which one is better? Should I used tcd mode of ecatt for any transaction? Or there is any limitations for the same. same for SAPGUI?

    Hello Lalit,
    TCD & SAPGUI modes have their own advantages & disadvantages. So their usage depends on their requirement in the recording.
    Some of the differences between TCD & SAPGUI are as follows -
    1. TCD recording mode can run in background as well as foreground.
    - SAPGUI recording mode requires GUI playback. But it can run with or without user intervention.
    2. TCD is fastest mode of recording as well as replay.
    -SAPGUI is very slow.
    3. TCD cannot be used for ENJOY transactions (those who have activex controls) where the usage of activex controls is mandatory. It is suitable for simpler transactions where directly values and be placed and results can be seen.
    -SAPGUI work with ENJOY transactions. It should be selected only when the usage of the controls is mandatory.
    You will conclude more about the TCD & SAPGUI usage gradually as you will work with transaction in eCATT.
    More details can be found from the following weblogs -
    1. eCATT Introduction
    /people/sapna.modi/blog/2006/04/10/ecatt--an-introduction-part-i
    2. TCD Recording Mode
    /people/sapna.modi/blog/2006/04/10/ecatt-scripts-creation-150-tcd-mode-part-ii
    3. SAPGUI Recording Mode
    /people/sapna.modi/blog/2006/04/10/ecatt-scripts-creation--sapgui-mode-part-iii
    PS If the answer solves your query, do reward points to everyone responding.
    Regards

  • Newbie Quest. : Howto disable SAPGUI script warning

    Hi,
    just trying to do some things with vbs and sapgui, i've enabled scripting on the server and disabled scripting warning in the Control Panel. Scripting works fine if the gui is already started, but if i try to start the GUI over vbs and logon i still get:
    "A script is opening a connection to system xyz"
    Using Sapgui 6405.5.28
    how can i disable the warning message ?
    thx
    Heinrich

    Hi,
    Log into the SAP system you are running the script on. Goto the Customize Local Layout button on the toolbar (last one on the right). In the resulting drop down menu click on options.
    You should get a pop up box so go to the scripting tab. Untick the option "Notify When a Script Attaches to a Running GUI". Also untick the "Notify When a Script Opens a Connection".
    That should sort it out - let me know if not.
    Thanx
    Nath

  • Can't get conky-cli and bash scripts to both display in dwm statusbar!

    I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
    The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
    network(){
    iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
    echo wired
    exit 0
    essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
    stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
    bars=`expr $stngth / 10`
    case $bars in
    0) bar='[-------]' ;;
    1) bar='[#------]' ;;
    2) bar='[##-----]' ;;
    3) bar='[###----]' ;;
    4) bar='[####---]' ;;
    5) bar='[#####--]' ;;
    6) bar='[######-]' ;;
    7) bar='[#######]' ;;
    *) bar='[--!!!--]' ;;
    esac
    echo $essid$bar
    exit 0
    volume(){
    vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
    echo Vol: $vol%
    exit 0
    conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
    exec dwm
    (let me know if it would help to post any other files)
    For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
    An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
    cpu0/1: xx% xx%
    Also, seeing RAM usage would help a lot. In conky it shows:
    mem: xx% (xxxMB)
    These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
    Help?

    Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
    EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
    Thanks for your help!
    Last edited by Allamgir (2009-07-18 14:41:11)

  • Error with dbms_scheduler and shell script execution

    Hi,guys.
    I have an issue with a dbms_scheduler and a shell script execution. So, the shell script as it self works fine, when i'm executing ./test.sh all process is running, but when i'm executing the script from dbms_scheduler it just simply doesn't work. Actually it works, but some of executable information in sh doesn't work, seems it just jump over of the part of the script. Sendmail part is running, maybe there is problem with rman script as it self?
    DB version: 10g
    And my scripts:
    Shell scripts (permisons 755):
    #!/bin/ksh
    export PATH=/home/oracle/product/asm_home/bin:/home/oracle/product/db_home/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X11:/sbin:.
    export ORACLE_BASE=/home/oracle/product
    export ORACLE_SID=zabbix
    export ORACLE_HOME=/home/oracle/product/db_home
    ${ORACLE_HOME}/bin/rman<<EOF
    connect target /
    run {backup recovery area delete all input;}
    EOF
    {       echo "From:[email protected]"
            echo "To: [email protected]"
            echo "Subject: Recovery area"
            echo 'Content-Type: text/html'
            echo
            echo '<html><body><table border="1" cellspacing="1">'
            echo '<tr><td><b>Process</b></td><td><b>Statuss</b></td></tr>'
            echo "<tr><td>RMAN</td><td><b>Works</b></td></tr>"
            echo "</table></body></html>"
    } | sendmail -tIn the first part i'm exporting all of the important stuff for oracle, then I call RMAN with specific atributes. And then there is just simply sendmail functionality inside script to represent if script works (for now).
    And below pl/sql script:
    begin
      DBMS_SCHEDULER.CREATE_JOB
      job_name => 'FLASH_RECOVERY',
      job_type => 'EXECUTABLE',
      job_action => '/home/oracle/backup/test.sh',
      start_date => sysdate,
      job_class => 'DEFAULT_JOB_CLASS',
      enabled => TRUE,
      auto_drop => FALSE,
      comments => 'FLASH RECOVERY USAGE AREA backup and delete'
      END;
      /And this job execution:
           begin
               DBMS_SCHEDULER.run_job (job_name =>'FLASH_RECOVERY',use_current_session => TRUE);
           end;What can be wrong? For me, I think it's something with permisions.
    I hope you got my idea and could help me.
    Tom
    Edited by: safazaurs on 2013.18.2 22:16

    There is no error, i just receive all the time e-mail, seems it jumps over rman. I tried almost everything and still couldn't get result as i want. And, if i'm running script from command line - it works. Rman calls, and starts to recover archivelogs.

  • Render and Email script

    Hello everybody. I have a question that I have thoroughly researched on the web with no results.
    I am trying to get the default After Effects "Render and Email" script to run properly. I have only been able to successfully send FROM one specific email address TO another (slightly less specific) email address. Most other email services I put in (icloud, gmail, etc) all give strange errors upon execution.
    For the SENDING email address, I'm currently using one I created that is a part of my web hosting account (this is the only account I am able to successfully send from). For RECEIVING, I've only successfully gotten my gmail address to work. All other receiving addresses don't always give me error, but also never show up. Either that, or I get very weird errors. The most common one I get is "Unaable to send mail. 533 5.7.1 AUTH command is not enabled."
    I haven't been able to find this error documented anywhere online. I'd like to be able to send emails to my icloud account, since it pushes email notifications to my phone in real time.
    Long ago someone by the name of Ko Maruyama supposedly explained all this in detail, but the writeup was posted on a .mac website (http://homepage.mac.com/komaruyama/Tutorials/AE/AE_javamail/AE_mail.html), which Apple officially discontinued/took down several years ago.
    Does anyone have any experience with this?

    For Mac, the path is of course slightly different. If you cannot delete the file, you should at least be able to edit it in Extend Script Toolkit or any text editor or run the script separately to change its config data. Works for me...
    Mylenium

  • Need flash player 8 and java script enabled to play videos on ipad, need help please.

    need flash player 8 and java script enabled on my ipad in order to view videos.  please help.

    iPads do not directly support Flash.
    You can look for Flash Browsers in the App store for some options to try. Support is not 100%, but maybe one may work for you.  Browsers like Puffin, Skyfire, Photon etc...
    IPads do fully support JavaScript.  Just make sure its turned on under Settings->Safari->Advanced->JavaScript.
    If you require Java, which is completely different to JavaScript, again there are some browsers in the App store that support it.  Search for "Java browsers" in the store.

  • ICal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed on alert.

    iCal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed.

    Calendar (not called iCal anymore) does not include that capability any longer, apparently.  What you have to do now is go to Automator and create a Calendar Alert action.  You can add a Run AppleScript object to the action and paste in your script there, then when you save it, it will become available as a choice in the alert menu in Calendar.

Maybe you are looking for

  • How to view logs in case of stand alone deployment

    Hi, I have deployed my UI app on a WLS server (A standalone deployment). And my UI has an LOV and i want to find out the exact query that it is firing when i click on the LOV (They query has some bind variables too). So for this i need to see the wls

  • Dynamic selection of records based on checkbox checked

    Hello, I want to select a list of records from a multirecord block by using the checkbox checked values as the criterion and use the records selected in the where clause for querying in another forms. The data from the multirecord block is from a que

  • How can I get redeem code for free upgrade for OS X Lion

    I had register for serial No: of Mac Pro already but not get redeem code for free upgrade OS X Lion. How can I get the redeem code? Best regards, Noiloso

  • Some email with attached files can not be received

    email already recieved by my serverhost cannot be downloaded to my computer. It has to do with the attached files. Most of the time large attached files, especially with an Excel file.

  • How do I search just the Dreamweaver forums?

    Hi all, I must be crazy but I can't seem to see how to search just the Dreamweaver forums. Two search fields, one for all adobe.com and one for searching all forums but no option to search only this one? David