VS2010 vb.net SAP.net connector Step by step guide to send parameter and get result from BAPI Function

In continuatiuon to my Last Post:



Imports SAP.Middleware.Connector

Public Class ECCDestinationConfig
    Implements IDestinationConfiguration

    Public Event ConfigurationChanged(ByVal destinationName As String, ByVal args As RfcConfigurationEventArgs) Implements IDestinationConfiguration.ConfigurationChanged

    Public Function GetParameters(ByVal destinationName As String) As RfcConfigParameters Implements IDestinationConfiguration.GetParameters

        Dim parms As New RfcConfigParameters

        Select Case destinationName

            Case "DEV"

                parms.Add(RfcConfigParameters.AppServerHost, "10.0.0.47")
                parms.Add(RfcConfigParameters.SystemNumber, "00")
                parms.Add(RfcConfigParameters.SystemID, "ED1")
                parms.Add(RfcConfigParameters.User, "009383")
                parms.Add(RfcConfigParameters.Password, "vvvvv")
                parms.Add(RfcConfigParameters.Client, "100")
                parms.Add(RfcConfigParameters.Language, "EN")
                parms.Add(RfcConfigParameters.PoolSize, "5")
                parms.Add(RfcConfigParameters.PeakConnectionsLimit, "10")
                parms.Add(RfcConfigParameters.IdleTimeout, "600")

            Case Else

        End Select

        Return parms

    End Function

    Public Function ChangeEventsSupported() As Boolean Implements IDestinationConfiguration.ChangeEventsSupported
        Return False
    End Function


End Class




Imports SAP.Middleware.Connector
Public Class Form1
    Private _ecc As RfcDestination
    Public log As String = ""
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Try
            RfcDestinationManager.RegisterDestinationConfiguration(New ECCDestinationConfig)
            _ecc = RfcDestinationManager.GetDestination("DEV")
            Dim repository As RfcRepository = _ecc.Repository

            Dim bapiGetCompanyList As IRfcFunction = repository.CreateFunction("BAPI_COMPANY_GETLIST")
            Dim bapiGetCompanyDETAIL As IRfcFunction = repository.CreateFunction("BAPI_COMPANY_GETDETAIL")

            'populate from SAP
            bapiGetCompanyList.Invoke(_ecc)
            Dim companytable As IRfcTable = bapiGetCompanyList.GetTable("Company_List")
            Dim rfcreturn As IRfcStructure = bapiGetCompanyList.GetStructure("RETURN")

            For companyptr As Integer = 0 To companytable.RowCount - 1
                companytable.CurrentIndex = companyptr
                Dim companynumber = companytable.GetString("COMPANY")
                log = log & companynumber & " " & companytable.GetString("NAME1")
                '' now get value from function by passing parameters
                bapiGetCompanyDETAIL.SetValue("COMPANYID", companynumber)
                'populate from SAP
                bapiGetCompanyDETAIL.Invoke(_ecc)
                Dim rfcreturn1 As IRfcStructure = bapiGetCompanyDETAIL.GetStructure("RETURN")
                Dim companydetail As IRfcStructure = bapiGetCompanyDETAIL.GetStructure("COMPANY_DETAIL")
                log = log & companydetail.GetString("CITY") & companydetail.GetString("STREET") & companydetail.GetString("COUNTRY") & vbCrLf
            Next
            TextBox1.Text = log

           Catch ex As Exception
            TextBox1.Text = log & "Error " & ex.Message

        End Try
    End Sub
    
End Class

Comments

Unknown said…
Hi,
this is good and helpful post.
Could you please share some example that how we can use use Badi ACC_Document in BAPI_ACC_DOCUMENT_POST in table extn1 or extn2. its very urgent.
Thanks in Advance