基類:RfcBaseException
nco3.0中異常的基類是RfcBaseException, 繼承自ApplicationException。其他一些重要的異常類說明如下:
其他常見異常類
RfcCommunicationException
- 繼承自RfcBaseException
- 與后臺SAP系統(tǒng)通訊失敗時,引發(fā)此異常,比如網(wǎng)絡(luò)問題,SAP服務(wù)器沒有啟動等。
RfcLogonException
- 繼承自RfcBaseException
- SAP系統(tǒng)拒絕用戶登錄,比如密碼錯誤等引發(fā)的異常。
RfcInvalidParameterException
- 繼承自RfcBaseException
- 如果參數(shù)不存在,或者參數(shù)名不正確,會引發(fā)該異常。
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函數(shù)將字串中插入到TCPIC表中,函數(shù)適合做演示之用
- 如果插入table parameter的參數(shù)有規(guī)律,可以參考本例中的代碼
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系統(tǒng)專題
http://www.cnblogs.com/mengxin523/category/315696.html