cancel
Showing results for 
Search instead for 
Did you mean: 

Call BAPI using SAP .NET Connector 3.0

Former Member
0 Kudos

Dear

I installed visual studio 2008 and SAP .NET connector 3.0.

How can I call a BAPI from vb.net ?

Accepted Solutions (0)

Answers (4)

Answers (4)

frank_wagner2
Participant
0 Kudos

Considering the EOL of .NET Connector 3.0 and the move to .NET core I would also to mention here our alternative YaNco (Yet Another .NET Connector).

It is open source, you can find it on github https://github.com/dbosoft/YaNco and nuget.

Former Member
0 Kudos

Shafi, .net connector 3 works with .net framework4, try it in vs 2010.

former_member197445
Contributor
0 Kudos

I neglected to mention that you must reference "sapnco.dll" in your project. Also, make sure your target framework is ".NET v4.0" NOT ".NET v4.0 Client" -- that way you get the System.Web namespace that is required.

Former Member
0 Kudos

Hello Expert,

When I use bellow code, no values display in my webform, can you help me to find where am goes wrong.

     try

            {

               

                RfcDestinationManager.RegisterDestinationConfiguration(new Class1());

                RfcDestination mydestination = RfcDestinationManager.GetDestination("SE37");

                RfcRepository myrepository = mydestination.Repository;

                IRfcFunction Bapiemployeelist = myrepository.CreateFunction("BAPI_EMPLOYEE_GETDATA");

                Bapiemployeelist.SetValue("EMPLOYEE_ID", TextBox1.Text.Trim());

                Bapiemployeelist.Invoke(mydestination);

               

                IRfcTable Employeetable = Bapiemployeelist.GetTable("PERSONAL_DATA");

                if (Employeetable.RowCount>0)

                {

                    TextBox2.Text = Employeetable.GetString("PERNO").ToString();

                    TextBox3.Text = Employeetable.GetString("LAST_NAME").ToString();

                    TextBox4.Text = Employeetable.GetString("FIRSTNAME").ToString();

                    TextBox6.Text = Employeetable.GetString("COSTCENTER").ToString();

                }

            }

            catch (RfcInvalidParameterException exec)

            {

                Label1.Text = exec.Message;

            }

            catch (RfcTypeConversionException exec2)

            {

                Label1.Text = exec2.Message;

            }

            catch (RfcCommunicationException exec1)

            {

                Label1.Text = exec1.Message;

            }

            catch (RfcBaseException exec3)

            {

                Label1.Text = exec3.Message;

            }

           

        }

    }

    }

former_member197445
Contributor
0 Kudos

First, create a class that implements IDestinationConfiguration. VB.NET code shown below.

Imports SAP.Middleware.Connector

Public Class ECCDestinationConfig
    Implements IDestinationConfiguration

    Public Event ConfigurationChanged(ByVal destinationName As String, ByVal args As RfcConfigurationEventArgs) Implements IDestinationConfiguration.ConfigurationChanged

    Public Function GetParameters(ByVal destinationName As String) As RfcConfigParameters Implements IDestinationConfiguration.GetParameters

        Dim parms As New RfcConfigParameters

        Select Case destinationName

            Case "ECDCLNT140"

                parms.Add(RfcConfigParameters.AppServerHost, "10.1.1.1")
                parms.Add(RfcConfigParameters.SystemNumber, "00")
                parms.Add(RfcConfigParameters.SystemID, "ECD")
                parms.Add(RfcConfigParameters.User, "username")
                parms.Add(RfcConfigParameters.Password, "secret")
                parms.Add(RfcConfigParameters.Client, "140")
                parms.Add(RfcConfigParameters.Language, "EN")
                parms.Add(RfcConfigParameters.PoolSize, "5")
                parms.Add(RfcConfigParameters.MaxPoolSize, "10")
                parms.Add(RfcConfigParameters.IdleTimeout, "600")

            Case Else

        End Select

        Return parms

    End Function

    Public Function ChangeEventsSupported() As Boolean Implements IDestinationConfiguration.ChangeEventsSupported
        Return False
    End Function

End Class

Then, create a web application, console application, web service, whatever, that uses the NCo 3.0 object model. Very simple stuff to call an RFC enabled Function Module. See sample Console application below:

Imports SAP.Middleware.Connector

Module Driver

    Private _ecc As RfcDestination

    Sub Main()

        RfcDestinationManager.RegisterDestinationConfiguration(New ECCDestinationConfig)

        Try

            _ecc = RfcDestinationManager.GetDestination("ECDCLNT140")

            GetCompanyName()


        Catch ex As Exception
            System.Console.WriteLine(ex.Message)
            System.Console.ReadLine()
        End Try


    End Sub

    Private Sub GetCompanyName()
        System.Console.WriteLine(String.Format("Successfully connected to System {0} Client {1}.", _ecc.SystemID, _ecc.Client))
        System.Console.WriteLine("Enter a company ID:")

        Dim companyID As String = System.Console.ReadLine()

        While Not String.IsNullOrEmpty(companyID.Trim)

            Dim companyAPI As IRfcFunction = _ecc.Repository.CreateFunction("BAPI_COMPANY_GETDETAIL")
            companyAPI.SetValue("COMPANYID", companyID)

            companyAPI.Invoke(_ecc)

            Dim companyName As String = companyAPI.GetStructure("COMPANY_DETAIL").GetString("NAME1")

            If String.IsNullOrEmpty(companyName.Trim) Then
                companyName = "Not found"
            End If

            System.Console.WriteLine(companyName)

            companyID = System.Console.ReadLine()

        End While
    End Sub

End Module

Pretty sweet how you don't have to define the input or output structures. It's all done behind the scenes. Love it!

Former Member
0 Kudos

Hi

how i can call a BAPI from a simple .NET Client using SAP.Net Connector 3.0?

There is a simple sample that show that?

Thanks you in advance

madhu_vadlamani
Active Contributor
0 Kudos

Hi Enrico,

Check the library functions.

Regards,

Madhu.

Former Member
0 Kudos

Hello all,

I got my connection to work and call SAP.

But, when multiple people shared the connection pool. Sap is not distinguish the user name I have pass user name separately.

Does anyone had tried the multiuser session control under SAP connector 3.0?

Former Member
0 Kudos

Hi Case,

          I see the post has been quite old . Your code sample looks nice and easy.

One thing on the Nco 3.0 connector about hte way it uses the function metadata at run time (using the statement, IRfcFunction objrfc = rep.CreateFunction("ZSOME_TEST") ), Every time this statement is called on various Rfc function names it takes couple of seconds to get the instance of IRfcFunction. When i know my Rfc functions won't change a lot, is there a way to store this metadata some how at design time (not like the design time proxy generation in Nco 2.0)?

The time delay caused in this statement is deteriorating the performance of my .net app. Rest of all the process, of Invoking the actual Rfc function and downloading/ uploading the data goes pretty quickly in not more than a second). Any thoughts around this could be helpful..!

Regards,

KP

Former Member
0 Kudos

Hi Case Ahr

    

     I know this post is OLD, however want to say thanks for your example; I was desperate looking for something like this; I search for almost 2 days until I find this post. It work great and give the exact idea on what need to be done.

Thank you!

Former Member
0 Kudos

The connection with sap is successful,