SAPGui Scripting SystemFocus or GUIFocus.
I can not seem to get the syntax correct for either of these commands.
I have a script and I am trying to determine the inout field where the cursor is placed.
my code looks something like this now, but it is obviously not correct:
msg = session.findbyid("wnd[0]").systemfocus
I am not trying to SET the focus, only determine where the field name where the cursor resides.
Thank you,
Mike
Hello Mike,
try this:
Set Focus = session.ActiveWindow().GUIFocus()
MsgBox Focus.Name & vbCrLf & Focus.Id & vbCrLF & Focus.Type
I hope you get the information you need.
Cheers
Stefan
Similar Messages
-
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,
MikeStandard Excel VBA uses UCASE to convert text to upper case.
-
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,
VirgilioHi Virgilio,
See this link is usefully
Security for the Use of SAP GUI Scripting - eCATT Security Guide - SAP Library
Regards,
Deva -
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.. -
Is it possible to execute SAPGUI scripts from java program?
Hi everyone..
I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
it will be more helpful, if docs related to that are shared..
Thanks in advanceOh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
Thanks for this answer . . .
Sharon -
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
DidierHi 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
ThomasHopefully 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 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 014Standard 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 -
Sapgui scripting - export report to Excel then return to sap
I am new to SAP and my company has just updated to 4.7. I can export a report to MS Excel as spreadsheet, run a excel macro on the spreadsheet in excel, save the excel workbook in a local directory, then close & exit excel. However, I can not get the script to continue after excel is closed. The script does not respond. the following is an example of the code:
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]/usr/ctxtS_POSID-LOW").text = "me24810110"
session.findById("wnd[0]/usr/ctxtS_POSID-HIGH").text = "me24810111"
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[43]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/sub:SAPLSPO5:0101/radSPOPLI-SELFLAG[0,0]").select
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
set ns1=createobject("WScript.shell")
ns1.AppActivate "Microsoft Excel"
ns1.SendKeys "%TMM", True
ns1.SendKeys "PERSONAL.XLS!EOM_Status", True
ns1.SendKeys "%R", True
ns1.SendKeys "%FA H:\2005_Monthly_Status\EOM_CIP_Status.xls ", True
ns1.SendKeys "%Y", True
ns1.SendKeys "%Fx", True
Now... from here, the SAP report that was exported is showing on the screen, but I can't get the script to recognize any of the controls on the screen.
Any help would be greatly appreciated.First, I want to thank you for your response. It's greatly appreciated.
The message box example you sent me does and did work before. I am attaching example code (I've numbered some of the lines of code so we can reference the same code) followed by specific events. Example code follows:
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]/usr/ctxtS_POSID-LOW").text = "me24730110"
session.findById("wnd[0]/usr/ctxtS_POSID-HIGH").text = "me24730111"
session.findById("wnd[0]/usr/ctxtS_POSID-HIGH").setFocus
session.findById("wnd[0]/usr/ctxtS_POSID-HIGH").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
1. session.findById("wnd[0]/tbar[1]/btn[8]").press
2. session.findById("wnd[0]/tbar[1]/btn[43]").press
3. session.findById("wnd[1]/tbar[0]/btn[0]").press
4. session.findById("wnd1]/usr/sub:SAPLSPO5:0101/radSPOPLI-SELFLAG[0,0]").select
5. session.findById("wnd[1]/tbar[0]/btn[0]").press
6. session.findById("wnd[1]/tbar[0]/btn[0]").press
7. set ns1=createobject("WScript.shell")
8. ns1.AppActivate "Microsoft Excel"
9. ns1.SendKeys "%TMM", True
10. ns1.SendKeys "PERSONAL.XLS!EOM_Status", True
11. ns1.SendKeys "%R", True
12. ns1.SendKeys "%FA H:\SAP_Scripts\EOM-Status\t1Data.xls ", True
13. ns1.SendKeys "%Y", True
14. ns1.SendKeys "%Fx", True
15. 'MsgBox session.Id
16. session.findById("wnd[0]/tbar[0]/btn[3]").press
Specific events:
First scenario ... With line 15 (MsgBox) commented out. The script runs great until line 16 . Excel is activated, the report data exported to a spreadsheet, the excel macro executed properly, excel file saved, and excel is exited properly. When the excel app is closed out, the script is left in the same condition as after execution of line 1 (the SAP report data has been selected and is presented in report format) and the excel app is no longer resident. Line 16 depresses the green back arrow and would return SAP to the previous screen. But nothing happens. It's like the script does not see line 16 and ends after excel is closed out in line 14.
Second scenario ... With line 15 (MsgBox) NOT commented out. Excel is activated, the report data exported to a spreadsheet, and the excel macro begins execution. During the excel macro execution, the MsgBox is displayed (/app/con[0]/ses[0]) and everything halts after the ecxel macro completes. When I hit the OK button in the MsgBox, an SAP information modal box is displayed with the caption "Save data in spread sheet". When I hit the green check mark (enter) in the information modal box, I am returned to same condition as after execution of line 1 (the SAP report data has been selected and is presented in report format) however, the excel app is still showing the result of the executed excel macro, the excel file is not saved, and the excel app is still resident. It appears that the script halted when the MsgBox was executed.
Please... any suggestions.??? -
How to execute SAPGUI script from the command line?
I have created a script and would like to execute it from the command line. There must be some flag that goes with SAPGUI.EXE. Any help appreciated.
Thanks,
JeffHi Jeff,
the best way to do this is to run the script using the Windows Script Host, for example like this:
cscript myscript.vbs
This will execute the script which in turn can access SAP GUI. You may however have to make sure the script attaches to the correct session.
Best regards,
Christian -
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.. -
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
HeinrichHi,
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 -
SAPGUI Scripting - Help, Books, Tutorial, Articles
If anyone knows about any good books, help topics, articles, tutorial on SAP GUI Scripting. Please let me know.
Thanks,
_MHi Manoj,
the bulk of the scripting documentation is available at the service market place at http://service.sap.com/~form/sapnet?_SHORTKEY=00200797470000050367
An updated version of the API document is currently in the works.
There is also a book 'ABAP Best Practices', which has a chapter on SAP GUI Scripting. I'm afraid it seems to be available only in German so far.
Best regards,
Christian -
SAPGUI Scripting for a beginner !!
Hi all,
I'm new to this GUI Scripting.Can anyone guide me to start up with this scripting by providing any information,blogs or materials regarding the same.
Regards,
VenkySorry, that was the wrong place.
Regards
ScriptMan
Edited by: ScriptMan on May 22, 2009 11:49 AM
Edited by: ScriptMan on May 22, 2009 2:57 PM
Maybe you are looking for
-
Hello, I am getting the below error messages when I render a TIFF image sequence using default settings. I have double-checked and I have read-write privileges for the file destination. I have also emptied the Disk Cache and Cleaned the Database. My
-
Reg sending Mail with PDF attachment
Hi All, Am converting smartforms(Purchase Order Me23N) to pdf then am attaching pdf in mail,mail is going with attachment to specific id but when i try to open PDF file am getting an Error PDF File is Corrupted. Am using these FM :CONVERT_O
-
Flat file upload (from local system) to internal table
I am trying to use BAPI to create sales order. for that I have to upload flat file containing header and item data from the local system (not from application server). please suggest me if any functional module is available for this. Thanks, Rajan
-
What is the file size that ODI can handle
Hi all, What is the file size that ODI can handle ????????? can it handle 1GB files without any issues????????? Thanks Phani
-
After effects trial Update problem.
Hi, So I downloaded the Adobe After Effects trial, and on my desktop the AdobePatchInstaller appeared alongside two files: payloads & META- INF. I clicked on the Patch Installer ( I believe that was the right thing to do.) then a pop up comes up sayi