zoukankan      html  css  js  c++  java
  • RFC调用SAP接口程序之直接读取SAP表案例4

    这个需要有SAP相关基础知识。最起码SAP表结构要熟悉。

        //根据品号读取计量单位
                IDestinationConfiguration ID = new RfcConfig();
                RfcDestinationManager.RegisterDestinationConfiguration(ID);
                RfcDestination prd = RfcDestinationManager.GetDestination("PRD_000");
                RfcDestinationManager.UnregisterDestinationConfiguration(ID);
                RfcRepository repo = prd.Repository;
                IRfcFunction companyBapi = repo.CreateFunction("RFC_READ_TABLE");   //调用函数名
                IRfcFunction companyBapi1 = repo.CreateFunction("RFC_READ_TABLE");   //调用函数名
    
                try
                {
                    companyBapi.SetValue("QUERY_TABLE", "MARM");                        //设置Import的参数
    
                    IRfcTable OPTIONS = companyBapi.GetTable("OPTIONS");
                    OPTIONS.Insert();
                    OPTIONS.CurrentRow.SetValue("TEXT", "MATNR = '" + txt01.Text.Trim().ToUpper() + "'");
                    companyBapi.SetValue("OPTIONS", OPTIONS);
    
                    IRfcTable FIELDS = companyBapi.GetTable("FIELDS");
                    FIELDS.Insert();
                    FIELDS.CurrentRow.SetValue("FIELDNAME", "MEINH");
                    FIELDS.CurrentRow.SetValue("LENGTH", "3");
                    FIELDS.CurrentRow.SetValue("TYPE", "C");
                    FIELDS.CurrentRow.SetValue("FIELDTEXT", "MEINH");
    
                    companyBapi.SetValue("FIELDS", FIELDS);
                    companyBapi.Invoke(prd);   //执行函数
                    IRfcTable RETURNTable = companyBapi.GetTable("DATA");
    
                    for (int i = 0; i < RETURNTable.RowCount; i++)
                    {
                        RETURNTable.CurrentIndex = i;
                        ddlcs.ddlInsertValue(ddl01, RETURNTable.GetString("WA").Trim());
                    }
    
                    ddlcs.ddlInsertValue(ddl01, "");
    
                    companyBapi1.SetValue("QUERY_TABLE", "MBEW");                        //设置Import的参数
    
                    IRfcTable OPTIONS1 = companyBapi1.GetTable("OPTIONS");
                    OPTIONS1.Insert();
                    OPTIONS1.CurrentRow.SetValue("TEXT", "MATNR = '" + txt01.Text.Trim().ToUpper() + "' AND BWKEY = '1601'");
                    companyBapi1.SetValue("OPTIONS", OPTIONS1);
    
                    IRfcTable FIELDS1 = companyBapi1.GetTable("FIELDS");
                    FIELDS1.Insert();
                    FIELDS1.CurrentRow.SetValue("FIELDNAME", "BKLAS");
                    FIELDS1.CurrentRow.SetValue("LENGTH", "4");
                    FIELDS1.CurrentRow.SetValue("TYPE", "C");
                    FIELDS1.CurrentRow.SetValue("FIELDTEXT", "BKLAS");
    
                    companyBapi1.SetValue("FIELDS", FIELDS1);
                    companyBapi1.Invoke(prd);   //执行函数
                    IRfcTable RETURNTable1 = companyBapi1.GetTable("DATA");
    
                    if (RETURNTable1.RowCount == 1)
                    {
                        RETURNTable1.CurrentIndex = 0;
                        hd01.Value = RETURNTable1.GetString("WA").Trim();//评价类别
                    }
                    else
                    {
                        hd01.Value = null;
                    }
                }
                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);
                }
    你的一分支持,是我坚持创作的十分动力。 如果文章的内容对你有帮助的话,请用微信扫描下方二维码,支持一下。谢谢! wechat1
  • 相关阅读:
    第二阶段站立会议05
    第二阶段站立会议04
    第一阶段冲刺总结
    站立会议08
    站立会议07
    站立会议06
    站立会议05
    站立会议04
    第一次冲刺第3天
    站立会议2
  • 原文地址:https://www.cnblogs.com/shuilong/p/13940848.html
Copyright © 2011-2022 走看看