Updated date:

How to Use SAP Nco Connector with C# and .Net

how-to-use-sap-nco-3-net-4-visual-studio-2010

SAP offers several technologies to interface with its ECC system. Of those varied technologies, RFC (or Remote Function Call) is one of the most popular. SAP has developed many implementation for the RFC, including COM, Java and .Net. SAP initially created a Connector using Java, called the Jco or (Java Connector) as an alternative to their flagship ABAP language. As the .Net framework and platform became more prevalent, SAP created a RFC Connector for.Net, titled Nco (.Net Connector). SAP recently released an updated version of their .Net Connector for .Net Framework 4 (Visual Studio). This article provides a tutorial on using the Nco with .Net 4 and Visual Studio.

Install the connector on your machine

To interface with SAP using the SAP Nco 3.0.3.0 for .Net Framework 4.0 and Visual Studio, you will need to download the Connector from the SAP Marketplace web site. Note that you need to be a SAP customer with a valid customer id and password: http://service.sap.com/connectors/

For Visual Studio, you will need to download the latest one:

sapnco30dotnet40P_3-20007347.zip

Unzip and install to a convenient location on your machine.

Create an App

For the purposes of this tutorial, I will create a Console application using the C# language to retrieve a list of customers from SAP. I will also create a C# class to handle the operations and a class to manage the connections to the different SAP systems. If you have Visual Studio, follow these steps:

Create a Visual Studio Windows Console Application. I name mine SAP_Customers, but you can name it anything you want.

Dll Version Information

Dll Version Information

Create SAP Connection

Once the Project is setup, create a new C# class, SAPSystemConnect, to implement the “IDestinationConfiguration” interface. This class will manage the configuration and connection to the SAP system. To be able to implement the “IDestinationConfiguration” interface, you will need to add a couple of references.

  • Right click on project and select “Add Reference”
  • When window opens, select “Browse” and navigate to the folder where you installed the SAP Nco Connector.
  • You will need to select the following dll:
  • Sapnco.dll
  • Sapnco_utils.dll
Add the Connector Reference to the Class.

Add the Connector Reference to the Class.

Next in the SAPSystemConnect class file, add a reference to the Connector SAP.Middleware.Connector.

To connect to a SAP system, we need to implement “IDestinationConfiguration “interface and define connection configuration parameters.

Using the SAPSystemConnect class, add the IDestinationConfiguration and implicitly implement its methods. The following code snippet show how the code should look like after the methods are implemented. An easy way to implement methods and properties of an interface is to place your cursor at the end of the class name and type a colon “:”. Then start typing the interface name and IntelliSense should popup and provide some suggestions, or you can press Ctrl+Spacebar to bring up the IntelliSense menu. Once the interface name is entered, IntelliSense will add an underscore or squiggly just under the first couple of letters as a prompt for you to take further action.

Click on the squiggly and select to “implicitly…” implement the interface’s methods and IntelliSense will add the necessary methods, events and other properties that are in the interface.

Code Snippet of SAPSystemConnect class

Code Snippet of SAPSystemConnect class

To define an RFCDestination, we will need to change the code in the GetParameters method. Several important parameters need to be created and initialized to be able to connect to SAP and return an RFCDestination. First create a new RfcConfigParameters object, parms, to hold our connection details.

This class will manage the connections to the SAP system through a pooling manager, thus allowing for several threaded connections. Next, if you plan on using the same program for different destinations, you can test for the destination using an “if” statement or a “switch”. In the following example, I am using an “if” expression.

To define a destination, we will need to set some parameters as the following code snippet demonstrates.

SAP RFCConnection Parameters

SAP RFCConnection Parameters

BAPI Explorer

BAPI Explorer

Customer BAPI

Customer BAPI

SAP BAPI Explorer

SAP’s BAPI Explorer is your source of all the functions, objects, fields and source code to help you. BAPI Explorer is more than a documentation repository. It also provides access to the source code of the RFCs; provides detailed information on the import and export parameters, structures and tables. You can create and test new functions and you can run existing BAPIs to review the data that is being returned. A handy tool is the BAPI list generator. It searches and creates a list of all BAPIs for a particular object.

The BAPI Explorer tutorial is beyond the scope of this tutorial.

Customer Class Properties

Customer Class Properties

Using the RFCDestination

The next step in this tutorial is to actually use the RFCDestination to connect to a Repository and query the Customer Master Data to return a list of customers and some extra details. Four BAPIs (functions) that will give us the required information are:

  • BAPI_CUSTOMER_GETLIST
  • BAPI_CUSTOMER_GETSALESAREAS
  • BAPI_CUSTOMER_GETDETAIL1
  • BAPI_CUSTOMER_GETDETAIL2

