0

When the SAP GUI script searches for data via SAP GUI and finds nothing, it sends us a pop-up message saying "that it has not found any data", how to keep the macro running because later there are other transactions.

 Sub FOS()
 ...
      
On Error GoTo ConsoleAbs
Set Sapgui = GetObject("SAPGUI")
On Error GoTo 0

'transaction1
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87011964"
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxtBUKRS-LOW").Text = "0092"
...


'transaction2

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87012039"
session.findById("wnd[0]/tbar[0]/btn[0]").press
...

End Sub

I've been trying

On Error GoTo ConsoleAbs
Set Sapgui = GetObject("SAPGUI")
On Error GoTo 0

but I'm not sure that's the right solution.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
XDSSIOP
  • 91
  • 3
  • 11
  • Help me, I'm really struggling. – XDSSIOP May 28 '19 at 13:34
  • Your code does not show the necessary information, relevant parts are missing. See [mcve] to improve your question. Also make sure to unclude all variable declarations. – Pᴇʜ May 28 '19 at 14:11
  • Does a new window popup and does it have buttons? Or is the code interrupted because there is a warning down on the status bar? Error handling is a bit different in SAP GUI Scripting. – Josh May 29 '19 at 10:42
  • I also like simplifying starting a transaction by using `session.StartTransaction "S_ALR_87011964"` – Josh May 29 '19 at 10:46

1 Answers1

2

You could try the following.

for example:

Sub FOS()
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP_Application = SapGuiAuto.GetScriptingEngine
Set Connection = SAP_Application.Children(0)
Set session = Connection.Children(0)

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nS_ALR_87011964"
session.findById("wnd[0]").sendVKey 0
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
If session.ActiveWindow.Name = "wnd[1]" Then
   If session.findById("wnd[1]").Text = "Information" Then session.findById("wnd[1]/tbar[0]/btn[0]").press
else
  'do something 
end if

session.findById("wnd[0]/tbar[0]/okcd").Text = "S_ALR_87012039"
session.findById("wnd[0]/tbar[0]/btn[0]").press
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
If session.ActiveWindow.Name = "wnd[1]" Then
   If session.findById("wnd[1]").Text = "Information" Then session.findById("wnd[1]/tbar[0]/btn[0]").press
else
  'do something 
end if
End Sub

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9