cancel
Showing results for 
Search instead for 
Did you mean: 

GUI Script Loses focus when SAP Graphics opens

Former Member
0 Kudos

Hopefully an easy question.

I am new to SAP and am currently using GUI scripts embedded in Excel at the most basic level.

Now I am trying to create one from scratch using the recorder. The problem is that during the my recording a SAP Graphics window opens.

This causes the script to lose focus when I close that Graphics window.

Does anyone know how to close the window and then "regain" focus?

Thanks for your help....I know I am a novice.

Below is my code....


Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/tbar[0]/okcd").Text = "/ncm02"
Session.findById("wnd[0]").SendVKey 0
Session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[0]").Select
Session.findById("wnd[1]/tbar[0]/btn[7]").press 'Hierarchy Selection
Session.findById("wnd[2]/usr/ctxtRC65A-HNAME").Text = "Core Steel" 'Name of Hierarchy
Session.findById("wnd[2]/usr/ctxtRC65A-HWERKS").Text = "4000" 'Plant
Session.findById("wnd[2]/usr/ctxtRC65A-HWERKS").SetFocus
Session.findById("wnd[2]/usr/ctxtRC65A-HWERKS").caretPosition = 4
Session.findById("wnd[2]/tbar[0]/btn[0]").press
'This is where it loses focus

Session.findById("wnd[0]/tbar[1]/btn[6]").press
Session.findById("wnd[0]/mbar/menu[3]/menu[4]/menu[2]/menu[2]").Select
Session.findById("wnd[1]/usr/ssubRAHMEN:SAPLCNFA:0111/subAKT_FELDER:SAPLCNFA:0120/tblSAPLCNFATC_AKT_FELDER").getAbsoluteRow(0).Selected = True
Session.findById("wnd[1]/usr/ssubRAHMEN:SAPLCNFA:0111/subAKT_FELDER:SAPLCNFA:0120/tblSAPLCNFATC_AKT_FELDER/txtAKT_FELDER-SCRTEXT[0,0]").SetFocus
Session.findById("wnd[1]/usr/ssubRAHMEN:SAPLCNFA:0111/subAKT_FELDER:SAPLCNFA:0120/tblSAPLCNFATC_AKT_FELDER/txtAKT_FELDER-SCRTEXT[0,0]").caretPosition = 0
Session.findById("wnd[1]/usr/ssubRAHMEN:SAPLCNFA:0111/subAUSWAHL:SAPLCNFA:0140/btnNICHT_AUSWAEHLEN").press
Session.findById("wnd[1]/usr/ssubRAHMEN:SAPLCNFA:0111/subAKT_FELDER:SAPLCNFA:0120/tblSAPLCNFATC_AKT_FELDER").getAbsoluteRow(0).Selected = True
Session.findById("wnd[1]/usr/ssubRAHMEN:SAPLCNFA:0111/subAUSWAHL:SAPLCNFA:0140/btnNICHT_AUSWAEHLEN").press
Session.findById("wnd[1]/tbar[0]/btn[0]").press
Session.findById("wnd[0]/tbar[1]/btn[5]").press


Accepted Solutions (0)

Answers (1)

Answers (1)

Christian_Cohrs
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Andrew,

the SAP GUI Scripting API does not support these graphics applications. If you need to automate them you would need to use a more advanced tool that allows you to use both the Scripting API and native Windows automation. I've played around a bit with WinBatch. Below is a WinBatch script which opens and closes an external graphics application. I'm not sure this sample report exists in your system but the script should also work with any other graphic.

Best regards,

Christian

SapGuiAuto = ObjectGet("SAPGUI");

Application = SapGuiAuto.GetScriptingEngine;

AllConnections = Application.Children;

Connection = AllConnections.ElementAt(0);

AllSessions = Connection.Children;

Session = AllSessions.ElementAt(0);

session.findById("wnd[0]/tbar[0]/okcd").text = "/nse38";

session.findById("wnd[0]").sendVKey(0);

session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "GRGANT_1";

session.findById("wnd[0]").sendVKey(8);

session.findById("wnd[0]/tbar[1]/btn[8]").press(); This opens the graphics window

WinClose( "Studio-Disposition" );

session.findById("wnd[0]/tbar[0]/okcd").text = "/n";

session.findById("wnd[0]").sendVKey(0);

Message ("My Script", "Done");