How to extract data from SAP using .NET provider.


To extract using SSIS, you need to have access to backend system. You can use .NET connector and write a Windows application that extracts data from SAP system using Function Module.

For more details on how to connect SAP using .NET connector, you can refer this blog-

With use of BAPI’s you can allow external applications to access business processes and data in R/3 system. Below code is used to make call to BAPI. First is to create a class that implements IDestinationConfiguration −

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
   Dim parms As New RfcConfigParameters
   Select Case destinationName
      Case "ECDCLNT140"
     parms.Add(RfcConfigParameters.AppServerHost, "")
     parms.Add(RfcConfigParameters.SystemNumber, "00")
     parms.Add(RfcConfigParameters.SystemID, "ECD")
     parms.Add(RfcConfigParameters.User, "username")
     parms.Add(RfcConfigParameters.Password, "secret")
     parms.Add(RfcConfigParameters.Client, "140")
     parms.Add(RfcConfigParameters.Language, "EN")
     parms.Add(RfcConfigParameters.PoolSize, "5")
     parms.Add(RfcConfigParameters.MaxPoolSize, "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

Next is to create a Web Services which used .Net 3.0 connector to call RFC Function Module.

Imports SAP.Middleware.Connector
   Module Driver
      Private _ecc As RfcDestination
      Sub Main()
         RfcDestinationManager.RegisterDestinationConfiguration(New ECCDestinationConfig)
         _ecc = RfcDestinationManager.GetDestination("ECDCLNT140")
      Catch ex As Exception
      End Try
      End Sub
      Private Sub GetCompanyName()
         System.Console.WriteLine(String.Format("Successfully connected to System {0} Client {1}.", _ecc.SystemID, _ecc.Client))
         System.Console.WriteLine("Enter a company ID:")
         Dim companyID As String = System.Console.ReadLine()
         While Not String.IsNullOrEmpty(companyID.Trim)
            Dim companyAPI As IRfcFunction =
               companyAPI.SetValue("COMPANYID", companyID)
               Dim companyName As String =
              If String.IsNullOrEmpty(companyName.Trim) Then
                 companyName = "Not found"
              End If
                 companyID = System.Console.ReadLine()
              End While
           End Sub
        End Module
Published on 12-Feb-2018 15:19:04