如何使用.NET提供程序从SAP提取数据。

要使用SSIS进行提取,您需要有权访问后端系统。您可以使用.NET连接器并编写Windows应用程序,该应用程序使用功能模块从SAP系统提取数据。

有关如何使用.NET连接器连接SAP的更多详细信息,您可以参考此博客-https : //blogs.sap.com/2013/02/14/connecting-to-sap-with-nco-3/


使用BAPI,您可以允许外部应用程序访问R / 3系统中的业务流程和数据。下面的代码用于调用BAPI。首先是创建一个实现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
IDestinationConfiguration.GetParameters
   Dim parms As New RfcConfigParameters
   Select Case destinationName
      Case "ECDCLNT140"
     parms.Add(RfcConfigParameters.AppServerHost, "10.1.1.1")
     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

接下来是创建一个使用.Net 3.0连接器来调用RFC功能模块的Web服务。

Imports SAP.Middleware.Connector
   Module Driver
      Private _ecc As RfcDestination
      Sub Main()         RfcDestinationManager.RegisterDestinationConfiguration(New ECCDestinationConfig)
         Try
         _ecc = RfcDestinationManager.GetDestination("ECDCLNT140")
         GetCompanyName()
      Catch ex As Exception
         System.Console.WriteLine(ex.Message)
         System.Console.ReadLine()
      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("输入公司ID:")
         Dim companyID As String = System.Console.ReadLine()
         While Not String.IsNullOrEmpty(companyID.Trim)
            Dim companyAPI As IRfcFunction =
           _ecc.Repository.CreateFunction("BAPI_COMPANY_GETDETAIL")
               companyAPI.SetValue("COMPANYID", companyID)
               companyAPI.Invoke(_ecc)
               Dim companyName As String =
           companyAPI.GetStructure("COMPANY_DETAIL").GetString("NAME1")
              If String.IsNullOrEmpty(companyName.Trim) Then
                 companyName = "Not found"
              End If
                 System.Console.WriteLine(companyName)
                 companyID = System.Console.ReadLine()
              End While
           End Sub
        End Module