SapNwRfc中的配置参数,记录日志关闭 Trace=0,可以得到很好的性能。
有网友在问,SAP RFC返回多张表(C# 使用 SapNwRfc 一)中如何输入一张表的数据,正好博主也遇到了这个场景,今天做了一个DEMO,详细代码如下:
using SapNwRfc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace saprfc2024table
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
callsap();
}
void callsap()
{
string connectionString = "AppServerHost=xxx.xxx.xxx.xxx; SystemNumber=00; User=xxxxxx;Password=xxxxxxx Client=700; Language=ZH; PoolSize=5; Trace=0";
var connection = new SapConnection(connectionString);
connection.Connect();
toolStripStatusLabel1.Text = "Logon SAP Server...";
/*
InputItem[] inputItem = new InputItem[]
{
new InputItem { WERKS = "1003" },
new InputItem { WERKS = "1003" },
};
*/
//新建一个对象数组,大小10000
InputItem[] inputItem = new InputItem[10000];
for (int i = 0; i < 10000; i++)
{
inputItem[i] = new InputItem { WERKS = "1003",ZMENG = i };
}
//对象数组交给对象表
InputTable inputTable = new InputTable();
inputTable.Items = inputItem;
//调用函数,输入是一张表10000条数据,输出是函数返回的结果
var someFunction = connection.CreateFunction("ZSAP_PP_APS_XXXXX_IN");
var result = someFunction.Invoke<ReturnTable>(inputTable);
//显示返回的结果
foreach ( var item in result.Items )
{
listBox1.Items.Add(item.STATUS + " " + item.MESSAGE);
}
}
}
class InputTable
{
[SapName("IT_INPUT")]
public InputItem[] Items { get; set; }
}
class InputItem
{
[SapName("WERKS")]
public string WERKS { get; set; }
[SapName("MATNR")]
public string MATNR { get; set; }
[SapName("ATWRT")]
public string ATWRT { get; set; }
[SapName("Z_SALE_PACK")]
public string Z_SALE_PACK { get; set; }
[SapName("ATWRT1")]
public string ATWRT1 { get; set; }
[SapName("ATWRT2")]
public string ATWRT2 { get; set; }
[SapName("ETDAT")]
public string ETDAT { get; set; }
[SapName("ZMENG")]
public double ZMENG { get; set; }
[SapName("ZIEME")]
public string ZIEME { get; set; }
}
class ReturnTable
{
[SapName("ET_RETURN")]
public ReturnItem[] Items { get; set; }
}
class ReturnItem
{
[SapName("STATUS")]
public string STATUS { get; set; }
[SapName("MESSAGE")]
public string MESSAGE { get; set; }
}
}
只用了1秒钟,SAP中灌入了10000条数据