Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Vb.net calling is BAPI failing.

Former Member
0 Kudos
319

Hello all,

I've created a BAPI in ecc6 which basically looks up a customer name for a given Vbeln no.

I have successfully exposed this BAPI externally and I can see it via my .net application and parts of the structure while debugging.

The problem I'm having is that my program is failing when I try to get the table results back out when stepping through.

or maybe I've not successfully passed in the input?

Using the VB example here http://scn.sap.com/thread/1876430 by Case Ahr, and tweaking it, I have concocted the following sub routine..

  Private Sub CheckExists()

        Dim StrNo As String = "87233483"

While Not String.IsNullOrEmpty(StrNo.Trim)

            ' create a function object

            Dim myAPI As IRfcFunction = _ecc.Repository.CreateFunction("Z_BAPI_OCR_SCAN")

            ' prepare input parameters ( ZOcrSearch is the import structure - single value )

            Dim impStruct As IRfcStructure = myAPI.GetStructure("ZOCRSEARCH")

            impStruct.SetValue("DELNO", StrNo)

           

          ' fill the table parameter ( ZItemData is the export table, holding my results. )

            Dim rfcTable As IRfcTable = myAPI.GetTable("ZITEMDATA")

            Dim i As Integer = 0

            Do While (i < 1)

                Dim row As IRfcTable = CType(rfcTable.Clone, IRfcTable)

                impStruct.SetValue("DELNO", StrNo)

               ' THIS IS THE BIT WHERE ITS ALL GETS A BIT HAZY FOR ME.

                '  rfcTable.Append(row)

                i = i + 1

              Loop

            myAPI.Invoke(_ecc)

          ' this line fails also.
            Form1.TxtSAPoutput.Text += myAPI.GetTable("ZITEMDATA").GetString("Zvbeln").ToString


          ' clear the value to stop the loop.

            StrNo = Nothing

End While

   

End Sub

I've been trying for about 8 hours to get this working and its driving me crazy.

Can anyone shed any light on how to get the data back out of the BAPI

Many thanks in advance.

Dave

1 ACCEPTED SOLUTION

Former Member
0 Kudos
110

Hello all,

I've managed to get a little closer now with this sub routine, 

I can query the BAPI and return a list of field names from the output table.

But I can't get the data out..

Any ideas?

Private Sub GetCompanyName()

Dim StrNo As String = "87233483"

       

While Not String.IsNullOrEmpty(StrNo.Trim)

           

' create a function object           

Dim myAPI As IRfcFunction = _ecc.Repository.CreateFunction("Z_BAPI_OCR_SCAN")

' prepare input parameters           

Dim bintable As IRfcTable = myAPI.GetTable("ZITEMDATA")

Dim impStruct As IRfcStructure = myAPI.GetStructure("ZOCRSEARCH")

            impStruct.SetValue("DELNO", StrNo)

 

Dim am As RfcStructureMetadata = _ecc.Repository.GetStructureMetadata("ZITEMDATA")

Dim row As IRfcStructure = am.CreateStructure()

            myAPI.Invoke(_ecc)

            Form1.TxtSAPoutput.Text += row.Item(0).ToString & vbCrLf
            Form1.TxtSAPoutput.Text += row.Item(1).ToString & vbCrLf
            Form1.TxtSAPoutput.Text += row.Item(2).ToString & vbCrLf           
            Form1.TxtSAPoutput.Text += row.Item(3).ToString & vbCrLf
            Form1.TxtSAPoutput.Text += row.Item(4).ToString & vbCrLf

            Form1.TxtSAPoutput.Text += row.Item(5).ToString & vbCrLf

' clear the value to stop the loop.

            StrNo = ""

Nothing

End While

End Sub

many thanks

Dave

3 REPLIES 3

Former Member
0 Kudos
111

Hello all,

I've managed to get a little closer now with this sub routine, 

I can query the BAPI and return a list of field names from the output table.

But I can't get the data out..

Any ideas?

Private Sub GetCompanyName()

Dim StrNo As String = "87233483"

       

While Not String.IsNullOrEmpty(StrNo.Trim)

           

' create a function object           

Dim myAPI As IRfcFunction = _ecc.Repository.CreateFunction("Z_BAPI_OCR_SCAN")

' prepare input parameters           

Dim bintable As IRfcTable = myAPI.GetTable("ZITEMDATA")

Dim impStruct As IRfcStructure = myAPI.GetStructure("ZOCRSEARCH")

            impStruct.SetValue("DELNO", StrNo)

 

Dim am As RfcStructureMetadata = _ecc.Repository.GetStructureMetadata("ZITEMDATA")

Dim row As IRfcStructure = am.CreateStructure()

            myAPI.Invoke(_ecc)

            Form1.TxtSAPoutput.Text += row.Item(0).ToString & vbCrLf
            Form1.TxtSAPoutput.Text += row.Item(1).ToString & vbCrLf
            Form1.TxtSAPoutput.Text += row.Item(2).ToString & vbCrLf           
            Form1.TxtSAPoutput.Text += row.Item(3).ToString & vbCrLf
            Form1.TxtSAPoutput.Text += row.Item(4).ToString & vbCrLf

            Form1.TxtSAPoutput.Text += row.Item(5).ToString & vbCrLf

' clear the value to stop the loop.

            StrNo = ""

Nothing

End While

End Sub

many thanks

Dave

0 Kudos
110

.....

0 Kudos
110

After a lot of digging, I have managed to find a work around using the RFC_READ_TABLE method.

its a shame that the .net connector 3 doesn't work / or that there isn't enough exposure to it on the web..