Create a new C# class: Customers

Add the SAP Connector in the reference

To hold the data from SAP, define a series of protected properties. The code has been truncated for brevity but the complete source code is included at the end of the tutorial:

Next define method to perform the operations of connecting and retrieving the data from SAP: GetCustomerDetail. The method will take a RfcDestination parameter to pass in the destination from the main program, see section “Putting the Pieces Together” later in this tutorial.

The Connector provides several Exception classes that we will implement using a try…catch statement. The exception classes are:

  • RfcCommunicationException
  • We couldn’t obtain a connection with the system.
  • RfcLogonException
  • We couldn’t logon.
  • RfcAbapRuntimeException
  • A runtime error has occurred
  • RfcAbapBaseException
  • A General Abap error has occurred.

Within the try…catch operation, define an RfcRepository object, repo. Next create a RfcFunction to return a list of customers, customerList and pass in the “BAPI_CUSTOMER_GETLIST” function to return. Before we can use the function, we need to invoke it, see code snippet below.

Code Snippet of Creating Function

Code Snippet of Creating Function

Setting the idRange parameters

Setting the idRange parameters

Now that we have access to the function, we need to tell it what range of values to return. Create an IRFCTable object and set the GetTable property for the CustomerList function. Set the value to “IdRange”. For the purposes of this example, I will use the following parameters:

  • Sign = “I”
  • Options= “BT”, meaning “between”
  • Low = “”, or smallest value
  • High=”9999999”, the highest possible value

Here is a look at the code snippet:

Add idRange to BAPI function

Add idRange to BAPI function

Once these values are set, you will need to add the table to the function. Before invoking the function again to return the list of customers, you will need to tell the function which table of data you want to return. The current function can return “AddressData” and “Return” and “SpecialData”. I will use the “AddressData” for this example.

Once we have a list of customers, you will be able to loop through the list, extracting any needed data. I will create and destroy and explicitly call the garbage collector for each row in the list otherwise you will run into memory issues. You could use a “Using” statement to loop through the list and manage the object resources, but I have had issues with that design as well, so I will use the tried and true “for each”.

Also I will create (call or initialize) three new functions to get all the necessary information on the customers: “BAPI_CUSTOMER_GETSALESAREAS”, “BAPI_CUSTOMER_GETDETAIL1” and “BAPI_CUSTOMER_GETDETAIL2”.

Once the function are created and invoked, passing in any parameters as required, you can access the data as using the GetString property of the RFC function. Also bear in mind that a SAP function can return either a table or a structure. You will need to consult the documentation or through the Visual Studio debugger, “locals” window to determine which is which because the documentation may not always tell which is which form my experience. In the following example, the “CustomerGeneralDetail” in the “customerDetail2” function is a structure, while the “SalesAreas” in the “customerHierachy” function is a table. I have found that when accessing a table, it is better to test if there are any rows; otherwise the program throws an error.

This is the complete code for the Customers class:

Customers Class Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;

namespace SAP_Customers
{
    class Customers
    {
        protected string CustomerNo;
        protected string CustomerName;
        protected string Address;
        protected string City;
        protected string StateProvince;
        protected string CountryCode;
        protected string PostalCode;
        protected string Region;
        protected string Industry;
        protected string District;
        protected string SalesOrg;
        protected string DistributionChannel;
        protected string Division;





