需要的工具:
开发工具:Microsoft Visual Studio 2010 C#环境
NCO3.0:sapnco30dotnet40P_8-20007347.zip(VS2010环境下必须这个版本)
可到此下载:http://download.csdn.net/detail/easyboot/9457770
之后新建项目我这里新建的WPF
需要引用sapnco 和sapnco_utils
在代码中引用 SAP.Middleware.Connector
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using SAP.Middleware.Connector;
namespace SAPRFC
{
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void getSAPData()
{
RfcConfigParameters rfcPar = new RfcConfigParameters();
rfcPar.Add(RfcConfigParameters.Name, "DEV");
rfcPar.Add(RfcConfigParameters.AppServerHost, "192.168.2.1");
rfcPar.Add(RfcConfigParameters.Client, "602");
rfcPar.Add(RfcConfigParameters.User, "userid");
rfcPar.Add(RfcConfigParameters.Password, "userpwd");
rfcPar.Add(RfcConfigParameters.SystemNumber, "00");
rfcPar.Add(RfcConfigParameters.Language, "EN");
RfcDestination dest = RfcDestinationManager.GetDestination(rfcPar);
RfcRepository rfcrep = dest.Repository;
IRfcFunction myfun = null;
myfun = rfcrep.CreateFunction("Z_FI_TRANFER");
myfun.SetValue("COMPANYCODE", "2000"); //SAP传入参数 Single
myfun.SetValue("COMPANYNAME", "COMPANY"); //SAP传入参数 Single
IRfcStructure rfcstructSN = null;
IRfcStructure rfcstructX = null;
rfcstructSN = myfun.GetStructure("GENERALDATA"); //SAP传入参数 Structure
rfcstructSN.SetValue("SERIAL_NO", "TestValue"); //SAP传入参数 Structure
myfun.SetValue("GENERALDATA", rfcstructSN);
myfun.Invoke(dest);
IRfcStructure rfcReturn = myfun.GetStructure("RETURN"); //此处返回类型为Structure 如果是Single类型 则直接调用myfun.GetString("RETURN");
string s = rfcReturn.GetString("TYPE");
}
private void button1_Click(object sender, RoutedEventArgs e)
{
getSAPData();
}
}
}