Eduardo GS
Eduardo GS

Reputation: 43

How to read the cell value in a table control?

I want to read a cell value on a table - example on transaction C202:

SAP GUI transaction `C202`

I can use SAP GUI Scripting Recorder to "check" or "select" (row = 5, column = 1), which is next to "0122" and (row = 5, column = 1), which is next to "0125", it gives me a simple code:

' selects 0122
session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401").getAbsoluteRow(4).selected = true

'selects 0125
session.findById("wnd[0]/usr/tabsTABSTRIP_RECIPE/tabpVOUE/ssubSUBSCREEN_RECIPE:SAPLCPDI:4401/tblSAPLCPDITCTRL_4401").getAbsoluteRow(7).selected = true

However, the row containing 0122 or 0125 is at a different row. The rows could be different e.g.:

I want to read column = 2 so I know if it's 0122 or 0125 and then check them.

How could I put this value inside a variable and use msgbox to display it?

PSEUDO CODE:

dim readVariable as string

for row = 1 to NumberOfRows
      readVariable = Table.Read (row,2) ' <======== ???
         if readVariable = 0122 then
            msgbox "row = " & row " & " is 0122"
         end if
         if readVariable = 0125 then
            msgbox "row = " & row " & " is 0125"
         end if
next

I tried following Link but I can't get it to work.

Thanks a lot!!!

Upvotes: 1

Views: 8948

Answers (2)

Sandra Rossi
Sandra Rossi

Reputation: 13628

So, you are talking about a GuiTableControl Object.

First solution: to get the field ID, use the recorder, position the caret (text cursor) at the 1st character in the field of the 3rd column of the 4th row (respectively the numbers 2 and 3 as the first occurrence is the number 0), the generated VBS file contains the field ID in the form FIELDNAME[column,row] e.g.:

session.findById(".../tblXXXXX/FIELDNAME[2,3]").caretPosition = 1

You may then use this field ID in your own VBA to get the field value:

cellText = session.findById(".../tblXXXXX/FIELDNAME[2,3]").Text
msgbox cellText

Here is how to refer to a value of a cell at a given row and column, which are both provided as variables:

row = 0
column = 1
cellText = session.findById(".../tblXXXXX/FIELDNAME[" & column & "," & row & "]").Text

Second solution: use the method GetCell:

cellText = session.findById(".../tblXXXXX").GetCell(row,column).Text

You may also need to scroll the rows to read the rows in the next pages, because referring to a row which is not displayed returns an error. This answer about the same topic gives more details about scrolling via SAP GUI Scripting: Reading text in Table Control.

Upvotes: 0

Kacper Witos
Kacper Witos

Reputation: 49

Use '&' instead of a + and you'll get 01101 as VBS will assume that the conversion will be directed to string type and will concat your string with "1" instead of parsing your string to digit type of variable to simply add 1.

Upvotes: 0

Related Questions