Integrating SAP using .NET Connector 3.0 (NCO)

//Integrating SAP using .NET Connector 3.0 (NCO)
  • How to Integrate SAP using NCO 3.0

Integrating SAP using .NET Connector 3.0 (NCO)

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. Examples of this are eCommerce applications. You may need prices, taxes, minimum order quantity and other system validations to come from SAP. Another example for integration is 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.

Technology Stack

SAP .Net connector connects Microsoft .Net application and SAP systems by using the SAP RFC. This is called as NCo. We 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

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

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.

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

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.

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

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.

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

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.

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

Below function is used for the data types.

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

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.

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

Spread the Wisdom
By |2018-05-25T02:48:08+00:00May 21st, 2018|SAP|0 Comments

About the Author:

Veon brings best in consulting and integration solutions on Salesforce, SugarCRM, and SAP. It is an innovative company which deals best of the breed solution using integration solutions on the above platforms. making small and medium enterprise become smarter.