0

I am automating my work with SAP GUI script at the moment and whilst trying to recreate the recorded macro I am having an issue at one particular point which I don't know how to translate.

session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").setCurrentCell 1,"MAKTX2"
session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").doubleClickCurrentCell
session.findById("wnd[1]/tbar[0]/btn[0]").press

I have read through the SAP GUI Scripting API pdf and am struggling to see how I action the .setCurrentCell 1,"MAKTX2" part. I am accessing the container cell with the following:

GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

How do I make "materials" double click "MAKTX2"?

Edit: Full SAP GUI script:

SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper();
object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);
GuiApplication GuiApp = (GuiApplication)engine;
GuiConnection connection = (GuiConnection)GuiApp.Connections.ElementAt(0);
GuiSession session = (GuiSession)connection.Children.ElementAt(0);
GuiFrameWindow frame = (GuiFrameWindow)session.FindById("wnd[0]");
GuiTextField jobsite = (GuiTextField)session.FindById("wnd[0]/usr/subSA_0100_1:SAPMZCX_CSDSLSBM5001_OFS_OTS:2410/subSA_2410_1:SAPMZCX_CSDSLSBM5001_OFS_OTS:2510/ctxtKUWEV-KUNNR");
jobsite.Text = "I033";
frame.SendVKey(0);
GuiLabel aggregates = (GuiLabel)session.FindById("wnd[1]/usr/lbl[12,3]");
aggregates.SetFocus();
GuiFrameWindow frame2 = (GuiFrameWindow)session.FindById("wnd[1]");
frame2.SendVKey(1);
GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Logan9Fingers
  • 37
  • 1
  • 3
  • 9

1 Answers1

2

To be honest I can't help you with C#, but perhaps the SAP interface is generic enough anyway. Thing is, session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell") gives you a reference to an object of type GuiShell or GuiContainerShell or whatever it's called. On this reference, you can call the methods defined for this type. So in the same way, when you do

session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").setCurrentCell 1,"MAKTX2"

You're just getting the reference first, and then applying the method setCurrentCell on it, all on the same line.

When you did in C#

GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

you gave this reference a name materials, and provided that line works correctly, I guess you can just say now:

materials.setCurrentCell(1, "MAKTX2")
materials.doubleClickCurrentCell
Nelson Vides
  • 443
  • 4
  • 11
  • Thanks for the help Nelson, the issue I am facing is that there is no setCurrentCell method that I can apply to the materials variable. I will update question with full C# on how I get this far, maybe you can see more clearly and advise how in Visual Basic and I can try and convert!? – Logan9Fingers May 02 '18 at 09:46
  • I think I got it. Perhaps materials is not of type `GuiContainerShell`! Have a look at your findById string: "wnd[0]/shellcont/shell/shellcont[1]/shell", you can see you have a shell inside a shellcont(ainer)! Also, I've just remembered that `.setCurrentCell` was defined for GuiGridView in VBA. Checking here: http://www.synactive.com/download/sap%20gui%20scripting/sap%20gui%20scripting%20api.pdf I can see that the function `.setCurrentCell` is defined only for something of type `GuiCtrlGridView`. Which is a parent of a shell. Try changing the types and check that the cast in material works. – Nelson Vides May 02 '18 at 10:03
  • Amazing, it worked. I would have never found that. Thanks so much. – Logan9Fingers May 02 '18 at 10:14