This article explains that how we can connect third party applications with SAP using .NET connector (NCO). This is crucial in today’s world as system landscape consist of heterogeneous applications. These third party applications are as crucial as SAP.

Let us take an example of an eCommerce application. Since this is a customer facing platform, you may need prices, taxes, minimum order quantity and other system validations to come from SAP. This ensures that we take order at the correct price for something which is in stock. Another integration business case is a CRM application where you may want to enable sales representatives to submit accurate quote to the end customer.

Integrating applications eliminate manual steps and improve efficiency. Look at below video on how we have integrated order to cash cycle from an eCommerce application named Magento with SAP.

Now lets get to know how we can push data from and to SAP in a real time manner. For this we have taken an example to showcase how we can pull information using remote function call.  However before we go on to that lets understand a few basic things first.

Read more about best practices while integrating SAP with third party applications.


Integrating using SAP NCO – Understanding Technology Stack

SAP .NET connector (NCO) connects Microsoft .NET application and SAP systems by using the SAP RFC. This is called as NCo. Similarly, e can connect by using the Java, which is called the JCO. We will go with the .NET connector. Before moving forward these are prerequisites to understanding the process easily. Must have basic knowledge of development using C# and ASP.Net For developing the connector you will require the following Dll’s. There are 32 bit (x86) and 64-bit versions are available.

  • sapnco.dll
  • sapnco_utils.dll

SAP Integration Services by Veon Contact Banner


Where to get NCO 3.0

The SAP .NET Connector 3.0.20 can be downloaded from the SAP Service Marketplace.

  • Navigate to SAP Connector for Microsoft .NET
  • Download SAP Connector for Microsoft .NET Version 3.0

This will require a username and password. If you are a .net developer, probably you do not have it. Ask Your SAP Basis team to download and get it for you because they have the access to SAP marketplace.

Key fields

Given below are the key fields you will need to generate a remote session with SAP. These are available with the SAP Basis team or the system administrators.

  • SAP_USERNAME
  • SAP_APPSERVERHOST
  • SAP_PASSWORD
  • SAP_SYSNUM
  • SAP_CLIENT
  • SAP_LANGUAGE
  • SAP_POOLSIZE

Getting Started – Launch the Visual Studio

So now that we have all the credentials and requirements fulfilled, lets get started with the development of a sample integration program.

  • Create a web application SAP_NCO_ConnectionDemo and add reference of sapnco.dll and sapnco_utils.dll
  • Add a new class called RfcConfig that you will use to read the configuration(created this class in Utils folder)
  • Add SAP.Middleware.Connector namespace to this class which comes from the dll’s that you just added as a reference in your project.
Copy to Clipboard

To read the destination, SAP Connector provides an interface called IDestinationConfiguration. This interface provides a method called GetParameters. Inherit IDestinationConfiguration to your class and right click on it to implement an interface. In the below, we have made some changes after the implementation of the interface.

Copy to Clipboard

GetParameters method returns RfcConfigParameters which is a class in SAP Connector DLL. Update the code to read the config values.

Copy to Clipboard

Now we are able to get the configuration, next step is to test the connection. It can be called in a class where you would connect to the SAP. But the SAP connector has a method called RegisterDestinationConfiguration. All the destinations that have been needed to be registered first before connecting to the SAP.

You can do this step just before connecting to the SAP. For this Create one more class as RfcClient. Register the SAP configuration using the RegisterDestinationConfiguration. If the destination comes as null handle the exceptions.

Copy to Clipboard

Now define a method to test the connection. In this method, we are sending a request to Standard SAP BAPI request.

Copy to Clipboard

In the testconnection method, we have called the PullRequestTo SAPrfc function which will create an RFC request packet, sends the request to the SAP and returns the SAP response. This is shown in below.

Copy to Clipboard

RequestFn.Invoke(_ECCsystem); is the line where the .NET application actually calls the SAP Function. In PullRequestTo SAPrfc, we have used the two other functions which will creates a RFC request from XML i.e, PrepareRfcFunctionFromXML.

Copy to Clipboard

Create an instance of RFCRepository which has all the functions into it.

RfcRepository repo = _ECCsystem.Repository;

Using this repository call the method CreateFunction and provide the RFC name of SAP that you need to call. You need to make sure that the exact function name is available in SAP.

IRfcFunction RfcFunction = repo.CreateFunction(xmlFunction.Name.ToString());

In PrepareXMLrfcfrom method we have converted the RFC request to XML format.

Copy to Clipboard

The next step is to create a class which will act as a middleman between the .NET application and the SAP. This class will be responsible for connecting to SAP Server using SAP Connector, sending data and fetching data. Add a new class called SAPConnection. Add using SAP.Middleware.Connector namespace, as this is also going to use the SAP Connector DLL and call the testconnection Method

Copy to Clipboard

If the connection test is failed, It will provide the respected Exception which is defined in testconnection Method like credential mismatches. If the connection test is a success, You will get the response from the SAP.

Now proceed to test with some actual data. First I will show this on SAP side. Here we are calling the standard SAP bapi RFC_READ_TABLE for retrieving the product sales area.

Test function Module initial screen

Result:

Display DATA

Prepare the same request in XML string format and Call the PullRequestToSAPrfc method as shown.

Copy to Clipboard
Now we have successfully connected to the SAP. Below is the SAP response printed on the console.

Successfully connected to the SAP

In this way, we can connect to the SAP by using the SAP .NET connector 3.0.


Looking for a partner to integration SAP?

We can help deliver SAP integration projects. Reach out to us for a non-obligation consultation.

Contact us for a free assessment