on 2019 Nov 19 8:57 AM
Hi,
I have several questions
1. Is it possible to not traverse object tree each time i want to access specific field?
So far i use Object.children.item() and so on. But it seems that anyway SAP traverse all the elements.
I thought it would be more performant but after profiling it seems not.
How to avoid that? Keep some kind of cache to access elements directly
2. Some GUI events doesn’t work: Hit, Error.
I catch them from Session object (Session_Hit, etc).
CreateSession and DestroySession works just fine.
The idea is same as built-in recorder: listen to user events and record script but with different payload (trying to avoid continuous session.FindById... and make element names human-readable).
Thank you in advance!
Request clarification before answering.
Hello Conrad,
very interesting questions and a very interesting perspective.
1. I have never done a profiling of this kind. Here my example:
TStart = Timer()
For i = 1 To 100
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = CStr(i)
Next
TEnd = Timer()
MsgBox CStr(TEnd - TStart) 'Result 0,8
Set Field = session.findById("wnd[0]/usr/txtRSYST-MANDT")
TStart = Timer()
For i = 1 To 100
Field.Text = CStr(i)
Next
TEnd = Timer()
MsgBox CStr(TEnd - TStart) 'Result 0,4
It's about twice as fast to work with objects instead of the findById with the ID.
Wow...
sandra.rossi and you give the answer, cache the UI element in an object. I don't know another way.
2. The hit event works with the following example.
Sub ses_Error(Sess, ErrID, Desc1, Desc2, Desc3, Desc4)
MsgBox(Desc1 & vbCrLf & Desc2 & vbCrLf & Desc3 & vbCrLf & Desc4)
End Sub
Sub ses_Hit(Sess, Comp, IObj)
MsgBox(IObj) 'Works perfect
End Sub
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children(0)
Set session = connection.Children(0)
If IsObject(WScript) Then
WScript.ConnectObject session, "ses_"
End If
'-To use hit event it is necessary to set this property-----------------
session.findById("wnd[0]").ElementVisualizationMode = True
MsgBox "Press to end"
I can't simulate the error event, but I assume this code example works.
How do you simulate an access denial to a a SAP GUI ActiveX control in a running script?
Let us know your experience.
Best regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In SAP GUI for Windows, there is the Recorder in the System menu, which records your input and generate a VBScript.
It generates this kind of lines:
set field = FindById( "/app/con[0]/ses[0]/wnd[0]/usr/lblRS38M-PROGRAMM" )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi everybody. Sorry for such a late reply.
It seems that there's misunderstanding.
Set ScreenA = Session.FindById("BLA")
Set ScreenB = Session.FindById("BLABLA")
ScreenB.DoubleClick 'entered 2nd screen.
ScreenB.MoveBack 'entered 1st screen.
ScreenA.Text 'object is not available anymore because SAP cleaned reference.
Set ScreenA = Session.FindById("BLA") 'so you've to find it again which is obviously costy. I often faced with such an operation in loop where you have to switch between 2 screens.
So the original question is that how can i keep reference to ScreenA between screen change?
I think it's limitation of host application (SAP) so its should be changed from there. But maybe there's some workaround exist which i'm unaware of.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.