        public void GetCustomerDetails(RfcDestination destination)
        {


            try
            {
                RfcRepository repo = destination.Repository;
                IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_GETLIST");


                customerList.Invoke(destination);

                IRfcTable idRange = customerList.GetTable("IdRange");
                idRange.SetValue("SIGN", "I");
                idRange.SetValue("OPTION", "BT");
                idRange.SetValue("LOW", "");
                idRange.SetValue("HIGH", "999999");


//add selection range to customerList function to search for all customers
                customerList.SetValue("idrange", idRange);


                IRfcTable addressData = customerList.GetTable("AddressData");
                customerList.Invoke(destination);
               
                for (int cuIndex = 0; cuIndex < addressData.RowCount; cuIndex++)
                {
                   
addressData.CurrentIndex = cuIndex;
IRfcFunction customerHierachy = repo.CreateFunction("BAPI_CUSTOMER_GETSALESAREAS");
IRfcFunction customerDetail1 = repo.CreateFunction("BAPI_CUSTOMER_GETDETAIL1");
IRfcFunction customerDetail2 = repo.CreateFunction("BAPI_CUSTOMER_GETDETAIL2");
                    
this.CustomerNo = addressData.GetString("Customer");
this.CustomerName = addressData.GetString("Name");
this.Address = addressData.GetString("Street");
this.City = addressData.GetString("City");
this.StateProvince = addressData.GetString("Region");
this.CountryCode = addressData.GetString("CountryISO");
this.PostalCode = addressData.GetString("Postl_Cod1");
                    
customerDetail2.SetValue("CustomerNo", this.CustomerNo);
customerDetail2.Invoke(destination);
IRfcStructure generalDetail = customerDetail2.GetStructure("CustomerGeneralDetail");

this.Region = generalDetail.GetString("Reg_Market");
this.Industry = generalDetail.GetString("Industry");


customerDetail1.Invoke(destination);
IRfcStructure detail1 = customerDetail1.GetStructure("PE_CompanyData");

this.District = detail1.GetString("District");
                       

customerHierachy.Invoke(destination);
customerHierachy.SetValue("CustomerNo", this.CustomerNo);
customerHierachy.Invoke(destination);

IRfcTable otherDetail = customerHierachy.GetTable("SalesAreas");

if (otherDetail.RowCount > 0)
{
this.SalesOrg = otherDetail.GetString("SalesOrg");
this.DistributionChannel = otherDetail.GetString("DistrChn");
this.Division = otherDetail.GetString("Division");
}

                    customerHierachy = null;
                    customerDetail1 = null;
                    customerDetail2 = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();



                }


            }
            catch (RfcCommunicationException e)
            {

            }
            catch (RfcLogonException e)
            {
                // user could not logon...
            }
            catch (RfcAbapRuntimeException e)
            {
                // serious problem on ABAP system side...
            }
            catch (RfcAbapBaseException e)
            {
                // The function module returned an ABAP exception, an ABAP message
                // or an ABAP class-based exception...
            }

        }
    }
}

Putting the Pieces Together

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;

namespace SAP_Customers
{
    class Program
    {
        static void Main(string[] args)
        {
            SAPSystemConnect sapCfg = new SAPSystemConnect();
         

            RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);
            RfcDestination rfcDest=null;

            for (int i = 0; i < args.Length; i++)
            {     
                // arg[i] = Dev
                rfcDest = RfcDestinationManager.GetDestination(args[i]);
            }
          

            Customers customer = new Customers();
            customer.GetCustomerDetails(rfcDest);  
      
            System.Environment.Exit(0);

        }


    }
}

Source code for tutorial

In Summary

Creating, invoking and extracting data from either a structure or table is very easy. The hardest part is finding the right function, import parameters and which tables or structures contains the proper information. Also it is important to bear in mind the fact that the functions use the same field names as in the SAP tables, so I sometimes, you will need to open the program to see which fields are being retuned. For this and finding the functions, tables, structures, import and export parameters, the BAPI Explorer is an invaluable tool.

I hope this tutorial contains enough information to get you going. If more information is required leave a comment and I will try and help.

This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.

© 2011 Kevin Languedoc

Comments

Amresh Nikam on April 22, 2020:

Can you explain RFC Server implementation in dot net. So ABAP program call dot net function

Kevin Languedoc (author) from Canada on September 30, 2019:

Hello to All,

I have added a link to the GitHub repo where the source code is located.

Thanks

Kevin

deecation on July 13, 2019:

How can I get the source code

brad on July 12, 2019:

Does the NCO library provide any logging to a file for debugging or errors.

Ramprit Sahani on June 17, 2019:

From where will get Sample code?

Kevin Languedoc (author) from Canada on April 28, 2019:

Hi

Can you provide more detail on your request. I am not sure what you are asking. Also send your request to kevinlanguedoc@gmail.com as I don't check these comments regularly.

Thanks

Kevin

Nileshpatil21 on April 19, 2019:

Hey,

Currently I am working on an integration project using the NCo, fetch the data from SAP ERP. I request you to please provide me some guide lines on 'How to follows the standard code writing in C#' if possible, as we are going for SAP certification. Your response will be highly appreciated.

Thanks in advance. Waiting for your reply.

David Burg from Sammamish, WA on July 06, 2018:

There is a bug in the sample app, ChangeEventsSupported must be implemented as part of the contract with SAP NCo as it will be called back. Other have noticed the not implemented exception throws, causing the program to fail. The simple implementation is just

return false;

As the sample application does indeed not have code to handle change events.

Faizan on November 22, 2017:

Hi,

I have 2 queries

1. Why are u invoking method twice 1 before set and one after.

