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

The 3.0 connector doesn't work this way> right click my project and "Add Item" and one of those items should be an SAP Proxy object item. Instead

For Visual Studio 2010, you will need to download the latest one:
Unzip and install to a convenient location on your machine.

Create An App

  • Right click on project and select “Add Reference”
  • When window opens, select “Browse” and navigate to the folder where you installed the SAP Nco Connector.
  • You will need to select the following dll:
  • Sapnco.dll
  • Sapnco_utils.dll
 First, create a class that implements IDestinationConfiguration.  VB.NET code shown below.

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, "")
                parms.Add(RfcConfigParameters.SystemNumber, "00")
                parms.Add(RfcConfigParameters.SystemID, "ED1")
                parms.Add(RfcConfigParameters.User, "009383")
                parms.Add(RfcConfigParameters.Password, "....")
                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

Write your Form code.. have a textbox on form

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
            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")

            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
                log = log & vbCrLf & companytable.GetString("COMPANY") & " " & companytable.GetString("NAME1")
            TextBox1.Text = log

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

        End Try
    End Sub
End Class

Among other errors i get this:
Type 'RfcDestination' is not defined. The referenced assembly "sapnco" could not be resolved because it has a dependency on "System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

Check under Project Properties --> Compile --> Advanced Compile Options.  Is your target framework .NET Framework 4 Client profile?  If so, change this to simply .NET 4 Framework (without the "Client Profile").  System.Web should now be available to import.

SAP BAPI Explorer

Login to your SAP Dev server. SAP’s BAPI Explorer is your source of all the functions, objects, fields and source code to help you. BAPI Explorer is more than a documentation repository. It also provides access to the source code of the RFCs; provides detailed information on the import and export parameters, structures and tables. You can create and test new functions and you can run existing BAPIs to review the data that is being returned. A handy tool is the BAPI list generator. It searches and creates a list of all BAPIs for a particular object. Transaction : BAPI


Use the SAP transaction SE37 to determine the parameters for functions BAPI_COMPANY_GETLIST and BAPI_COMPANY_GETDETAIL. This will tell us what parameters need to be passed in and where to find the results that are returned to our code.

Using the RFCDestination

The next step in this tutorial is to actually use the RFCDestination to connect to a Repository and query the Customer Master Data to return a list of customers and some extra details. Four BAPIs (functions) that will give us the required information are:
Create a new C#/VB class: Customers
Add the SAP Connector in the reference
To hold the data from SAP, define a series of protected properties. The code has been truncated for brevity but the complete source code is included at the end of the tutorial:
Next define method to perform the operations of connecting and retrieving the data from SAP: GetCustomerDetail. The method will take a RfcDestination parameter to pass in the destination from the main program, see section “Putting the Pieces Together” later in this tutorial.

- By Vinod Kotiya


Most Viewed Post

solution for facebook static.ak.fbcdn.net waiting

Connect Sony XPLOD MEX-BT2500 Bluetooth CD Receiver with ur mobile

Crystal Report : Show data horizontally (Left to right) i.e. columns as rows

Google+ Followers