0

I need to find the field name references to textboxes in SAP using scripting under VBA!

Gridview doesn't show the names!

 Dim GridView As Object

 If Not IsObject(SapAPP) Then
   Set SapGuiAuto = GetObject("SAPGUI") 
   Set SapAPP = SapGuiAuto.GetScriptingEngine
 End If
 If Not IsObject(SAPConn) Then
   Set SAPConn = SapAPP.Children(0)
 End If 
 If Not IsObject(session) Then
   Set session = SAPConn.Children(0)
 End If
 If IsObject(WScript) Then
  WScript.ConnectObject session, "on"
  WScript.ConnectObject SapAPP, "on"
 End If
 session.FindById("wnd[0]").resizeWorkingPane 150, 31, False
 session.FindById("wnd[0]").resizeWorkingPane 150, 31, False
 session.FindById("wnd[0]/tbar[0]/okcd").Text = "cn46n"
 session.FindById("wnd[0]").SendVKey 0
 session.FindById("wnd[0]/usr/ctxtCN_PROJN-LOW").Text = "P-312313"
 session.FindById("wnd[0]/usr/ctxtCN_NETNR-LOW").Text = "13123123"
 session.FindById("wnd[0]/usr/ctxtCN_NETNR-LOW").SetFocus
 session.FindById("wnd[0]/usr/ctxtCN_NETNR-LOW").CaretPosition = 7
 session.FindById("wnd[0]/tbar[1]/btn[8]").press
 session.FindById("wnd[0]/usr/cntlALVCONTAINER/shellcont/shell").CurrentCellColumn = "STATXT"
 session.FindById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").TopNode = "         23"
 'Set GridView = session.FindById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell")
 Set GridView = session.FindById("wnd[0]/usr/cntlALVCONTAINER/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell")
 session.FindById("wnd[0]/tbar[0]/btn[15]").press

Usually with gridview I can see what the text field names are and extract what I need with something like... MsgBox (" PSPID = ") & GridView.GetCellValue(i, "PSPID")

But I can't find a way to properly id the fields.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Peter
  • 148
  • 1
  • 2
  • 18
  • Set GridView = Session.FindById("wnd[0]/usr/tabsTABCJLE/tabpLEGR/ssubLISTE:SAPLCJWB:0902/tblSAPLCJWBTAB_902/txtPRPS-POST1[3,0]") Then I can use msgbox("test= ") & gridview.text ,which works fine, but still need to find a way to access rows without setting the gridview with a specific syntax ! – Peter May 02 '18 at 16:46

1 Answers1

1

You could try the following:

for i = 0 to 9
msgbox "test = " & Session.FindById("wnd[0]/usr/tabsTABCJLE/tabpLEGR/ssubLISTE:SAPLCJWB:0902/tblSAPLCJWBTAB_902/txtPRPS-POST1[3," & cstr(i) & "]").text
...

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9
  • That works. If you can , tell me where I can get documentation , tutorials or at least a decent book on SAPGUI scripting preferably with examples! ( LOL I feel like I'm doing an ad for home adviser! )But thanks – Peter May 03 '18 at 12:16
  • Although I find it odd that the row is converted to a string with Cstr! Pete – Peter May 03 '18 at 12:24