on 2020 Oct 28 5:12 PM
Hello,I'm trying to read out data from diffrent transactions in SAP through the scripting function.I already did it successfully in VBA, now I want to do it with Python to run the scripts outside of the Microsoft Office environment.
I am new to Python and realised to handle errors is quite different than in VBA. For some processes I use the try and exception
handling, there where I know how the code shall process after an error appeared.
But what if an unexpected error occurs? My problem is I want to continue with the Try
block where the error occurs after I handle the error event in the exception
block but I learnt in Python it is not possible. Something like On Error Resume Next
doesn't exist. To wrap every code line in try
exception
block of the large script can't be the single solution.
Is there a possibilty when the main code interrupts, a second event shall be fired to handle the error and after that the main code shall continue?
Especially for my problem the main idea is an error/pop up window in SAP should be traced and closes by a second event while the main event is paused and continues when the first event finishes.
Thanks in advance.
Request clarification before answering.
Hello,
thanks for your solution, to solve such problems in VB is not a big deal.
Quote: "...then pass it the session & then come back for the rest of the flow..."
That's the issue, I can't pass such functions in the session block because such popup can occurs anytime/anywhere, even if there are only finite places. To find the exact spots in every transaction makes it more complicated. Moreover to jump "back" to the rest of the code after handling an error in python is not possible (or till now I am not aware of it).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
there are generally finite places the scripted process will raise an "unexpected pop-up"
my strategy would be the same as in VBA, & its not on error resume next.
its functionally test for the presence of something & then have logic to address it.
For simple cases I'd check the button on the window exists:
'###catch not existing elements###
If Not session.findById("wnd[1]/usr/btnBUTTON_2", False) Is Nothing Then
session.findById("wnd[1]/usr/btnBUTTON_2").press
End If
for more complex stuff:
Dim pop As SAPFEWSELib.GuiModalWindow
Set pop = session.FindById("wnd[1]")
'check if pop is not nothing
'then do something
pop.FindById("tbar[0]/btn[0]").Press
I've even made subroutines just called CheckForUnexpectedPopups()
then pass it the session & then come back for the rest of the flow.
I imagine there is trivial equivalents in python.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
12 | |
9 | |
8 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.