on 01-14-2011 9:17 PM
Hey All,
I have gotten the NCo.net 3.0.....In the past I built a proof-of-concept to work on the old connector, but the new connector looks totally different. Is there any people out there with a simple connection and simple data retrieve from SAP server?
Hi..
Here i am giving a small code which contains the following scenario:
Whenever u login to SAp through .NET, in the page load you will all the packages in ABAP. When u click on button1, the programs list will be display checklistbox which contains in the package. When you select the button2, the programs will be display in the list view.
Here is the COde:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SAP.Middleware.Connector;
using System.Data.SqlClient;
namespace Code_Optimization
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
public class MyBackendConfig : IDestinationConfiguration
{
public RfcConfigParameters GetParameters(String destinationName)
{
if ("SE38".Equals(destinationName))
{
RfcConfigParameters parms = new RfcConfigParameters();
parms.Add(RfcConfigParameters.AppServerHost, "192.168.1.14");
parms.Add(RfcConfigParameters.SystemNumber, "02");
parms.Add(RfcConfigParameters.User, "abaper");
parms.Add(RfcConfigParameters.Password, "erp@1234");
parms.Add(RfcConfigParameters.Client, "800");
parms.Add(RfcConfigParameters.Language, "EN");
parms.Add(RfcConfigParameters.PoolSize, "5");
parms.Add(RfcConfigParameters.MaxPoolSize, "10");
parms.Add(RfcConfigParameters.IdleTimeout, "600");
return parms;
}
else return null;
}
public bool ChangeEventsSupported()
{
return false;
}
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
private void Form1_Load(object sender, EventArgs e)
{
RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());
RfcDestination prd = RfcDestinationManager.GetDestination("SE38");
RfcRepository repo = prd.Repository;
IRfcFunction companyBapi = repo.CreateFunction("ZBAPI_PACKAGE_GETLIST");
companyBapi.Invoke(prd);
IRfcTable address = companyBapi["ZPACKAGE"].GetTable();
for (int index = 0; index < address.RowCount; ++index)
{
comboBox1.Items.Add(address[index]["DEVCLASS"].GetString());
}
}
private void button1_Click(object sender, EventArgs e)
{
checkedListBox1.Items.Clear();
RfcDestination prd = RfcDestinationManager.GetDestination("SE38");
RfcRepository repo = prd.Repository;
IRfcFunction companyBapi1 = repo.CreateFunction("ZBAPI_PACKAGE_OBJECTLIST");
string package = "EU_" + comboBox1.SelectedItem.ToString();
companyBapi1.SetValue("PACKNAME", package);
companyBapi1.Invoke(prd);
IRfcTable address1 = companyBapi1["TOBJECTS"].GetTable();
if (address1.RowCount != 0)
{
for (int index = 0; index < address1.RowCount; ++index)
{
checkedListBox1.Items.Add(address1[index]["PROGRAM"].GetString());
panel2.Visible = true;
}
}
else
{
MessageBox.Show("No Programs Found");
}
}
private void button2_Click(object sender, EventArgs e)
{
listView1.Visible = true;
listView1.Items.Clear();
RfcDestination prd = RfcDestinationManager.GetDestination("SE38");
RfcRepository repo = prd.Repository;
IRfcFunction companyBapi1 = repo.CreateFunction("ZBAPI_GET_PROGRAM_DETAILS");
companyBapi1.SetValue("PROGRAM", checkedListBox1.SelectedItem.ToString());
companyBapi1.Invoke(prd);
IRfcTable address1 = companyBapi1["PROGDET"].GetTable();
for (int index = 0; index < address1.RowCount; ++index)
{
listView1.Items.Add(address1[index]["STRING"].GetString());
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do you pass in a parameter to the BAPI? I am getting an error on the createnewfunction when I try to call it before I set the parameters.
I am not invoking it yet, just trying to use create new function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Anybody know how to resolve this error? I'm running Windows 7 64, Net Framework 4.0 and the latest net connector, intel 64 bit
Error 9 'RfcConfigParameters' is not declared. It may be inaccessible due to its protection level.
Warning 1 The referenced assembly "sapnco" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project. ConsoleApplication1
Edited by: Brian on Mar 2, 2011 3:12 PM
Solution found
The client profile attempts to restrict the set of referenced assemblies to those that are only interesting to a client application. For example it won't make System.Web available by default because it is not typically valuable to client apps.
For Visual Basic projects, click the Compile tab and then click Advanced Compile Options. The Target Framework list is in the Advanced Compiler Settings dialog box. Select the Full Net Framework.
@Case Ahr
Hello, i am trying to get this to work (your code examples), but i simply can not.
I am usin VB2010.
Among other errors i get this:
Type 'RfcDestination' is not defined.
If i typeSAP.Middleware.Connector and then ., then i dont get the selection 'RfcDestination' in the dropdown. It's the same with IRfcFunction, VB does not know this as well.
How do i make RfcDestination, IRfcFunction etc. know to my program??
I have copy pasted your program into a console application.
Can anyone help??
Ohh, now i see the error i get:
The referenced assembly "sapnco" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
How do i fix this?
Cheers
I had the same Problem, with that options it was solved.
But i have another question, maybe somebody can help me.
I want to connect to our sap server...
I have the username and the password, but everytime i get the error that the username or the password is incorrect.
The other error is, that the repository is NULL...
To solve these errors I need the librfc.dll file, is it right?
Or is there another solution?
Thanks Guys!
Hi Case,
I am following your snip code and looks like I made the connection to SAP server. But my problem is the companyAPI.GetStructure("COMPANY_DETAIL").GetString("NAME1") is returning empty string. But When I call BAPI through SAP directly, I can see the compnay name (NAME1) has value, Do you know why this happens. I am using VS 2008 and framework is 3.5. I Appreciate your help! Thank you!
Assuming your code is identical to the posting above, you can try and debug and see what's going on. Replace this line:
Dim companyName As String = companyAPI.GetStructure("COMPANY_DETAIL").GetString("NAME1")
with these lines
Dim compDetail As IRfcStructure = companyAPI.GetStructure("COMPANY_DETAIL")
' debug "compDetail" object and see what it contains!
Dim companyName As String = compDetail.GetString("NAME1")
If this doesn't help, please post your code, and we can all take a look and offer advice.
Thank you very much, Case for the quick reply.
I changed the code and the IRFCStructure (compDetail) is returning NON-NULL value. It is still same that the NAME1 returning empty string. Is there anything I should check on SAP side? I only checked the BAPI and it is running as expected. Here is the code. Thank you very much for your help!
Imports SAP.Middleware.Connector
Module Module1
Private _ecc As RfcDestination
Sub Main()
RfcDestinationManager.RegisterDestinationConfiguration(New SAPSystemConnect)
Try
_ecc = RfcDestinationManager.GetDestination("SAPServer")
GetCompanyName()
Catch ex As RfcCommunicationException
System.Console.WriteLine(ex.Message)
System.Console.ReadLine()
Catch ex As RfcLogonException
System.Console.WriteLine(ex.Message)
System.Console.ReadLine()
Catch ex As RfcAbapRuntimeException
System.Console.WriteLine(ex.Message)
System.Console.ReadLine()
Catch ex As RfcAbapBaseException
System.Console.WriteLine(ex.Message)
System.Console.ReadLine()
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()
'Dim companyID As String = "1"
While Not String.IsNullOrEmpty(companyID.Trim)
Dim companyAPI As IRfcFunction = _ecc.Repository.CreateFunction("BAPI_COMPANY_GETDETAIL")
companyAPI.SetValue("COMPANYID", companyID)
companyAPI.Invoke(_ecc)
Dim compDetail As IRfcStructure = companyAPI.GetStructure("COMPANY_DETAIL")
Dim companyName As String = compDetail.GetString("NAME1")
If String.IsNullOrEmpty(companyName.Trim) Then
companyName = "Not found"
End If
System.Console.WriteLine("Company name:" & companyName)
companyID = System.Console.ReadLine()
End While
End Sub
End Module
imports SAP.Middleware.Connector
Public Class SAPSystemConnect : 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 "SAPServer"
parms.Add(RfcConfigParameters.AppServerHost, "10.1.1.1")
parms.Add(RfcConfigParameters.SystemNumber, "00")
parms.Add(RfcConfigParameters.SystemID, "EE1")
parms.Add(RfcConfigParameters.User, "User")
parms.Add(RfcConfigParameters.Password, "Pass")
parms.Add(RfcConfigParameters.Client, "100")
parms.Add(RfcConfigParameters.Language, "EN")
parms.Add(RfcConfigParameters.PoolSize, "5")
parms.Add(RfcConfigParameters.PeakConnectionsLimit, "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
Hello,
I have an isse when I execute this code for a second time, I test your code in a window form and does work very well but I need a web services with this, and when I start for a first time and I senda value, the BAPI return another value. But if I try to send another value the system shows an error message:
RfcDestinationManager.RegisterDestinationConfiguration(New ECCDestinationConfig) <- destination configuration already initialized
Could you please help me with this?
Hi Case,
The last one for today
When logging on via SAP GUI -. No problem
When logging on with same details
parms.Add(RfcConfigParameters.AppServerHost, "150.175.248.24")
parms.Add(RfcConfigParameters.SystemNumber, "20")
parms.Add(RfcConfigParameters.SystemID, "PD1")
parms.Add(RfcConfigParameters.User, "xxxxxxxx")
parms.Add(RfcConfigParameters.Password, "xxxxxxxx")
parms.Add(RfcConfigParameters.Client, "606")
parms.Add(RfcConfigParameters.Language, "EN")
parms.Add(RfcConfigParameters.PoolSize, "5")
parms.Add(RfcConfigParameters.MaxPoolSize, "10")
parms.Add(RfcConfigParameters.IdleTimeout, "600")
I get the error
Any idea?
Thanks
ton
Hi Hynek,
not really. In case only the port was wrong, the message would be "connection refused". In this case, network connectivity is not possible to that IP from the host, on which NCo is running. It simply cannot reach the host with that IP.
@Ton: Is the GUI perhaps using a SAPRouter in order to connect to that system? This would explain why it is not reachable with the current set of parameters ...
Best regards,
Markus
Hi Ton, is it the same destination, like you use over here?
If yes let's move to that thread for the resolution. Marcus was perfectly right for usage of the SAPRouter, besides you are using load balanced system, where you shall use rather RfcConfigParameters.MessageServerHost and LogonGroup, instead of AppServerHost and SystemNumber.
Hello, i have a problem.
Because i must two table import to my rfc function.
But didnt worked this method.
My code part is below.
AppServerHost = servername;
SystemNumber = "96";
User = "USER"
Password = "password";
Client = "210";
Language = "TR";
PoolSize = "1";
MaxPoolSize = "1";
IdleTimeout = "0";
CreateFunction = "ZTMTR_WAS_02";
try
{
RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());
}
catch
{
}
RfcDestination prd = RfcDestinationManager.GetDestination("PRD_000");
RfcRepository repo = prd.Repository;
IRfcFunction companyBapi = repo.CreateFunction(CreateFunction.ToString());
IRfcTable import2 = companyBapi.GetTable("ZBASLIK");
for (int i = 0; i < dtbaslik.Rows.Count; i++)
{
import2.Append();
import2.SetValue("PERNR", dtbaslik.Rows[i]["pernr"].ToString());
import2.SetValue("SCHEMT", dtbaslik.Rows[i]["SCHEMT"].ToString());
import2.SetValue("BEGDA", dtbaslik.Rows[i]["begda"].ToString());
import2.SetValue("ENDDA", dtbaslik.Rows[i]["endda"].ToString());
import2.SetValue("KUNDE", dtbaslik.Rows[i]["kunde"].ToString());
import2.SetValue("ZORT1", dtbaslik.Rows[i]["zort1"].ToString());
import2.SetValue("ZLAND", dtbaslik.Rows[i]["zland"].ToString());
import2.SetValue("REINR", dtbaslik.Rows[i][7].ToString());
import2.SetValue("PERIO", dtbaslik.Rows[i][8].ToString());
import2.SetValue("PDVRS", dtbaslik.Rows[i][9].ToString());
}
IRfcTable import = companyBapi.GetTable("ZBELEG");
for (int i = 0; i < dtbeleg.Rows.Count; i++)
{
import.Append();
import.SetValue("BELNR", dtbeleg.Rows[i]["BELNR"].ToString());
import.SetValue("SPKZL", dtbeleg.Rows[i]["SPKZL"].ToString());
import.SetValue("BEART", dtbeleg.Rows[i]["BEART"].ToString());
import.SetValue("MWSKZ", dtbeleg.Rows[i]["MWSKZ"].ToString());
import.SetValue("BETRG", dtbeleg.Rows[i]["BETRG"].ToString());
import.SetValue("BLDAT", dtbeleg.Rows[i]["BLDAT"].ToString());
import.SetValue("BTEXT", dtbeleg.Rows[i]["BTEXT"].ToString());
import.SetValue("WAERS", dtbeleg.Rows[i]["WAERS"].ToString());
import.SetValue("KURSB", dtbeleg.Rows[i]["KURSB"].ToString());
import.SetValue("FFACT", dtbeleg.Rows[i]["FFACT"].ToString());
import.SetValue("TFACT", dtbeleg.Rows[i]["TFACT"].ToString());
import.SetValue("ANZFR", dtbeleg.Rows[i]["ANZFR"].ToString());
import.SetValue("LNDFR", dtbeleg.Rows[i]["LNDFR"].ToString());
import.SetValue("BERFR", dtbeleg.Rows[i]["BERFR"].ToString());
import.SetValue("RGION", dtbeleg.Rows[i]["RGION"].ToString());
import.SetValue("TXJCD", dtbeleg.Rows[i]["TXJCD"].ToString());
import.SetValue("PAYOT", dtbeleg.Rows[i]["PAYOT"].ToString());
import.SetValue("PAYCURR", dtbeleg.Rows[i]["PAYCURR"].ToString());
import.SetValue("ABOVE_LIMIT", dtbeleg.Rows[i]["ABOVE_LIMIT"].ToString());
import.SetValue("PROTECT", dtbeleg.Rows[i]["PROTECT"].ToString());
import.SetValue("pernr", dtbeleg.Rows[i]["pernr"].ToString());
}
companyBapi.SetValue("FUNCTION", "3");
companyBapi.Invoke(prd); // i didnt get any error.But rfc didnt worked.
IRfcTable test = companyBapi.GetTable("LOGTAB");
Normally , test table should contains rows.But didnt return any rows.
Not error or warning .
Could you help me please?
Check out this blogpost [A Spotlight on the New .NET Connector 3.0|SDNWeblogs_Interoperabilitynet%2528SAPNetworkWeblogs%253AInteroperability.NET%2529]
It hightlights the differences and improvements wrt NCo 2.0 (in particular the relieve of explicit connection handling, which previous NCo versions required each application developer to do self); and also has some example code for how to set up a configuration, simple client and simple server.
Best regards, William.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
I creat rfc with SAP .NET CONNECTION 3.0.
The rfc read data from lips,return incorrect values.
i_vbeln = 180009902
clent 880
error:
{STRUCTURE LIPS{VBELN:CHAR10, MANDT:CHAR3,
{TABLE [STRUCTURE LIPS { FIELD VBELN=8800180009 FIELD MANDT=880
right:
{STRUCTURE LIPS{MANDT:CHAR3, VBELN:CHAR10,
why?
i creat a rfc. its tables associated type is lips and import associate type lips-vbeln.
Microsoft .NET Framework4.0 and SAP .NET connector 3.0
.NET Framework4.0 call rfc to return tables.
please look
SAP .Net Connector 3.0 RfC return incorrect values - Stack Overflow
Sorry,i don't understand what you mean.
When I put SAP .NET connector upgrading from 2.0 to 3.0,there is the problem.
this is .Net code.
IRfcFunction fuction = null;
fuction = destination.Repository.CreateFunction("Z_RFC_OPMS_INBOUND_DELIVERY");
fuction.SetValue("I_VBELN", EBELN);
fuction.Invoke(destination);
Console.WriteLine(fuction);
IRfcStructure headtable = fuction.GetStructure("E_LIKP");
IRfcTable itemtable = fuction.GetTable("T_LIPS");
IRfcTable logtable = fuction.GetTable("T_RETURN");
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.