基类:RfcBaseException
nco3.0中异常的基类是RfcBaseException, 继承自ApplicationException。其他一些重要的异常类说明如下:
其他常见异常类
RfcCommunicationException
- 继承自RfcBaseException
- 与后台SAP系统通讯失败时,引发此异常,比如网络问题,SAP服务器没有启动等。
RfcLogonException
- 继承自RfcBaseException
- SAP系统拒绝用户登录,比如密码错误等引发的异常。
RfcInvalidParameterException
- 继承自RfcBaseException
- 如果参数不存在,或者参数名不正确,会引发该异常。
RfcAbapBaseException
- 继承自RfcBaseException, 是Abap异常的基类
示例
using System;
using SAP.Middleware.Connector;
namespace NCo03
{
public class ExceptionHandlingDemo
{
public void WriteTCPIC()
{
// the folowing lines will be added to TCPIC table in SAP system
String[] lines = new String[] {
"轻轻的我走了,",
"正如我轻轻的来,",
"我轻轻的招手,",
"作别西天的云彩。"};
try {
RfcDestination dest = NCo02.DestinationProvider.GetDestination();
IRfcFunction fm = dest.Repository.CreateFunction("STFC_WRITE_TO_TCPIC");
IRfcTable tcpicData = fm.GetTable("TCPICDAT");
tcpicData.Append(lines.Length); // insert lines according to lines.Length
for (int i = 0; i < lines.Length; i++) {
tcpicData[i].SetValue("LINE", lines[i]);
}
fm.Invoke(dest);
}
catch (RfcCommunicationException ex) {
// network problem
System.Console.WriteLine(ex.ToString());
}
catch (RfcLogonException ex) {
// user could not log on
System.Console.WriteLine(ex.ToString());
}
catch (RfcAbapBaseException ex) {
// ABAP excpeption
System.Console.WriteLine(ex.ToString());
}
}
}
}
说明
- STFC_WRITE_TO_TCPIC函数将字串中插入到TCPIC表中,函数适合做演示之用
- 如果插入table parameter的参数有规律,可以参考本例中的代码
NCo3.0系列的参考文档
SAP .NET Connector 3.0官方帮助
http://help.sap.com/saphelp_crm700_ehp02/helpdata/EN/4a/097b0543f4088ce10000000a421937/content.htmA Spotlight on the New .NET Connector 3.0
http://scn.sap.com/people/thomas.weiss/blog/2011/01/14/a-spotlight-on-the-new-net-connector-30Add items to IRfcTable
http://stackoverflow.com/questions/4783739/add-items-to-irfctable
SAP NCo 3.0: How-to Pass Table Parameters to SAP RFC
http://www.dataxstream.com/2012/03/sap-nco-3-0-how-to-pass-table-parameters-to-sap-rfc/SAP .Net Connector 3.0 (NCo) Example
http://www.codeproject.com/Articles/824928/SAP-Net-Connector-NCo-Example.NET连接SAP系统专题
http://www.cnblogs.com/mengxin523/category/315696.html