AcademiaAgriculture & FarmingHumanitiesSocial SciencesSTEM

How to Use SAP Nco 3 Connector:.Net 4 (Visual Studio 2010)

Updated on May 2, 2016

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 2010). This article provides a tutorial on using the Nco with .Net 4 and Visual 2010.

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 2010, 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 2010, 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 2010, follow these steps:

Create a Visual Studio 2010 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);

        }


    }
}

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.

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Stanislav 4 years ago

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

      sidnev.stanislav@yandex.ru?

      I tried this code and got some error in

      RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Yes I send today

    • profile image

      romanlopg 4 years ago

      I implemented your code in a web application, works great in my local environment !. But, there's always a but, when I deployed to a server doesn't work, the web page hangs out and finally show "The page cannot be displayed"

      Do you know what do Im doing wrong ? Or if there some issues for Web Applications ??

      One thing that I notice is that in my local environment I have SAP GUI installed, and not at the server...

      I will appreciate any ideas

      Thanks in advance !

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Yes you need either the sapgui or the dll for the rfc, the librfc32.dll which is the lib for the rfc interface. Add it to you reference and add to the server.

    • profile image

      Ricardo 4 years ago

      Hi, I think this is a very clean and useful code! if you don't mind, please can you send me the example code too

      Thanks in advance

    • profile image

      Ricardo 4 years ago

      I am so sorry!, I forgot to give you my e-mail address: please can you send me the code example to rmadiedo@yahoo.com?

      Thank you

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Sure no problem Ricardo.

      Kevin

    • profile image

      Bernd 4 years ago

      Hi, thanks for you example! Have you any experience and an example to check-in or check-out a file to an SAP Server. I have got the Error "Callback Server is not available" .

      Thanks for your advise

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      No sorry. I wish I could help.

    • profile image

      Bernd 4 years ago

      Ok, thanks again. It's to bad, I can't find a solution.

    • profile image

      Bernd 4 years ago

      OK, thanks again. It's to bad, I can't find a solution.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      If you can give more details, I can ask around. I know a few SAP programmers and techies. Are you woeking with SAP NetWeaver AS?

    • profile image

      Bernd 4 years ago

      Yes, your example works find. I create a RfcFuntion from the BAPI

      BAPI_DOCUMENT_CHECKIN_REPLACE2 an Invoke this with the following lines:

      RfcSessionManager.BeginContext(RfcDest);

      documentCheckin2.Invoke(RfcDest);

      commitBapi.Invoke(RfcDest);

      RfcSessionManager.EndContext(RfcDest);

      after the second line I get the error.

      Thanks Bernd

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      What is the error you are getting?

    • profile image

      ASG 4 years ago

      Hi

      Thanks a lot for your very useful code.

      I'm getting error in following method

      public bool ChangeEventsSupported()

      {

      throw new NotImplementedException();

      }

      error is "The method or operation is not implemented."

      So please help me slove the issue. Also could you please send me the full source code for the above example.

      Thank you.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Hi Amila,

      Your error simply means that the method has no executable code. You have to change the NotImplementedExeception with your own code. Also I am happy to send you the code.

      Kevin

    • profile image

      Avital 4 years ago

      Can you send me the source code to avitalbe@gmail.com

      Do you have any sample of sending or receiving idoc

      Thanks

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      No sorry I don't at the moment

    • Anjo Bacarisas II profile image

      Anjo Bacarisas II 4 years ago from Cagayan de Oro, Philippines

      very great... this is very helpful to me and my friends. we are very interested on SAP

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Glad to hear and I appreciate the feedback.

    • profile image

      shimaa 4 years ago

      Very great documentation...i am a beginner to SAP with C#

      so i have some problems at

      event RfcDestinationManager.ConfigurationChangeHandler IDestinationConfiguration.ConfigurationChanged

      {

      add { throw new NotImplementedException(); }

      remove { throw new NotImplementedException(); }

      }

      i do not know how i should implement it ...depends on what??

      And this function what should do ...returns true or false for what?

      bool IDestinationConfiguration.ChangeEventsSupported()

      {

      return false;

      }

      is there any condition before return true or false???

      these two functions which i didn't understand, i will be thankful if u explained them to me and tell me how implement them

      can you send to me the source code??

      My email shimaa.younes@jupiter2000.com

    • profile image

      Saqlain 4 years ago

      Dear

      Kindly tell me can I download the connector without having customer id and password ??

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Saqlain

      To get the NCo connector, you need to have a customer id since it is only available to SAP customers.

      shimaa

      You don't have to implement them unless you want to handle a change in logon configuration. You could add code to login into a different client with different credentials. You could provide alternate login credentails.

    • profile image

      Andrew 4 years ago

      Tks a lot for your example! Is the most complete and comprehensive I ever found!

      I`m starting now to integrate SAP and C# apps, and the SAP world is kind of new (and confusing) to me!

      I still didn`t get how you have defined the IRFCTable and how can I know what a function can return (and how to define what to return). Can you please give some adivice or point where to find more material about that?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks Andrew for the great feedback!

      To know what a BAPI or RFC returns, you have to look at the object in the Object Repository in SAP, transaction BAPI. Switch to the Alphabethical listing and select the filter icon and select all.

      Scroll down to a business object, say SalesOrder.

      Expand the node and select GetList

      click on the Tools tab and select Function Builder

      Click on the Display button to view the details of the BAPI/RFC

      Once the BAPI is open in the Function Builder

      Click on Import tab to view import parameters

      Click on Export for any return variables, or

      Click on Tables to view returning tables or structures

      Click on Source code to view the source code of the RFC

      Hope this helps

    • profile image

      Andrew 4 years ago

      Terrific! Tanks again!

      Can you please send the code sample to my e-mail? (andrelmgomes@gmail.com)?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Sure, you can download the code from the following Google Code site

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

      Good Luck

    • profile image

      MRAA 4 years ago

      Hi.

      Nice post, what i really needed, but i m facing this error.

      "Hard-coded logon parameters not allowed when using a DestinationConfiguration"

      plz help me

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Did you try passing your logon credentials either from a command line or from a resource file?

    • profile image

      Krishna 4 years ago

      Wonderful example of using .net connector. Thank you so much. You saved several hours of struggle.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thank you for the wonderful feedback Krishna. I am glad my tutorial has been able to help you with your work.

    • profile image

      Raj Arora 4 years ago

      Thanks for this helpful article. When I implemented the interface,

      i get following error.

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

      Request you to please help. Thanks in advance.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Did you add the RFC dll in your 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

    • profile image

      jim tanng 4 years ago

      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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      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.

    • profile image

      jim tang 4 years ago

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      I will check and hopefully I can help.

    • profile image

      Oskar 4 years ago

      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?

    • profile image

      Jose Antonio 4 years ago

      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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      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

    • profile image

      Sylvergirl 4 years ago

      Excellent

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks

    • profile image

      harry 4 years ago

      Superb post

    • profile image

      harry 4 years ago

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

    • infotechnology profile image

      Omogiade, Stephen Nosakhare 4 years ago from Lagos, Nigeria.

      This is a nice hub, very educative

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      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

    • profile image

      Sathish 4 years ago

      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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Sorry no I don't

    • profile image

      eray kaya 4 years ago

      Excellent. can u send me this project.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Thanks Eray Kaya,

      You can download the code at this address:

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

      Thanks

    • profile image

      Ish 4 years ago

      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,

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      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

    • profile image

      Gabi 4 years ago

      This works fine for x86 compilations.

      However, It's not working for x64.

      Exists some installer the sap connector for 64 bits?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      .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

    • profile image

      Ashish 4 years ago

      Dear

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

      thanks

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Ashish,

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

    • profile image

      satrughan mahato 4 years ago

      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.

    • profile image

      Andrew 4 years ago

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

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      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

    • profile image

      Satrughan mahato 4 years ago

      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.

    • profile image

      satrughan mahato 4 years ago

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      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.

    • profile image

      satrughan mahato 4 years ago

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

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

      SIGN

      OPTION

      LOW

      HIGH

    • profile image

      satrughan mahato 4 years ago

      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?

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

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

    • profile image

      Jonathan 4 years ago

      Can you help me, I have an error in

      RfcRepository repo = destination.Repository

      Object reference not set to an instance of an object.

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

      Jonathan,

      Did you add a reference to the rfc libs

    • profile image

      Jonathan 2 4 years ago

      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

    • profile image

      Jonathan 2 4 years ago

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

      Seems I was missing a prerequisite

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 years ago from Canada

    • profile image

      Sagar 4 years ago

      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?

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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

    • profile image

      cedric finet 3 years ago

      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

    • profile image

      Aman 3 years ago

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

      Any help will be really appreciated.

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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.

    • profile image

      Amine 3 years ago

      hey can you send me working example on

      amineraoui@hotmail.com

      i have some errors in

      RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      you can download the code from here

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

    • profile image

      Paulo Rocha 3 years ago

      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.

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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;

    • profile image

      Arjun Walmiki 3 years ago

      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.

    • profile image

      Luffy 3 years ago

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

      luffy.syu@motorpro.com.tw?

    • profile image

      Anoop 3 years ago

      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

    • profile image

      Luis 3 years ago

      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'

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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/

    • profile image

      Lois 3 years ago

      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

    • profile image

      Anoop 3 years ago

      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.

    • profile image

      Eduardo 3 years ago

      This information is great. Congratulations.

      How can I check for existing connections?

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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

    • profile image

      ChloeLim 3 years ago

      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)

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      Yes that is correct.

    • profile image

      ChloeLim 3 years ago

      Thanks for confirming. :)

    • profile image

      vijay 3 years ago

      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

    • profile image

      RAM 3 years ago

      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

    • profile image

      MohsenSam 3 years ago

      Hi

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

      thanks

      mohsensamano@gmail.com

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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

    • profile image

      pk 3 years ago

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

    • profile image

      Ismael 3 years ago

      Thank you, works perfect!!

    • profile image

      rajesh 3 years ago

      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

    • profile image

      fei 3 years ago

      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.

    • profile image

      fei 3 years ago

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

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

      thanks!

    • profile image

      Ranjan 3 years ago

      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.

    • klanguedoc profile image
      Author

      Kevin Languedoc 3 years ago from Canada

      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

    • profile image

      Star Moe 2 years ago

      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

    • profile image

      Atul Sharma 2 years ago

      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

    • profile image

      Richard 2 years ago

      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?

    • klanguedoc profile image
      Author

      Kevin Languedoc 2 years ago from Canada

      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.

    • profile image

      Imran 19 months ago

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

    • profile image

      Imran 19 months ago

      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?

    • profile image

      Niels 12 months ago

      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

    • profile image

      Ashish Tasare 9 months ago

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 months 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

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 months ago from Canada

      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

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 months ago from Canada

      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.

    • profile image

      Ashish Tasare 5 months ago

      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

    • profile image

      Ashish Tasare 5 months ago

      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

    • klanguedoc profile image
      Author

      Kevin Languedoc 5 months ago from Canada

      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

    • profile image

      Hans 4 months ago

      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 .

    • profile image

      FranciscoRomero 4 months ago

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

    • klanguedoc profile image
      Author

      Kevin Languedoc 4 months ago from Canada

      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.

    • profile image

      Ashish Tasare 3 months ago

      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?

    • profile image

      Mecit 2 months ago

      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?

    Click to Rate This Article