Skip to Content
avatar image
Former Member

How to pass a variable containing a string to findById

Hello,

I have the following code that I want to simplify in order to be able to iterate thru a Table.

Original Code

.findById("wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-IDNRK[2,3]").SetFocus

My New Code

col_item = 2
row_item = 3

table_id = "wnd[0]/usr/tabsTS_ITOV/tabpTCMA/ssubSUBPAGE:SAPLCSDI:0152/tblSAPLCSDITCMAT/ctxtRC29P-IDNRK"

table_item = table_id & "[" & Str(col_item) & "," & Str(row_item) & "]"    'String concatenation to iterate through Table.findById(table_item).SetFocus   

My code stops working when it reaches the .findById(table_item).SetFocus line. It says it can't find ID.

Do you have any recommendations.

Thank you for your help.

Carlos De La Cruz.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 09 at 10:07 AM

    Hello Carlos,

    welcome in the SAP Community.

    Your code works, but you must use CStr instead Str. I tried it with another table, here the code:

    col_item = 2
    row_item = 3
    table_id = "wnd[0]/usr/tblSAPMBIBSTC535/txtLOOP510-F3"
    table_item = table_id & "[" & CStr(col_item) & "," & CStr(row_item) & "]"
    session.findById(table_item).SetFocus
    

    Cheers
    Stefan

    Add comment
    10|10000 characters needed characters exceeded