I am struggling with a case might be simple but turned my day upside down.
Scenario: I access a tcode via GUI Scripting from VBA in Excel. I apply some filters and then execute that finally drops me an ALV Grid table with a dataset.
The challenge is simple. I have a code that is able to handle the conditions where runtime is still OK, but it is supposed to apply a command such as 'Stop Transaction' which is easily available manually but won't make a footprint in the recording ever. Or, at least, I cannot record this simple step.
Just to see it clearly, here we go with the important fragment of the code:
Dim sap_application, Connection, SecondsElapsed, fityirc
Set SapGuiAuto = GetObject("SAPGUI")
Set sap_application = SapGuiAuto.GetScriptingEngine
Set Connection = sap_application.Children(0)
Set session = Connection.Children(0)
'here I use an object to apply the execute button - this way parallel with the SAP runtime, the VBA script can proceed.
perec = session.FindById("wnd/tbar/btn").press
'here we set a loop to check whether system is busy over a certain time then we may interrupt:
Application.Wait (Now + TimeValue("0:00:05"))
SecondsElapsed = SecondsElapsed + 5
fityirc = session.Busy()
Loop Until SecondsElapsed >= 100
If fityirc = True Then
'and here comes the trouble. I cannot figure out what command to apply to simply make the Stop Transaction command work.
'this solution below here won't work as it does only when session is not busy - Stop Transaction could make a good job here.
session.FindById("wnd/tbar/okcd").Text = "/ns000"
ActiveWorkbook.SaveAs Filename:= _
TargetPath1 & "FAILED_" & ExtractName _
, FileFormat:=xlUnicodeText, CreateBackup:=False
Thank you in advance to make this move somewhere.