SAP And SharePoint Integration Using .NET

Contents

  • Introduction
  • Pre-requisites
  • Procedure
    • Web.config 2
    • User_Control.cs 2
      • Fetch Data from SAP 2
      • Submit the data to SAP 3
  • Exceptions Expected and solution to it 4

Introduction

There can be a scenario where we need to fetch data from SAP and submit the updates to SAP using the functions given by the SAP team from the SharePoint screen.

To enable the preceding we will be writing .Net code using NCo3015_Net40_x64 MSI.

Pre-requisites

  1. Ensure the following ports are opened from the entore SharePoint front end and app servers to the SAP Server:

    3200, 3201, 3300, 3301, 3600, 3601

  2. SQL port 1433 to be opened between SharePoint front end and app servers to SQL Server.

  3. Download SAP NCO 3.0 package (NCo3015_Net40_x64 MSI) and install it on all servers (Development, UAT, Production [Front End, App, Distributed Cache and and so on (if any) servers]). Once installed, the following folder would be created and four DLL files are copied to that

    C:\Program Files (x86)\SAP\SAP_DotNetConnector3_Net40_x64

Procedure

  1. Open Visual Studio 2012.

  2. Create an Empty SharePoint Project.

  3. Add a User Control then call the user control in the Visual Web Part.

  4. Copy the four DLL files from C:\Program Files (x86)\SAP\SAP_DotNetConnector3_Net40_x64 to the application's bin folder (C:\inetpub\wwwroot\wss\Virtualdirectories\<Port Number>\bin).

  5. Add a reference of sapnco.dll and sapnco_utils.dll to the project from the bin folder.

  6. Write code in the User Control. The following code will only connect to SAP and fetch/submit the data. No Business logic is covered here.

  7. Deploy / Public the WSP file on the App server (or respective server) and web application.

Web config

Add the following entry in the appsettings of the web.config file location at the application bin folder (C:\inetpub\wwwroot\wss\Virtualdirectories\<Port Number>\web.config).

Note: For production, these entries are required on all Front End server's web.config file.

  1. <add key="SAPIP" value="XX.XXX.XX.XX" />  
  2. <add key="SAPUSERID" value="XXXX" />  
  3. <add key="SAPPWD" value="XXXX" />  
  4. <add key="SYSTEMNO" value="XX" />  
User_control.cs

Fetch data from SAP
  1. //Create RFC Config parameter object and bind the parameters  
  2. RfcConfigParameters rfc = new RfcConfigParameters();  
  3. rfc.Add(RfcConfigParameters.Name, "mySapName");  
  4. rfc.Add(RfcConfigParameters.AppServerHost, ConfigurationManager.AppSettings["SAPIP"].ToString());   
  5. rfc.Add(RfcConfigParameters.Client, "700");  
  6. rfc.Add(RfcConfigParameters.User, ConfigurationManager.AppSettings["SAPUSERID"].ToString());  
  7. rfc.Add(RfcConfigParameters.Password, ConfigurationManager.AppSettings["SAPPWD"].ToString());  
  8. rfc.Add(RfcConfigParameters.SystemNumber, ConfigurationManager.AppSettings["SYSTEMNO"].ToString());  
  9. rfc.Add(RfcConfigParameters.Language, "EN");  
  10. rfc.Add(RfcConfigParameters.PoolSize, "5");  
  11. rfc.Add(RfcConfigParameters.PeakConnectionsLimit, "10");  
  12. rfc.Add(RfcConfigParameters.ConnectionIdleTimeout, "500");  
  13.   
  14. //Create Destination, Repository and Function objects and bind the values accordingly  
  15. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfc);  
  16. RfcRepository rfcRep = rfcDest.Repository;  
  17. IRfcFunction function = rfcRep.CreateFunction("<<SAP Function Name>>");  
  18.   
  19. //Create a table object to hold the value set received from SAP   
  20. IRfcTable UserInfo = function.GetTable("<<SAP Table to Read>>");  
  21.   
  22. //pass the fields with values to be filtered from the result set  
  23. function.SetValue("Field1", txtTextBox.ValidationDate);  
  24. function.SetValue("Field2", Page.Request.QueryString["xxx"].ToString());  
  25. function.SetValue("Field3", txtTextBox3.Text.ToString());  
  26.   
  27. //Invoke the SAP function to update the result table with filtered values.   
  28. function.Invoke(rfcDest);  
  29. //UserInfo Table has filtered values which can be mapped to DataTable or any other object as per the requirement   
