step by step 教你用SAP NCO3.0调用RFC

需要的工具:

开发工具: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();
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值