本篇讲解 NCo3.0 调用 SAP RFM (允许远程调用的函数)的方法。SAP 的 BAPI_COMPANYCODE_GETDETAIL 函数可以查看公司代码的信息。我们先在 SAP 系统中使用 SE37 来说明函数的参数和用法。这个函数只有一个参数需要输入:公司代码。
执行函数运行,测试的显示界面如下:
输出参数 COMPANYCODE_DETAIL 是一个结构,包含公司代码的信息。
DestinationProvider
为了获取 RfcDestination 对象,我们创建一个静态类,将 GetSAPDestination() 设计为一个静态方法。代码文件:DestinationProvider.cs
Rfc 函数调用
和之前RFC调用的方法相比,现在的方法确实方便多了。说下重点:
-
编程人员不用关心与SAP系统的连接,只需要关心RfcDestination,RfcDestination代表后端SAP系统,NCo3.0 负责连接和关闭。我们把 RfcDestination 封装在DestinationProvider 类中,SAPService 类只需要
RfcDestination dest = DestinationProvider.GetDestination();
获取。 -
IRfcFunction 表示 SAP 系统的函数,SAP 函数包含在 Repository 中,所以获取SAP 函数使用下面的代码:
RfcDestination dest = XXX;
RfcRepository repository = dest.Repository;
IRfcFunction fm = repository.CreateFunction("xxx");
一般我们不用关心 Repository,所以也可以写为:
RfcDestination dest = XXX;
IRfcFunction fm = dest.Repository.CreateFunction("xxx")
IRfcStructure
BAPI_COMPANYCODE_GETDETAIL
函数 exporting 参数 COMPANYCODE_DETAIL
是一个结构,我们将它转换成一个 ArrayList,代码如下,在 SAPUtils.cs 中: