0

I am trying to get the table counts from the table and what columns are available in each table. This information I need to get in the Excel sheet with table name, counts, field names. I have generated VBA script. I don't have much access to the SAP GUI. I run SE16 to get the table counts. The below is the script that got generated.

It's very difficult to take the counts one by one entering the table and taking the counts.

I am looking for something to pass the table names as file to the SAP GUI and outputs the results as a file that contains "table name", "counts","field names".

The below code does the login, runs SE16, enters table QPRS, presses Enter and then the button Ctrl+F7 to display the number of entries of the table, and do the same for the next tables, TQ43, TQ43T, TQ45 and TQ45T.

If Not IsObject(application) Then
    Set SapGuiAuto  = GetObject("SAPGUI")
    Set application = SapGuiAuto.GetScriptingEngine
End If

If Not IsObject(connection) Then
    Set connection = application.Children(0)
End If

If Not IsObject(session) Then
    Set session    = connection.Children(0)
End If

If IsObject(WScript) Then
    WScript.ConnectObject session,     "on"
    WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "900"
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "12345"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "*****"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus
session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 12
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "QPRS"
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[31]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "TQ43"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[31]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "TQ43T"
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 5 
session.findById("wnd[0]").sendVKey 0 
session.findById("wnd[0]/tbar[1]/btn[31]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "TQ45"
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 4 
session.findById("wnd[0]").sendVKey 0 
session.findById("wnd[0]/tbar[1]/btn[31]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "TQ45T"
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 5 
session.findById("wnd[0]").sendVKey 0 
session.findById("wnd[0]/tbar[1]/btn[31]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Anonymous
  • 193
  • 1
  • 13
  • 1
    It's really not necessary to post that many lines of code. Please see [mre]. Post the bare minimum amount of code necessary to demonstrate the issue. – Ken White Aug 07 '20 at 00:09
  • @KenWhiteThank you for editing it. Will keep a note of it. – Anonymous Aug 07 '20 at 02:16
  • I'm not sure to understand what is your exact question. I read "Having difficulties", but not a question. Do you simply want to add a line to the script to retrieve the number of lines displayed and store it in a VBA variable? (and then you can place it into the Excel sheet). – Sandra Rossi Aug 07 '20 at 07:17
  • @SandraRossi From SAP gui , i need row counts for some set of tables. and the row counts should be displayed in a excel sheet along with the table name. – Anonymous Aug 07 '20 at 10:12
  • I understand that the requirement is unchanged from what you previously said in your original post, but what did you try and what is your question? See [here how to ask](https://stackoverflow.com/help/how-to-ask). – Sandra Rossi Aug 07 '20 at 12:03
  • I generated a script , from sap gui, to get the record counts of tables. My question is instead of giving tables individually , is there any way to pass the tables in a text file and pass it to the above vba script? And also i need the output in a excel sheet with table name and record counts. Thanks. – Anonymous Aug 10 '20 at 13:53
  • Your first question is how to read a text file, and loop at each line. One possible solution is [answered here](https://stackoverflow.com/questions/11528694/read-parse-text-file-line-by-line-in-vba). Your second question is how to fill data in a worksheet and save it. You will get some possible solutions by recording the action of filling cells manually, via the macro recorder in the Developer tab, reuse the code given by the macro recorder. – Sandra Rossi Aug 11 '20 at 14:47

0 Answers0