2. If there's a change in BAPI like new parameter and function is also changed works fine but after some time it(code) start picking old BAPI function and it gets resolved after IISRESET. Any idea what is wrong and why does it starts picking after IISRESET?

Ángel on June 23, 2017:

Hello Kevin

could you tell me someting about BAPI_DOCUMENT_CHECKOUTVIEW2 function and callback method ? this function don't work with NCO 3. Is there a solution?

Thanks in advance

Mecit on March 06, 2017:

Hi I´m getting the error "Hard-coded logon parameters not allowed when using a DestinationConfiguration". I have a seperate xml file which I consume during run time to create the RfcConfigParameters.

After reading the xml I produce a new RfcConfigParameters object and then add them "rfcConfigParameters.Add(RfcCnfigParameters.Name, "Name");"

I also tried to add them like that:

"rfcConfigParameters[RfcConfigParameters.Name] = "Name";"

but that didn´t work too.

Could you please help me?

Ashish Tasare on February 06, 2017:

Hi Ashish,

It sounds more like a SAP issue and not a code or Nco/RfcSdk issue. Did any of the login credentails (sys nr, client code, etc. ) change? There is correlation between the nco and the SAP system as far as the credentials are concerned unless any of the input parameters are different siince the reset.

Can the user log into SAP using the same credentials and SAPgui and parameters?

Kevin

==============================

Thank you Kevin.

How to turn off connection pooling for SAP Connector in web.config?

Kevin Languedoc (author) from Canada on January 05, 2017:

Hi Hans, FranciscoRomero,

Hans: If you app is working well I would necessarily change for the sake of changing. If you need to support another version based on corporate policy than do so otherwise leave well alone.

Francisco: Unfornutalely I don't work with this technology anymore and I can't find the original source code that I used. Sorry.

FranciscoRomero on January 04, 2017:

Hello. Can you please send me working example of this on

pacorom60@outlook.com

I implemented the code but still get and NullPointerException in the RfcDestination.

I want to check what I did wrong. Thanks !!

Hans on January 04, 2017:

Hello Kevin,

I am still using connector 2.0 and thinking about to change to 3.0.

What is your opinion: 3.0 is also some years old. Is it ok to invest time into 3.0 or is there a newer or better way of a connector ? Of course my application reads and send information in both directions and with 2.0 .

Kevin Languedoc (author) from Canada on December 23, 2016:

Hi Ashish,

It sounds more like a SAP issue and not a code or Nco/RfcSdk issue. Did any of the login credentails (sys nr, client code, etc. ) change? There is correlation between the nco and the SAP system as far as the credentials are concerned unless any of the input parameters are different siince the reset.

Can the user log into SAP using the same credentials and SAPgui and parameters?

Kevin

Ashish Tasare on December 22, 2016:

Ashish Tasare,

Where did that person reset their password. what client? I know this sounds like a dumb question but it has happpened to me. Are you testting in the same client where the use reset their password

=======================================

Kevin,

User reset the password either in SAP Logon or Windows. When user update windows password, it will sync with SAP.

-AShish

Ashish Tasare on December 22, 2016:

Kevin Languedoc

3 weeks ago from Canada

Neils, Imran, Sarosh, Ashish Tasare

First, sorry for the late reply. What .Net version are you using as this has a huge impact on code functionality.

Sarosh, I am not sure in reference to what. One of the methods refers to events.

Please send more details and I will get back to you this week.

Thanks

Kevin

=========================================

Kevin,

I'm using VS 2013 and .Net framework 4.0

-AShish Tasare

Kevin Languedoc (author) from Canada on November 29, 2016:

Neils,

Yes the sdk should work in a web application as long as you are using the proper .net version that is supported by the nco. Unfortunately I no longer have access to a SAP system or the nco and saprfc so I can't provide any code to help you out.

Kevin Languedoc (author) from Canada on November 29, 2016:

Ashish Tasare,

Where did that person reset their password. what client? I know this sounds like a dumb question but it has happpened to me. Are you testting in the same client where the use reset their password

Kevin Languedoc (author) from Canada on November 29, 2016:

Neils, Imran, Sarosh, Ashish Tasare

First, sorry for the late reply. What .Net version are you using as this has a huge impact on code functionality.

Sarosh, I am not sure in reference to what. One of the methods refers to events.

Please send more details and I will get back to you this week.

Thanks

Kevin

Ashish Tasare on August 09, 2016:

Hi Kevin,

We are using windows user Id and password to connect SAP. The connection failed for all the user if one of the user reset password.

Please help to fix this issue.

//Code snippet