Submit the data to SAP
  1. RfcConfigParameters rfc = new RfcConfigParameters();  
  2. rfc.Add(RfcConfigParameters.Name, "mySapName");  
  3. rfc.Add(RfcConfigParameters.AppServerHost, ConfigurationManager.AppSettings["SAPIP"].ToString());  
  4. rfc.Add(RfcConfigParameters.Client, "700");  
  5. rfc.Add(RfcConfigParameters.User, ConfigurationManager.AppSettings["SAPUSERID"].ToString());  
  6. rfc.Add(RfcConfigParameters.Password, ConfigurationManager.AppSettings["SAPPWD"].ToString());  
  7. rfc.Add(RfcConfigParameters.SystemNumber, ConfigurationManager.AppSettings["SYSTEMNO"].ToString());  
  8. rfc.Add(RfcConfigParameters.Language, "EN");  
  9. rfc.Add(RfcConfigParameters.PoolSize, "5");  
  10. rfc.Add(RfcConfigParameters.PeakConnectionsLimit, "10");  
  11. rfc.Add(RfcConfigParameters.ConnectionIdleTimeout, "500");  
  12. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfc);  
  13. RfcRepository rfcRep = rfcDest.Repository;  
  14. IRfcFunction function = rfcRep.CreateFunction("<<SAP submit Function Name>>");  
  15. IRfcTable table = function.GetTable("<<SAP Table to update>>");  
  16.   
  17. DataTable dtmodified = (DataTable)Session["xxxxx"];  
  18.   
  19. foreach (DataRow row in dtmodified.Rows)  
  20. {  
  21.    table.Append();  
  22.    table.SetValue("field1", “Value1”);  
  23.    table.SetValue("field2", “Value2”);  
  24.    // set the value of all required fields with respective values  
  25.    table.SetValue("field_n", “Value_n”);  
  26. }  
  27.   
  28. function.Invoke(rfcDest);  
Exceptions expected and solution to it
  1. Could not load a file or assembly sapnco.dll / sapnco_utils.dll.

    Solution

    Ensure to copy the four DLLs from C:\Program Files (x86)\SAP\SAP_DotNetConnector3_Net40_x64 to the application bin folder (C:\inetpub\wwwroot\wss\Virtualdirectories\<Port Number>\bin).

  2. SharePoint 2013 layouts pages breaking with "Exception 'Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode:SubStatus:The request timed out".

    Solution

    Run the following Power Shell script to increase the response time.

    First run the following commands to see the health of the distributed cache that includes the status.
    1. $SPFarm = Get-SPFarm   
    2. $cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()   
    3. $cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local   
    4. $cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName)  
    5. $cacheClusterInfo  
    To resolve the issue, suggested to run following Power Shell commands that increase the distributed cache time out values to 10 seconds.
    1. $settings = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache   
    2. $settings.ChannelOpenTimeOut =10000   
    3. $settings.RequestTimeout=10000   
    4. Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $settings   
    5. $settingsverify = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache   
    6. $settingsverify   
    7.   
    8. $settingsa = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache   
    9. $settingsa.ChannelOpenTimeOut = 10000   
    10. $settingsa.RequestTimeout=10000   
    11. Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache -DistributedCacheClientSettings $settingsa   
    12. $settingsaverify = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache   
    13. $settingsaverify  
    14.   
    15. $set = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache   
    16. $set.MaxBufferSize = 33554432   
    17. Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache -DistributedCacheClientSettings $set   
    18. Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache   
    19.   
    20. $set = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache   
    21. $set.MaxBufferSize = 33554432   
    22. Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $set   
    23. Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache   
  3. SAP.Middleware.Connector.RfsCommunicationException: Location CPIC (TCP/IP) on the local host with Unicode Error Partner "xx.xxx.xx.xxx:3301" not reached time. Connection timeout counter.

    Solution

    Ensure the following ports are opened from the Front End, App Servers to the SAP Server.

    3200, 3201, 3300, 3301, 3600, 3601