调用SAP RFC如何传递一个内表参数

来源:互联网 发布:网上商城 免费 建站 编辑:程序博客网 时间:2024/04/29 05:26
搞SAP,ABAP开发的时候,内表是最常用的,SAP中的内表功能强大,相当于C#中的Datatable和数组;C#中无法定义SAP中的内表,那么如何将一个内表传进给SAP呢?
1.先调用RFC,获取一个空的内表结构;
//登录SAP
RfcConfigParameters parameters = GetRfcLoginParameters();//获取登录参数
RfcDestination rd = RfcDestinationManager.GetDestination(parameters);
RfcRepository repo = rd.Repository;

IRfcFunction f = repo.CreateFunction("ZGET_BU_WORKDAY_LOG"); //调用函数名
//首次调用,获取返回的 内表
f.Invoke(rd); //执行函数
IRfcTable itb = f.GetTable("T_ZBO5");


2.获取到内表结构后,往里面填充内容;
//往内表中填充数据
for (int i = 0; i < dt.Rows.Count; i++)
{
itb.Insert();
itb.CurrentRow.SetValue("BU", dt.Rows[i]["BU"].ToString());
itb.CurrentRow.SetValue("DL", dt.Rows[i]["DL"].ToString());
itb.CurrentRow.SetValue("ZDATE", Convert.ToDateTime(dt.Rows[i]["DATE"].ToString()).ToString("yyyy-MM-dd"));
itb.CurrentRow.SetValue("SJSB", dt.Rows[i]["SJSB"].ToString());
itb.CurrentRow.SetValue("PSJB", dt.Rows[i]["PSJB"].ToString());
itb.CurrentRow.SetValue("ZMJB", dt.Rows[i]["ZMJB"].ToString());
itb.CurrentRow.SetValue("FDJB", dt.Rows[i]["FDJB"].ToString());
itb.CurrentRow.SetValue("QJ", dt.Rows[i]["QJ"].ToString());
itb.CurrentRow.SetValue("GSJ", dt.Rows[i]["GSJ"].ToString());
itb.CurrentRow.SetValue("BJ", dt.Rows[i]["BJ"].ToString());
itb.CurrentRow.SetValue("FJ", dt.Rows[i]["FJ"].ToString());

}

3.再次调用RFC,将内表传递进去。

//传递内表参数,执行RFC
f = repo.CreateFunction("ZGET_BU_WORKDAY_LOG"); //调用函数名
f.SetValue(0, itb);
f.Invoke(rd);

注:如果使用智遥工作流自带的接口,可以更方便的调用。
原创粉丝点击