zoukankan      html  css  js  c++  java
  • 浅析在C#里面抛出SAP里面自定义的异常信息

    首先运行“SE37”在Exceptions页面增加异常信息,Exception为异常信息的代码,Short Text则为异常信息的详细文本,如图:

    C#里面如果需要抛出用户自定义的异常,那么使用RfcAbapException即可,这个Exception是专门用来获取用户自定义的异常的。

     1   public void GetAllInfo(RfcDestination prd)
     2         {
     3             RfcRepository repo = prd.Repository;
     4             IRfcFunction irfc = repo.CreateFunction("ZAGETSAPDATAT");
     5             try
     6             {
     7                 irfc.SetValue("VTYPE", "0");
     8                 irfc.Invoke(prd);
     9                 string Value = irfc.GetValue("RRESULT").ToString();
    10             }
    11 
    12              //RfcAbapException   用于获取用户自定义的异常信息。
    13             //RfcTypeConversionException  用于获取数据之间类型转换失败的异常信息。
    14             catch (RfcAbapException ex)
    15             {
    16                 //Documentation获取对应的异常的说明文字.通过Key来获取。
    17                 MessageBox.Show(irfc.Metadata.GetAbapException(ex.Key).Documentation);
    18             }
    19 
    20 
    21             IRfcTable table = irfc.GetTable("IT_ZMYTB2");
    22             DataTable dt = new DataTable();
    23             dt.Columns.Add("USERID");
    24             dt.Columns.Add("USERPWD");
    25             dt.Columns.Add("USERADDRESS");
    26 
    27             for (int i = 0; i < table.RowCount; i++)
    28             {
    29                 table.CurrentIndex = i;
    30                 DataRow dr = dt.NewRow();
    31 
    32                 dr["USERID"] = table.GetString("USERID");
    33                 dr["USERPWD"] = table.GetString("USERPWD");
    34                 dr["USERADDRESS"] = table.GetString("USERADDRESS");
    35                 dt.Rows.Add(dr);
    36             }
    37 
    38             dgv.DataSource = dt;
    39             //prd = null;
    40             //repo = null;
    41         }

    效果如下图所示,抛出的错误信息就是SAP里面自定义的Exception。

查看全文
  • 相关阅读:
    PTA 1007 Maximum Subsequence Sum (25 分)
    c++ primer 6th 函数
    redis源码笔记(持续更新)
    c文件函数总结
    PAT基础知识点
    vector模糊查询
    c++ primer 15th 面向对象程序设计
    c++ primer 18th 用于大型程序的工具
    c++ primer 19th 特殊工具与技术
    MFC TreeCtrl
  • 原文地址:https://www.cnblogs.com/allen0118/p/2530526.html
  • Copyright © 2011-2022 走看看