RfcCustomDestination _customDestination = rfcDest.CreateCustomDestination();

_customDestination.User = "acc-fam"; //User = Login UserId

_customDestination.Password = "password"; //Password = Login User password

//Error message

No authorization to log on to the target system (error code 53).

Niels on May 10, 2016:

Can this code be user for a Visual Studio 2010 C# web application and how do I fire the events so it's starts reading the SAP values?

Thanks,

Niels

Imran on October 26, 2015:

Hi Kevin, Well I resolved the error but now I am getting an error while running the project. inside method

public bool ChangeEventsSupported()

{

throw new NotImplementedException();

}

"The method or operation is not implemented."

Can you please help?

Imran on October 24, 2015:

Hi Kevin, Thanks for your great tutorial.

I am trying to connect SAP but I am getting an error while building a project.

"The type or namespace name 'IDestinationConfiguration' could not be found (are you missing a using directive or an assembly reference?)"

Please not I am using VS2012 and NCO 3.0.10.0.

Can you please advise.?

Kevin Languedoc (author) from Canada on January 22, 2015:

Hi Atul,

I opted to use a system user with no expiry password so the end user doesn't have to login. I don't have any code specific to your needs.

Richard

What version of the Nco are you using versus the .Net framework. It looks like you have not implemented all the methods in the Class you are extending.

Richard on January 21, 2015:

Hello,

I implemented your example code , chhanging the parms to match our system info, but when I try to run the console app I keep getting the following error:

"

A first chance exception of type 'System.NullReferenceException' occurred in sapnco.dll

A first chance exception of type 'System.NotImplementedException' occurred in SAPConsole.exe

A first chance exception of type 'System.NotImplementedException' occurred in sapnco.dll

An unhandled exception of type 'System.NotImplementedException' occurred in sapnco.dll

Additional information: The method or operation is not implemented."

Any Ideas what I may be missing?

Atul Sharma on December 11, 2014:

We are trying to use SAP.NET NCo 3.0 to implement single sign on from .net application to SAP System. In the configuration set up method we are fetching user name and password along with other configuration information from configuration file.

E.g.

RfcConfigParameters rfcConfig = new RfcConfigParameters();

rfcConfig.Add(RfcConfigParameters.User, ConfigurationSettings.AppSettings["SAP_USRNAME"]);

rfcConfig.Add(RfcConfigParameters.Password, ConfigurationSettings.AppSettings["SAP_PWD"]);

rfcConfig.Add(RfcConfigParameters.Client, ConfigurationSettings.AppSettings["SAP_CLIENT"]);

We are looking for a way that we can implement SSO with windows authentication where will ne NO need to pass user id and password explicitly. We also have SNC configuration and other required file available with us.

Any relevant code snippet or pointer addressing this will be of great help.

Thanks in advance

Star Moe on July 06, 2014:

Hi,

Thank you very much.

Now I know how to extract data from SAP.

Could you please tell me how to update data in SAP using .net connector 3.0 in asp.net application.

Thanks again.

Star Moe

Kevin Languedoc (author) from Canada on March 06, 2014:

Ranjan,

Once you created the rfcDEstination (once) all you need to do is call it multiple times, possibly using Threads.

fei,

Glad to see everything worked out

pk,

Can you give me more information. Are you using the right framework and connector?

Kevin

Ranjan on February 27, 2014:

Hi,

This is a great tutorial. I need to implement multiple connection to sap I have implemented connection by using RfcConfigParameters, but I am getting an error "destination configuration already initialized" while Re-executing the API. Can you help me with this.

fei on February 25, 2014:

I'm sorry to say that it is my error to use wrong Nunit.

It is OK after i used nunit-x86.exe.

thanks!

fei on February 25, 2014:

Sir,

I have used your example code and get data in aspx.cs.But when i use Nunit to test it,it show follow message

eShippingTest.Business.CustomsListsTest.Testdt:

System.IO.FileNotFoundException : Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies.

rajesh on February 25, 2014:

sir,

i have used your example code , but i am not getting any list in my .net application. should i have to create a html page for that ? pl. help

Ismael on February 13, 2014:

Thank you, works perfect!!

pk on February 13, 2014:

I am using Dot Net connector 3 x64 on Windows 7 64 bit , bit getting error

Kevin Languedoc (author) from Canada on January 17, 2014:

RAM,

The process is the same except you have to use web services or an http handler (ashx)

To everyone looking for the code, it is here

http://code.google.com/p/sap-nco-tutorial-code/

Hope this helps

MohsenSam on December 31, 2013:

Hi

I used the code on the page, it is not working, please send me the your code

