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。

查看全文
  • 相关阅读:
    poj 3278 Catch That Cow(bfs+队列)
    poj 1265 Area(Pick定理)
    poj 2388 Who's in the Middle
    poj 3026 Borg Maze(bfs+prim)
    poj 2485 Highways
    变量引用的错误:UnboundLocalError: local variable 'range' referenced before assignment
    Sysbench硬件基准测试
    Sysbench-OLTP数据库测试
    字典
    操作列表
  • 原文地址:https://www.cnblogs.com/allen0118/p/2530526.html
  • Copyright © 2011-2022 走看看