water Posted August 6, 2010 Share Posted August 6, 2010 (edited) Just for the records:I'm using the SAP UDF with SAPGUI 7.20 and Windows 7 without problems (so far).I had problems running Scripting on SAPGUI 7.10 on Windows XP SP2 at all. Even the SAPGUI record and playback function didn't work and always returned (Error)(03.08.10 16:08:57.262): LoadLibrary failed for sapfewse.ocx (Error) : CMainFrame::RecordScript: pSessionDispatch is NULL Not sure if this is a problem with our installation or with SAPGUI. Could not find anything related on SAP OSSTo make scripting run i had to set a server parameter: "In order to use scripting within SAP GUI you need to activate several settings. First one is on level of your SAP application server by instance profile parameter: sapgui/user_scripting = TRUE This parameter is set to false by default. You can do this modification via TA RZ11."And last but not least: Thank you Sean for this great UDF! Edited August 6, 2010 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Klumhru Posted October 11, 2010 Share Posted October 11, 2010 Hi I've gotten as far as attaching and being able to enter actions, but I'm stuck on finding object IDs in the SAP gui. When I select Script Development Tools in the customize menu nothing happens. The menu closes is all. We've turned on scripting on the test server as per the previous post, and _SAPSessAttach and _SAPObjValueSet are working. Has anyone had this problem and been able to resolve it? Best Regards Högni Gylfason Link to comment Share on other sites More sharing options...
Klumhru Posted October 11, 2010 Share Posted October 11, 2010 In reply to my own question (sorry) I recorded macros to find out the object IDs. The IDs are embedded in strings there and after removing "/win[0]/" from the beginning of the string everything works fine. Regards Hg Link to comment Share on other sites More sharing options...
KingNED Posted November 24, 2010 Share Posted November 24, 2010 (edited) Been using this UDF lately, works quite nicely, though there are some transactions that give you a popup box instead of displaying it on the regular page, that causes a problem, since it's not attaching to the popup, and causes an error. *edit: Both screens have the same title* $sap_session.findById("wnd[" & $sap_window_num & "]/" & $object_id).text = $object_value $sap_session.findById("wnd[" & $sap_window_num & "]/" & $object_id)^ ERROR The $sap_window_num should go up 1, then it 'should' work. Any tricks available to find out whether one of the $sap_window_num's work? thanks in advance Edited November 24, 2010 by KingNED Link to comment Share on other sites More sharing options...
KingNED Posted November 24, 2010 Share Posted November 24, 2010 Been using this UDF lately, works quite nicely, though there are some transactions that give you a popup box instead of displaying it on the regular page, that causes a problem, since it's not attaching to the popup, and causes an error. *edit: Both screens have the same title* $sap_session.findById("wnd[" & $sap_window_num & "]/" & $object_id).text = $object_value $sap_session.findById("wnd[" & $sap_window_num & "]/" & $object_id)^ ERROR The $sap_window_num should go up 1, then it 'should' work. Any tricks available to find out whether one of the $sap_window_num's work? thanks in advance Fixed it, I now look with WinExists if the second instance of the object exists, then do $sapnum (which is $sap_window_num but then in another variable to not change the global) += 1, and hey, it works! Me's happy Thanks for this great UDF Link to comment Share on other sites More sharing options...
JohnMiyagi Posted July 14, 2011 Share Posted July 14, 2011 Hi, I'm trying to implement the SAP UDF into a automation spreadsheet that I use. Essentially I would like to create a number of scripts to perform different tasks, that will allow me to using spreadsheets setup 200 of one task and then once completed begin 300 of a different task so that I can go to my meetings without checking it. However I'm looking to get the current transaction code and username so that once complete I can then go back and debug any lines that failed (for tasks that cross more than one transaction screen). I can't seem to find a way to bring back the current environment/client number/username/tcode etc. When I do a hit test on the bottom right hand corner thing it only picks up the status bar as one big control. Any ideas? Link to comment Share on other sites More sharing options...
Donnovan Posted September 20, 2011 Share Posted September 20, 2011 seangriffin, Considering all the automation you did with SAP, have you missed a "_SAPWaitLoad()" function, like the "_IEWaitLoad()" function we have on the IE UDF? For example, on this script, taken from a preview post, i see the function sleep(1000) was used to make the script wait SAP to load, but this is a bad way to do it. #include <SAP.au3>_SAPSessAttach("SAP Easy Access")_SAPObjValueSet("tbar[0]/okcd", "XD02")_SAPVKeysSend("Enter")sleep(1000)_SAPSessAttach("Cliente modificar: 1ª tela")_SAPObjValueSet("usr/ctxtRF02D-KUNNR", "123456") How have you dealed with script and SAP syncronization? Since i will automate SAP to do a man work, repeating a process thousand of times, i really need to sync script and SAP to prevent the script to flood SAP with commands. If the script reachs "round" 5 and SAP is still on "round" 2, for sure some error will occurs. Link to comment Share on other sites More sharing options...
SeF Posted December 7, 2011 Share Posted December 7, 2011 (edited) seangriffin, Considering all the automation you did with SAP, have you missed a "_SAPWaitLoad()" function, like the "_IEWaitLoad()" function we have on the IE UDF? For example, on this script, taken from a preview post, i see the function sleep(1000) was used to make the script wait SAP to load, but this is a bad way to do it. #include <SAP.au3> _SAPSessAttach("SAP Easy Access") _SAPObjValueSet("tbar[0]/okcd", "XD02") _SAPVKeysSend("Enter") sleep(1000) _SAPSessAttach("Cliente modificar: 1ª tela") _SAPObjValueSet("usr/ctxtRF02D-KUNNR", "123456") How have you dealed with script and SAP syncronization? Since i will automate SAP to do a man work, repeating a process thousand of times, i really need to sync script and SAP to prevent the script to flood SAP with commands. If the script reachs "round" 5 and SAP is still on "round" 2, for sure some error will occurs. I process thousands of times without any sleep(). From my experience, SAP commands will be executed only when the last command is finished or when SAP interface is active/"free" again... I don't use sean's UDF, but I believe it works the same way. Here your script converted to AutoIt from SAP script (vbs): ; SAP Attach. $SapGuiAuto = ObjGet("SAPGUI") $application = $SapGuiAuto.GetScriptingEngine $connection = $application.Children(0) $session = $connection.Children(0) $session.findById("wnd[0]/tbar[0]/okcd").text = "XD02" $session.Children(0).sendVKey(0) ;Same as Enter input $session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").text = "12345" ;There is no need to attach again... By the way, I work a lot with SAP in portuguese too and with XD02 transaction. I can help you If you need Edited December 7, 2011 by SeF Link to comment Share on other sites More sharing options...
Zoldex Posted March 6, 2012 Share Posted March 6, 2012 Hi! I'm quite a novice in COM coding, and i'm trying to automate some processes with PowerSAP. Actually using a mix of SAP udf and direct COM access... I'm encountering problems while trying to select a menu item which may no longer exist (or greyed)... when the item is enabled the script works fine! How can I check a menu item status? $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select C:\AutoSAP.au3 (339) : ==> The requested action with this object has failed.: $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select^ ERROR Link to comment Share on other sites More sharing options...
SeF Posted March 6, 2012 Share Posted March 6, 2012 (edited) Hi! I'm quite a novice in COM coding, and i'm trying to automate some processes with PowerSAP. Actually using a mix of SAP udf and direct COM access... I'm encountering problems while trying to select a menu item which may no longer exist (or greyed)... when the item is enabled the script works fine! How can I check a menu item status? $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select C:AutoSAP.au3 (339) : ==> The requested action with this object has failed.: $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select^ ERROR I don't know how to check a menu item status, but you can use an "error handler". Like: $oMyError = ObjEvent("AutoIt.Error","SAP_Error") Func SAP_Error() MsgBox(0, "SAP", "Can't find the specified menu item!") Endfunc $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select Edited March 6, 2012 by SeF Zoldex 1 Link to comment Share on other sites More sharing options...
Zoldex Posted March 9, 2012 Share Posted March 9, 2012 I don't know how to check a menu item status, but you can use an "error handler". Like: $oMyError = ObjEvent("AutoIt.Error","SAP_Error") Func SAP_Error() MsgBox(0, "SAP", "Can't find the specified menu item!") Endfunc $SAP_Session.findById("wnd[0]/mbar/menu[3]/menu[1]").select Oh, many thanks for your fast answer, i thought i was following the topic but i didn't receive any notification about your answer. I'm still trying to understand how the error handler works anyways.... it works! I also found that sap udf has it's own error handler (_SAPErrorHandlerRegister()), unfortunately in my script I was launching it before the include of sap.au3 Look what I got after moving it in the proper place: err.number is: -2147352567 err.windescription: err.description is: The menu item is disabled. err.source is: SAP Frontend Server err.helpfile is: C:\Programmi\SAP\FrontEnd\sapgui\sapfront.HLP err.helpcontext is: 393215 err.lastdllerror is: 0 err.scriptline is: 342 err.retcode is: 623 ...another small lesson learned. Thanks to SeF for help and to Seangriffin for UDF! Link to comment Share on other sites More sharing options...
haraldschweitzer Posted July 11, 2012 Share Posted July 11, 2012 Hi,I've started to use the SAP UDF and now I find it really helpful! It makes daylie work with SAP so much more efficient. Thank you for this great job, Sean.My questions:1.) Has anyone ever managed the navigation between "Tabs"? (See first screenshot)For example: Just using "_SAPObjValueSet" for a Textfield within another tab doesn't work, it seems that the actual tab has to be "selected" / "in focus" to get "_SAPObjValueSet" to work.As a workaround, at the moment I use a sequence of Autoit-commands like (<tab>-<tab>-<right>-<right>-<enter>) to select another tab, but this is error-prone because it requires the cursor to be on a exact position before starting the Autoit sequence.2.) Is it possible to "select" a specific item of a "Tree"? What I wanted to do is select all items of the tree one after another. See second screenshot.Thanks a lot for your tips,Harald Link to comment Share on other sites More sharing options...
crazycrash Posted February 11, 2013 Share Posted February 11, 2013 Like the previous poster was asking I am looking for the same feautre. Is there a way to set the caret position with this udf? SAP Script Recorder: session.findById("wnd[0]/usr/tblSAPLCUKDTC_RCUKD/ctxtRCUKD-KNNAM[1,6]").setFocus session.findById("wnd[0]/usr/tblSAPLCUKDTC_RCUKD/ctxtRCUKD-KNNAM[1,6]").caretPosition = 14 Thanks! Link to comment Share on other sites More sharing options...
crazycrash Posted February 11, 2013 Share Posted February 11, 2013 Answering my own question: MsgBox(0, "Extracted Field", _SAPObjValueGet("usr/tblSAPLCUKDTC_RCUKD/txtRCUKD-KNKTX[2,3]")) So one can read the table like an array, however, only the visible fields. Zoldex 1 Link to comment Share on other sites More sharing options...
crazycrash Posted February 11, 2013 Share Posted February 11, 2013 Answering my own question, part 2: To move the carret to a position in the table: $sap_session.findById("wnd[" & $sap_window_num & "]/" & "usr/tblSAPLCUKDTC_RCUKD/txtRCUKD-KNKTX[2,3]").setFocus Zoldex 1 Link to comment Share on other sites More sharing options...
CaoD Posted February 20, 2013 Share Posted February 20, 2013 (edited) Hi All, Not sure if there is a lot of people still reading this but I'll try it anyway..... I managed to get past a lot of issues by trial and error but as others, I am dead stuck on the "tab selection" issue... I thought of the same workaround as above but it would be really interesting to have the function integrated in the SAP UDF I read the SAP UDF thouroughly and I think that the problem comes frome the fact that the "tabs" are a particular type of SAP Object - GuiTab if I'm not mistaken - and that object is not covered in the "supported objects" of the _SAPObjectSelect function description I'm not good enough at writing functions as to integrate it, I will try to come up with something based on the current contents of the function but I think that some help would be highly appreciated. This is what I get from a test hit on the tab I need to select /app/con[0]/ses[0]/wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2000/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1102/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_03 It looks to me as the previous poster found the solution but It's not clear to me how I can apply it to my situation... Congrats to all for the work done so far!!! Edited February 20, 2013 by CaoD Link to comment Share on other sites More sharing options...
ozmike Posted February 26, 2013 Share Posted February 26, 2013 (edited) the author of this UDF (Sean) ...no longer works in the SAP world - so you guys are on your own!Important note , in windows 7 the SAP script development tools (wizard) no longer works. Script recording and still does (see transaction rz11 to turn on)If you need to identify controls this tool is useful...SAP wizard mimic for windows 7Scripting Tracker Lite (at bottom of page)http://bebo.stschnell.de/ Edited March 28, 2013 by ozmike Link to comment Share on other sites More sharing options...
CaoD Posted May 6, 2013 Share Posted May 6, 2013 Hey there, after some research and some free programming courses from MIT on the web... I managed to better understand the SAP UDF Function and how to amend it to serve my needs. I was basically just in need to be able to select a "Tab" in SAP (see a few posts above). The solution was actually pretty simple... I just had to change a few characters while adding one more "Case" in the _SAPObjSelect Basically, I just added the following : ; Tab Case StringInStr($object_id, "/tab") > 0 $sap_session.findById("wnd[" & $sap_window_num & "]/" & $object_id).select Saved this into a SAP2.Au3 that I called in as an Include (removing the original SAP.Au3) and now I'm able to move from Tab to Tab without getting any annoying error messages... Not sure if it's worth updating the whole UDF.... yet. Maybe in the same manner I added the GuiTab selection there are other objects that could be added... Link to comment Share on other sites More sharing options...
Tblades Posted January 17, 2014 Share Posted January 17, 2014 Hello All, Found this UDF a this week and it has already revolutionized my code. Previously we were using mouse clicks everywhere. I have now removed most of the mouse clicks but they still remain in 1 case. This is where we use a drop-down to select a option. The SAP script shows the following session.findById("wnd[0]/usr/cntlZ_ALV/shellcont/shell").pressToolbarContextButton "&MB_EXPORT" session.findById("wnd[0]/usr/cntlZ_ALV/shellcont/shell").selectContextMenuItem "&XXL" Does anyone know how i can implement this in AutoIT? Thanks in advance. Link to comment Share on other sites More sharing options...
Tuokki Posted March 19, 2014 Share Posted March 19, 2014 @Tblades I had problems with .selectContextMenuItem, used .selectContextmenuItemByPosition instead. My code: $session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell[0]").pressContextButton("SELECT") $session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell[0]").selectContextMenuItemByPosition("4") Try this: $session.findById("wnd[0]/usr/cntlZ_ALV/shellcont/shell").pressToolbarContextButton("&MB_EXPORT") $session.findById("wnd[0]/usr/cntlZ_ALV/shellcont/shell").selectContextMenuItem("&XXL") If the 2nd line does not work, use the .selectContextMenuItemByPosition method. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now