thanks

mohsensamano@gmail.com

RAM on December 30, 2013:

HI ,

I have developed by Asp.Net ,this project connect to SAP database integration .Can you please tell me the process of integration . if any sample document or code please send me ramgopal.m@greenbyte.in

Thanks

Ram

vijay on December 12, 2013:

Hello,

Can you send me the code to creating sales order using bapi :

BAPI_SALESORDER_CREATEFROMDAT1

it will be a great help to me

My email Id is vijay.kr.seth@gmail.com

ChloeLim on November 24, 2013:

Thanks for confirming. :)

Kevin Languedoc (author) from Canada on November 23, 2013:

Yes that is correct.

ChloeLim on November 21, 2013:

Hello,

By following your method, when I go to SM04 and found 2 user session have been created, this should be expected?

Dim repo As RfcRepository = destination.Repository (FIRST session created)

Dim OperationList As IRfcFunction = repo.CreateFunction("BAPI_PRODORD_GET_DETAIL") (SECOND session created)

Kevin Languedoc (author) from Canada on November 12, 2013:

Lois,

Is your reference properly set? Also what version of the nCo library are you using with your .Net SDK? For VS2010 .net 3.5, you need nCO 3

Eduardo on October 16, 2013:

This information is great. Congratulations.

How can I check for existing connections?

Anoop on September 25, 2013:

Thank you klangudedoc

Its working.

Earlier What I did is with out giving RFC Name I tried to Connect SAP R/3 System.Now after giving RFC Name its working fine.

Thank you So much..:)

1]Let me know for Asp.net 3.5 framework for connecting SAP R/3 is any other best practice method is available.

2]Another thing SAP Dotnet connector is licensed or freeware.

Lois on September 24, 2013:

Thank you so much for this tutorial. It´s so clear.

I am tring to do your example. It have this {"Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies. Se ha intentado cargar un programa con un formato incorrecto."}

can you help me please

Kevin Languedoc (author) from Canada on September 22, 2013:

Luis, Arjun

try doing a regsrv to register the dll. Also what .net sdk are you using. Version is for .net 4.5

Anoop, Luffy

Code is available here:

http://code.google.com/p/sap-nco-tutorial-code/

Luis on September 16, 2013:

Hi. I had added all reference that you describe to my project, but I got the below error:

Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23'

Anoop on September 12, 2013:

As Per your Code I created a console Application.

In the class SAPSystemConnect you mentioned a method called

ChangeEventsSupported but inside that you have not provide any

code.

Kindly request to Suggest what code i need to write in that method.

Advance Thanks

Anoop

Luffy on September 11, 2013:

Hello. Can you please send me working example of this on

luffy.syu@motorpro.com.tw?

Arjun Walmiki on September 06, 2013:

Hi I am found the below error pls help

Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Kevin Languedoc (author) from Canada on September 03, 2013:

Hi Paula Rocha,

Since Nco uses a connection pool, it is hard to close the connections. I would set the connection object to NULL.

Something like

RfcSessionManager.EndContext(destination);

destination = null;

Paulo Rocha on August 31, 2013:

Thank you sooo much for this tutorial, but I have a question.

How do I close the SAP connection?

I'm trying to build a program with Windows Forms where I can add roles to the users. I inform the user and the roles, and he adds perfectly.

The problem is that when I put another user, I cannot run the program again, because it says that I already have an opened connection.

It sound silly but I really don't know what do I have to change.

Any tip will be helpful.

Thanks in advance.

Kevin Languedoc (author) from Canada on August 29, 2013:

you can download the code from here

http://code.google.com/p/sap-nco-tutorial-code/

Amine on August 16, 2013:

hey can you send me working example on

amineraoui@hotmail.com

i have some errors in

RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);

Kevin Languedoc (author) from Canada on July 11, 2013:

Hi cedric finet,

You could use the IDOC_INBOUND_ASYNCHRONOUS. It is RFC to process IDocs.

Hi Aman,

I don't know offhand but I would look at the number of connections in the rfcConfigurationManager and check if all are used up.

Aman on July 10, 2013:

How to get the number of users, who r using this connection..

Any help will be really appreciated.

cedric finet on July 09, 2013:

I need to implement Idoc processing with SAP .net connector 3.0

I'm looking for C# exemples. I didn't find any help into SAP .net connecor 3.0 library: SAP.Middleware.Connector

the SAPIDocReceiver class seems to have been removed from this new 3.0 version.

thanks to all

Kevin Languedoc (author) from Canada on June 14, 2013:

Sagar,

