on 01-23-2011 7:28 AM
Dear
I installed visual studio 2008 and SAP .NET connector 3.0.
How can I call a BAPI from vb.net ?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Shafi, .net connector 3 works with .net framework4, try it in vs 2010.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
}
}
}
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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!
Your example above is helpful,
The connection with sap is successful,
but when i execute the code , it is not retrieving the value from specified Bapi company .
Even if i give the valid available company ID in sap it returns no name1 .
finally I get "not found" message.
Where i am wrong ?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.