-2

I am running a script from Excel and would like to loop through rows in a table in order to obtain values for each line in a table. Here is what I basically need to do:

  1. Go to a page with a table in SAP GUI

  2. Double click on a line, which brings me to a window with values that I need to copy and insert in a spreadsheet.

  3. Loop through an entire table in the same fashion and repeat a procedure in SAP GUI.

The attached pictures show tables I am working with. I am not sure which of them are real tables that can be declared as Objects. I tried to run a code but it returns an error which concerns RowCount:

The object does not support this property or method

Code:

Dim Table As Object
Dim rows As Long
Dim i As Long

Set Table = Session.FindById("wnd[0]/usr/cntlUSAGE_TREE_CONTAINER/shellcont/shell/shellcont[1]/shell[1]")
rows = Table.RowCount - 1

For i = 0 To rows
Session.FindById("wnd[0]/usr/cntlUSAGE_TREE_CONTAINER/shellcont/shell/shellcont[1]/shell").selectedNode = "          i"
Session.FindById("wnd[0]/usr/cntlUSAGE_TREE_CONTAINER/shellcont/shell/shellcont[1]/shell").doubleClickNode "          i"

Next i
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
OAltyn
  • 21
  • 8
  • Basically, I would like to loop the following lines: `session.findById("wnd[0]/usr/cntlUSAGE_TREE_CONTAINER/shellcont/shell/shellcont[1]/shell[1]").selectedNode = " 6" session.findById("wnd[0]/usr/cntlUSAGE_TREE_CONTAINER/shellcont/shell/shellcont[1]/shell[1]").doubleClickNode " 6" session.findById("wnd[0]/tbar[0]/btn[3]").press` – OAltyn Aug 27 '18 at 16:33
  • 1
    had you googled this at all? I got this in a second of searching: https://stackoverflow.com/questions/48760731/vba-sap-script-loop-through-sap-table – Ibo Aug 27 '18 at 16:36
  • @Ibo yes I did but it did not show up. I have been googling 2 days, and that page was not in my search. Oh my! Thanks a lot Ibo! – OAltyn Aug 27 '18 at 17:08
  • 2
    `I am looking for confirmation that looping through a table in SAP is feasible.` Of course, it's feasible. Confirm it :) – Suncatcher Aug 27 '18 at 18:01
  • @Ibo can you please confirm if my object is a table at all (please see the picture attached). It seems i cannot apply the similar code to my object. – OAltyn Aug 27 '18 at 18:07
  • @Suncatcher I am new to SAP environment and wondering if my object is actually a table. I know my question is stupid but I am learning en route, trying to figure out the fast solution. – OAltyn Aug 27 '18 at 18:09
  • I don't know SAP and I am not sure if it is a table or not, but it has fields etc so it seems it is a table, I would recommend finding an example and doing the example first so you can make sure of the code and then try to solve your problem – Ibo Aug 27 '18 at 18:11
  • 1
    You haven't given any code, pic or screenshot, so I cannot confirm it's table or not. – Suncatcher Aug 28 '18 at 07:26
  • Related: [Going over a table in SAP returns an error](//stackoverflow.com/q/52046669) – user692942 Aug 28 '18 at 12:52
  • 1
    @Suncatcher I added pictures and some clarification. I would appreciate if you could give me some hints on how to proceed. I am really stuck – OAltyn Aug 28 '18 at 15:43
  • @OAltyn [What is the difference between VB and VBScript](//stackoverflow.com/a/44168928) – user692942 Aug 28 '18 at 15:49
  • @Lankymart i read the thread but it seems I am still not getting why my code returns an error. I declared a table as an object, I tried to run a method on the object but it says it does not support this method. – OAltyn Aug 28 '18 at 16:47
  • @OAltyn What about this *(referring to VBScript)* - *"It is illegal to declare an explicit type when declaring a variable. The `As` keyword is illegal!"*. Honestly the question is too sparce, there is not enough information to piece together what you are doing. The code looks like VBA to me so likely being run inside Excel, but how you interact with SAP from VBA I have no idea. Either way it seems VBScript isn't being used and just confuses the situation further. – user692942 Aug 28 '18 at 17:12
  • Possible duplicate of [VBA pulling data from SAP for dummies](https://stackoverflow.com/a/19456656/692942). – user692942 Aug 28 '18 at 17:18

1 Answers1

0

In my opinion, the attached pictures contain the following contents:

  1. Tree
  2. Table
  3. Grid

The program example refers to a tree.One of the possible solutions might look like this:

Set myTree = Session.FindById("wnd[0]/usr/cntlUSAGE_TREE_CONTAINER/shellcont/shell/shellcont[1]/shell[1]")
rowCount = myTree.GetColumnCol(myTree.GetColumnNames.item(0)).length
rows = rowCount - 1

For i = 0 To rows
 myTree.selectedNode right("          " + CStr(i),11)
 myTree.doubleClickNode right("          " + CStr(i),11)
Next i

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9
  • thanks for always helpful input! It seems working. The code accepts the object myTree but it returns the error: run time error -2147467259 (80004005) in the following line: ` myTree.selectedNode Right(" " + CStr(i), 11)` Any suggestions? (I am googling on this error at the moment) – OAltyn Aug 30 '18 at 16:36
  • it works perfectly! Thank you :) you cannot imagine how many people you made happy by your comments and hints. I have seen so many posts by you! Thanks again! – OAltyn Aug 30 '18 at 18:37
  • One more question: for the third type of objects I have a line: session.findById("wnd[0]/usr/lbl[6,8]) is it actually a table? I am confused as view of a table varies in SAP. – OAltyn Sep 03 '18 at 23:59
  • The third object is a grid. You give an example of a label. This corresponds approximately to the object table. My suggestion: ColumnTitle = session.findById("wnd[0]/usr/lbl[6,1]").text The theory can be explained by Stefan. ;-) – ScriptMan Sep 04 '18 at 09:04
  • thank you a lot! I know who you are referring to ;-) – OAltyn Sep 04 '18 at 15:15