If you just want to explore the API, you can use the BAPI explorer in SAP. The transaction code is BAPI. You can see RFCs there as well

Sagar on May 23, 2013:

Hi I just want to get List of functions availbale in SAP machine.

Currently we have to specify the function name in CreatFunction method.

I want to get the list of function names so that user can select from them and get the metadata of that selected function.

Can you please tell me is this possible with the help of this connector?

Kevin Languedoc (author) from Canada on May 13, 2013:

you can download from:

http://code.google.com/p/sap-nco-tutorial-code/

Kevin Languedoc (author) from Canada on April 26, 2013:

Ok cool. I was going to suggest looking at the frameworks, but I am glad you found your answer

Jonathan 2 on April 03, 2013:

Found the solution @ : http://www.dataxstream.com/2012/10/nco-3-0-error-c...

Seems I was missing a prerequisite

Jonathan 2 on April 02, 2013:

Hi,

I have an application that runs succesfully on my system, but not when I deploy it to another system. I get following error:

The type initializer for 'SAP.Middleware.Connector.RfcDestinationManager' threw an exception.

i use the build in publisher of VS2012

Any idea what could be the cause? How can I ensure the sapnco.dll gets correctly distributed with the application (assuming this causes the error).

Thanks for help,

Jonathan

Kevin Languedoc (author) from Canada on March 14, 2013:

Jonathan,

Did you add a reference to the rfc libs

Jonathan on March 08, 2013:

Can you help me, I have an error in

RfcRepository repo = destination.Repository

Object reference not set to an instance of an object.

Kevin Languedoc (author) from Canada on January 29, 2013:

Yes this is correct, you define a table and set values for each field in table, then add table to importparamterlist and execute function.

satrughan mahato on January 23, 2013:

Thanks a lot Klan.In ur sample code above only BAPI BAPI_CUSTOMER_GETLIST" needs Table -idrange as a parameter not other BAPI s like -

("BAPI_CUSTOMER_GETSALESAREAS");

("BAPI_CUSTOMER_GETDETAIL1");

("BAPI_CUSTOMER_GETDETAIL2");

Is my understanding is correct?

Kevin Languedoc (author) from Canada on January 23, 2013:

This bapi requires an input parameter as a table which must supply values including

SIGN

OPTION

LOW

HIGH

satrughan mahato on January 23, 2013:

why this line of code is written in ur above code sample as we are fetching data from IRFCTable "AddressData" and not "IdRange".

IRfcTable idRange = customerlist.GetTable("IdRange");

idRange.SetValue("SIGN", "I");

idRange.SetValue("OPTION", "BT");

idRange.SetValue("LOW", "");

idRange.SetValue("HIGH", "999999");

//

customerlist.SetValue("idrange", idRange);

Kevin Languedoc (author) from Canada on January 23, 2013:

Satrughan mahato

You have to use the Bapi Explorer. In SAP SAPGui enter the "BAPI" transaction code, this will launch the BAPI Explorer. Then you can drill down and view the functions, tables and structures associated with a BAPI. You can also view the source code and run it to see output.

I can write a quick tutorial with screenshots if you would like if this would help.

satrughan mahato on January 22, 2013:

How to get the tool : ABAP Workbench?Do i get it free or from SAP market place?

Satrughan mahato on January 22, 2013:

Thanks for ur reply Klanguedoc.As I am a DotNet developer having no idea about SAP.But in our DotNet project ,we need to fetch data from SAP system and use it in our DOT NET project.So how we came to know that which BAPI we required to fulfill our needs.and which table is associated with which BAPI?Here in ur above code sample u have used this BAPI BAPI_CUSTOMER_GETLIST .Here how u come to know that this BAPI use table "AddressData".In short how to know which tables are associated with which BAPI.Are all this information should be provided by SAP team?plz explain me in details like a fresher.

Kevin Languedoc (author) from Canada on January 22, 2013:

Hi satrughan mahato,

Yes these are special RFC (Remote Function Calls) called BAPIs (Business API). You can browse the BAPIs and RFCs through the ABAP Workbench using Transaction Code : BAPI

You can browse by business area or alphabetically. Since you can view the source code of all BAPIs and RFCs in SAP, they are also a great learning tool.

Andrew,

Have you tried this setup on VS2010 instead? remove any error handling and you will get more information. Please review SAP Note 856863 in the SAP service area on system requirements. Also try and lower the .net framework version to 3.5.x

Andrew on January 22, 2013:

