zoukankan      html  css  js  c++  java
  • RFC调用SAP接口程序之输入输出结构案例3

          C#通过RFC调用SAP接口系列三,接口程序输入输出结构的调用方法。

    using SAP.Middleware.Connector;

    IDestinationConfiguration ID = new RfcConfig();
            RfcDestinationManager.RegisterDestinationConfiguration(ID);
            RfcDestination prd = RfcDestinationManager.GetDestination("PRD_000");//正式区000环境
            RfcDestinationManager.UnregisterDestinationConfiguration(ID);
            RfcRepository repo = prd.Repository;
            IRfcFunction companyBapi = repo.CreateFunction("ZM_PURCHASE_PO");   //调用函数名
            
            try
            {
                var structSAP = companyBapi.GetStructure("pohead");    //表头
                structSAP.SetValue("ZRELEASE", "1");
                structSAP.SetValue("LIFNR", txtCname.Text.Trim());     //"410001"
                structSAP.SetValue("CITY1", "福建");
                structSAP.SetValue("COUNTRY", "CN");
                structSAP.SetValue("ZFORM", "8080");
                structSAP.SetValue("ZOABH", lblBH.Text.Trim());
    
                IRfcTable tableSAP = companyBapi.GetTable("IT_PO");   //表体
                for (int i = 0; i < gvlist1.Rows.Count; i++)    
                {
                    IRfcStructure st = tableSAP.Metadata.LineType.CreateStructure();
                    st.SetValue("ESOKZ", "0");
                    st.SetValue("BNFPO", gvlist1.Rows[i].Cells[3].Text.Trim());        
                    st.SetValue("MENGE", gvlist1.Rows[i].Cells[7].Text.Trim());        
                    st.SetValue("MEINS", gvlist1.Rows[i].Cells[6].Text.Trim());          //计算 单位  "EA"
                    st.SetValue("EEIND", Convert.ToDateTime(gvlist1.Rows[i].Cells[19].Text.Trim()).ToString("yyyyMMdd"));                           
                    tableSAP.Append(st);
                }
                companyBapi.SetValue("pohead", structSAP);
                companyBapi.SetValue("IT_PO", tableSAP);
                companyBapi.Invoke(prd);   //执行函数
    
                IRfcStructure OPTIONS2 = companyBapi.GetStructure("E_MATNRCOST");      //输出结构
    
                txtSCI04.Text = OPTIONS2.GetString("MAKTX");
                txtSCI05.Text = OPTIONS2.GetString("WRKST");
    
    
                IRfcTable OPTIONS = companyBapi.GetTable("RETURN");    //返回表格值
                bool IsFail = false;
                StringBuilder strMsg = new StringBuilder();
                for (int i = 0; i < OPTIONS.RowCount; i++)
                {
                    OPTIONS.CurrentIndex = i;
    
                    if (OPTIONS.GetString("TYPE").Equals("E"))
                    {
                        IsFail = true;
                        strMsg.Append(OPTIONS.GetString("MESSAGE"));
                        strMsg.Append("<br>");
                    }
    
                }
    
                if (IsFail)
                {
                    SystemTools.displayTips("SAP导入异常!具体明细:" + strMsg.ToString(), 0, lblInfoMsg);
                    return;
                }
            }
            catch (RfcAbapException ex)  //此Exception专门用于获取用户自定义的异常信息!!!!
            {
                twMsgbox.AjaxAlert(companyBapi.Metadata.GetAbapException(ex.Key).Documentation);
            }
            catch (RfcAbapRuntimeException ex)   //此Exception专门用于获取RFC执行过程中的运行时异常!!!!
            {
                twMsgbox.AjaxAlert(companyBapi.Metadata.GetAbapException(ex.Key).Documentation);
            }
            catch (RfcBaseException ex)  //此Exception是总Exception类,可以获取所有的异常,如果有多个Catch,则不可以放第一位!!!!
            {
                twMsgbox.AjaxAlert("号码不存在或者SAP数据库连接出错!信息如下:" + ex.Message);
            }
    你的一分支持,是我坚持创作的十分动力。 如果文章的内容对你有帮助的话,请用微信扫描下方二维码,支持一下。谢谢! wechat1
  • 相关阅读:
    Java 连接Redis客户端 Jedis
    Redis的基本类型
    [Windows Server 2008] 搭建数据云备份
    [Windows Server 2008] PHP安装Memcached
    五大免费主机系统
    当前主要的常用的PHP环境部署套件比较
    [Windows Server 2008] 404错误设置方法
    [Windows Server 2008] IIS配置伪静态方法(Web.config模式的IIS rewrite)
    护卫神·云查杀系统V4.0-安全检测部分
    [Windows Server 2008] 阿里云.云主机忘记密码解决方法
  • 原文地址:https://www.cnblogs.com/shuilong/p/11444734.html
Copyright © 2011-2022 走看看