0
votes

I'm using C# in order to automate SAP GUI 7.40 with sapfewse.ocx (inspired By How do I automate SAP GUI with c#)

I'stuck with an error on runtime when the script have to double click on leef of a tree.

private GuiApplication sapEngine { get; set; }
private GuiConnection sapConnexion { get; set; }
private GuiSession sapSession { get; set; }

sapEngine = new GuiApplication();
sapConnexion = sapEngine.OpenConnection(sapGUIConfig.EndPoint,Sync:true);
sapSession = (GuiSession)sapConnexion.Sessions.Item(0);

// ...

    GuiTree treeFilters = getTreePath("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell");
                    treeFilters.ExpandNode("          1");
                    treeFilters.SelectNode("         16");
                    treeFilters.TopNode = "         15";
                    treeFilters.DoubleClickNode("         16");
    
                    // Crash Here after DoubleClickNode Method
    

SAP ERROR: "The SAP application had to terminate due to an ABAP runtime error."

Note :

The same automation script manage with sapRotWrapper (SapROTWr.CSapROTWrapper) works

sapROTWrapper = new SapROTWr.CSapROTWrapper();
sapGUIROT = _sapROTWrapper.GetROTEntry("SAPGUI");
//Get the reference to the Scripting Engine
sapEngine = sapGUIROT.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, sapGUIROT, null);

sapConnexion = sapEngine.OpenConnection(sapGUIConfig.EndPoint);
sapSession = sapConnexion.Children(0);

// ...

sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").expandNode("          1");
                sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").selectNode("         16");
                sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").topNode = "         15";
                sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").doubleClickNode("         16");

Is there somebody can help me ?

Note : I've the same graphical troubles on screen during the execution, all components are not well displayed, There's a link ? (like in the question How to Automate SAP GUI 750 with C#)

1
The error indicates that the ABAP application failed, not your script. Log in the SAP system via SAP GUI, run the transaction code ST22 and see if there's a short dump and what it says precisely. In your script, why do you hardcode the node IDs? They are incremented automatically, so they may correspond to unknown values at run time, and may even not exist.Sandra Rossi
I've no access to transaction ST22 with my actual autorisations :(. I've hard coded nodes Ids, because, the script come from a pervious record from Sap (on the same system).Nicolas
You may ask someone... How can you solve an issue if the bug is not of your responsibility -> ask a system administrator or an ABAP developer.Sandra Rossi

1 Answers

0
votes

Since my previous post, after a long time of experimenting unprobably solutions, I've find the way to solve this problem.

It will be resume of a mix of the different set of code i've mentionned.

The objects used to manage the connection and session must be written with sapRotWrapper (

using SAPFEWSELib;
//...
sapROTWrapper = new SapROTWr.CSapROTWrapper();
sapGUIROT = _sapROTWrapper.GetROTEntry("SAPGUI");
//Get the reference to the Scripting Engine
sapEngine = sapGUIROT.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, sapGUIROT, null);

sapConnexion = sapEngine.OpenConnection(sapGUIConfig.EndPoint);
sapSession = sapConnexion.Children(0);

But The access to tree must done with the GuiTree object

GuiTree treeFilters = getTreePath("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell");
                treeFilters.ExpandNode("          1");
                treeFilters.SelectNode("         16");
                treeFilters.TopNode = "         15";
                treeFilters.DoubleClickNode("         16");