Jump to content

SAP UDF


seangriffin
 Share

Recommended Posts

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 OSS

  • To 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 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

  • 2 months later...

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

  • 1 month later...

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 :graduated:

Edited by KingNED
Link to comment
Share on other sites

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 :graduated:

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 :D

Thanks for this great UDF :D

Link to comment
Share on other sites

  • 7 months later...

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

  • 2 months later...

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

  • 2 months later...

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 :D

Edited by SeF
Link to comment
Share on other sites

  • 2 months later...

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

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 by SeF
Link to comment
Share on other sites

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 :oops:

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

  • 4 months later...

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

post-74219-0-00728400-1341993499_thumb.p

post-74219-0-46609800-1341993727_thumb.p

Link to comment
Share on other sites

  • 7 months later...

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

  • 2 weeks later...

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 by CaoD
Link to comment
Share on other sites

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 7

Scripting Tracker Lite (at bottom of page)

http://bebo.stschnell.de/

Edited by ozmike
Link to comment
Share on other sites

  • 2 months later...

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

  • 8 months later...

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

  • 2 months later...

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...