I`m having this wicked error! Can someone help me please??

http://stackoverflow.com/questions/14388128/no-des...

satrughan mahato on January 22, 2013:

BAPI_CUSTOMER_GETLIST,BAPI_CUSTOMER_GETSALESAREAS,BAPI_CUSTOMER_GETDETAIL1,BAPI_CUSTOMER_GETDETAIL2.Are this functions are inbuilt SAP functions?How we came to know that this functions are present in SAP system?Kindly explain me in details.

Kevin Languedoc (author) from Canada on January 20, 2013:

Ashish,

You can add the code to a web service or call the code from a web service.

Ashish on January 16, 2013:

Dear

expert, how can i write code for BAPI_EMPLOYEE_GETDATA in .net web application

thanks

Kevin Languedoc (author) from Canada on January 15, 2013:

.Net Nco is not widely supported at SAP. Java is their main programming language other than ABAP. I am not surprised that the 64 bit is not supported. I have switched to Java (Jco) for a current program because the Nco had problems with client (rfc) 7.x

Gabi on January 15, 2013:

This works fine for x86 compilations.

However, It's not working for x64.

Exists some installer the sap connector for 64 bits?

Kevin Languedoc (author) from Canada on December 08, 2012:

Sorry for the delay,

You can get a SAP Mini Basis by buying a book form SAP Press or by downloading from SAP, but you have to be a customer. I know this sounds stupid.

There are some books from SAP Press that have a SAP Basis system (DVD) included (this is the ECC without the business functions like SD, Copa, finance. Basically it is just the base ECC for testing and learning Abap. Read the book descriptions, especially the ones on Abap developerment.

I got mine with the Abap Objects by Horst Keller, SAP Press

Ish on November 28, 2012:

Thanks for the excellent article!!!

I want to connect an existing .net implication with SAP ECC. currently my employer don't have a sap customer. but we need to test this first.

So i want to know that, Is SAP ECC comes with Net viewer?

If i downloaded a Net viewer Trail is it includes the SAP ECC to test connecting my .net application as approach describe by you?

Thanks,

Kevin Languedoc (author) from Canada on November 26, 2012:

Thanks Eray Kaya,

You can download the code at this address:

http://code.google.com/p/sap-nco-tutorial-code/

Thanks

eray kaya on November 26, 2012:

Excellent. can u send me this project.

Kevin Languedoc (author) from Canada on November 15, 2012:

Sorry no I don't

Sathish on October 28, 2012:

This is a nice article. It covers almost everything for a good start.

i am tring to do SSO using NCO 3.0, and also need to know how to manage the connections. Do you have any article regarding this?

Thanks

Kevin Languedoc (author) from Canada on October 19, 2012:

Thanks Harry,

The change event can be used to detect when you switch from one connection to another for instance, such as a failover SAP configuration. I never use it simply because I never need to.

Thanks infotechnology

Omogiade Stephen Nosakhare from Lagos, Nigeria. on October 18, 2012:

This is a nice hub, very educative

harry on October 17, 2012:

thanks a lot for the sample.. what about the change event supported method and configuration change handler use? in sample?no implementation? plz explain..

harry on October 17, 2012:

Superb post

Kevin Languedoc (author) from Canada on October 16, 2012:

Thanks

Sylvergirl on October 15, 2012:

Excellent

Kevin Languedoc (author) from Canada on October 13, 2012:

Hi Oskar

You should have a disconnect() method. I haven't tried it though.

Hi Jose Antonio,

You can download the project using this url:

http://code.google.com/p/sap-nco-tutorial-code/

Thanks

Kevin

Jose Antonio on October 12, 2012:

Hi, great tutorial, I heve been looking where I can download the code of this tutorial in the post, but don't exist the option, could you please send me the code of this tutorial at the next direction: josemtz_2@hotmail.com

Thank's

Oskar on October 08, 2012:

Hello, I'm trying to create an app that, every 30 minutes update a SQL table from SAP. It's runs ok, but I've a problem, I can't disconnect from SAP between update.

I try to use the method RfcDestinationManager.UnregisterDestinationConfiguration(Config) and the garbage collector too (as you), but doesn't run.

Do you have any idea how I could logoff from SAP?

Kevin Languedoc (author) from Canada on September 28, 2012:

I will check and hopefully I can help.

jim tang on September 20, 2012:

I have sent an email to you for detail of my problem please help me thank you

Kevin Languedoc (author) from Canada on September 20, 2012:

I would simply call the SAPSystemConnect class and replace the hard coded values with variables that you can supply either from the running app or from a User Interface.

jim tanng on September 20, 2012:

how can create connections more two users , I mean after I created an connection ,how can I create another user connection with another user information

Related Articles