cancel
Showing results for 
Search instead for 
Did you mean: 

How to get data from a table using vb.net

Former Member
0 Kudos

Hi,

    I am new to SAPGUI scripting. Am tring to access a table get some data of it. Am using SAPFEWSE.ocx

i used  SAPFEWSELib and so far i was able to Login and navigate to the table. But I cant extracte specific data from them. Here is my code so far.

Can anyone help me on how to get a value from a table. Am getting error at the redline. PLease help me.


    Private Sub loginInfo()

        sapSession = sapCon.Children(0)

        With sapSession

            ' MsgBox(.FindById("wnd[0]/usr/txtRSYST-MANDT").Text)

            ' .FindById("wnd[0]/usr/txtRSYST-MANDT").Text = "200"

            ' MsgBox(.FindById("wnd[0]/usr/txtRSYST-MANDT").Text)

            .FindById("wnd[0]/usr/txtRSYST-BNAME").Text = sapID

            .FindById("wnd[0]/usr/pwdRSYST-BCODE").Text = sapPassword

            .FindById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

            .FindById("wnd[0]").SendVKey(0)

        End With

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Try

            ' sapID = TextBox1.Text

            'sapPassword = TextBox2.Text

            sap = CreateObject("SAPGUI.Scriptingctrl.1")

            sapCon = sap.OpenConnectionByConnectionString(sapServer, True)

            Create_File()

            loginInfo()

            prcss_data

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

    End Sub

    Private Sub prcss_data()

        With sapSession

            .FindById("wnd[0]/tbar[0]/okcd").text = "se16"

            .FindById("wnd[0]").sendvKey(0)

            .FindById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "zu1cd_fkkvkp"

            .FindById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 12

            .FindById("wnd[0]").sendVKey(0)

            '.FindById("wnd[0]/usr/ctxtI1-LOW").text = "W573121387"

            '.FindById("wnd[0]").sendVKey(8)

            '.FindById("wnd[0]/usr/ctxtI1-LOW").text = ""

            .FindById("wnd[0]/usr/ctxtI1-LOW").caretPosition = 0

            .FindById("wnd[0]").sendVKey(8)

            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell(-1, "GPART")

            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn("GPART")

            .FindById("wnd[0]/tbar[1]/btn[40]").press

            Dim stt As String

            For i = 1 To 10

                stt = .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell(1, 3)

                .FindById("wnd[0]/usr/txtI2-LOW").caretPosition = 10

                .FindById("wnd[0]/usr/txtI2-LOW").setFocus

                Write_log(stt)

            Next

            .FindById("wnd[0]").sendVKey(3)

            .FindById("wnd[0]/usr/ctxtI1-LOW").text = "0200000882"

            .FindById("wnd[0]/usr/txtI2-LOW").setFocus

            .FindById("wnd[0]/usr/txtI2-LOW").caretPosition = 10

            .FindById("wnd[0]").sendVKey(8)

            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "OFFCYCLE"

            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").firstVisibleColumn = "BUSINITCODE"

        End With

    End Sub

    Dim fs As Object

    Dim fs_file As Object

    Dim fname As String

    Private Sub Write_log(ByVal linestr As String)

        fs_file.writeline(linestr)

    End Sub

    Private Sub Create_File()

        fs = CreateObject("Scripting.FileSystemObject")

        fname = My.Application.Info.DirectoryPath + "\Log" + Date.Now.ToString("yyyyMMddHHmmss") & ".csv"

        fs_file = fs.CreateTextFile(fname, True)

    End Sub

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello bhagavath,

welcome in the Scripting Language forum.

If you want to read the content of a cell of the GuiGridView object in the SE16 transaction code you must use the method GetCellValue. Replace the code inside your loop with this:


For i = 1 To 10 

  stt = .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").getCellValue(i, "YourColumnName"

  .FindById("wnd[0]/usr/txtI2-LOW").caretPosition = 10 

  .FindById("wnd[0]/usr/txtI2-LOW").setFocus 

Write_log(stt) 

Next 

Note that your must use the name of the column and not the number.

You can find an interesting example here.

Let us know your results.

Hint: In the actual help file of the SAP GUI Scripting 7.40 PL 7 is the method GetCellValue not longer documented. I hope that doesn't mean anything.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan Schnell,

           Thanks for the help,That is exactly what i was looking for. I have so many question regarding SAP GUI scripting will ask for your help if i cant figure it out. Thanks once again for you help..

stefan_schnell
Active Contributor
0 Kudos

Hello bhagavath,

your are welcome.

Cheers

Stefan

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Stefan,        Could you Please look into this Post and help me Out? http://scn.sap.com/thread/3894333