【问题标题】:RFC_READ_TABLE passing "options" and "Fields" parameters (c#)RFC_READ_TABLE 传递“选项”和“字段”参数(c#)
【发布时间】:2014-12-24 07:38:53
【问题描述】:

需要帮助,我正在尝试使用 RFC_READ_TABLE 从 SAP 获取销售数据,但不知道如何将 OPTIONS 和 FIELDS 参数传递给 SAP。这是我的应用程序的示例代码。

连接正常,执行后出现异常“DATA_BUFFER_EXCEEDED”

public void RFC_READ_TABLE()
    {
        try
        {
            ECCDestinationConfig cfg = new ECCDestinationConfig();

            RfcDestinationManager.RegisterDestinationConfiguration(cfg);

            RfcDestination dest = RfcDestinationManager.GetDestination("ABI_ERP");

            RfcRepository repo = dest.Repository;

            IRfcFunction fn = repo.CreateFunction("RFC_READ_TABLE");

            fn.SetValue("QUERY_TABLE", "VBAP");

            fn.GetTable("DATA");

            fn.Invoke(dest);

            var companyCodeList = fn.GetTable("VBAP");

            var companyDataTable = companyCodeList.ToDataTable("VBAP");

            dataGridView1.DataSource = companyDataTable;
        }
        catch (RfcBaseException x)
        {

            MessageBox.Show("Some problems in programe execution. Check entered data, and try again." +
                                        "\n" +
                                        "\n<SAP Remote Execution Error>" +
                                        "\n" +
                                        "\nAdditional Information on Error: " + x.Message, "Oops, Runtime Error");
        }
    }

【问题讨论】:

标签: c# abap sap-dotnet-connector


【解决方案1】:

RFC_READ_TABLE 不是用于读取销售订单数据的理想功能模块(它实际上是为快速-n'-脏表读取而设计的,其中没有其他内容)。我会调查以下支持 RFC 的功能模块:

  • BAPI_SALESORDER_GETLIST - 获取销售文件列表
  • BAPISDORDER_GETDETAILEDLIST - 阅读单个销售文件的详细信息

如果您查看功能组 2032 或 Sales and Distribution -> Sales -> Sales Order 在事务 BAPI你会找到其他可能有帮助的。

【讨论】:

    【解决方案2】:

    你应该只定义你真正需要的列,比如在SQL中SELECT之后,即销售单据、项目和物料编号:

    IRfcTable fieldsTable = fn.GetTable("FIELDS");
    fieldsTable.Append();
    fieldsTable.SetValue("FIELDNAME", "VBELN"); //Sales Document
    fieldsTable.Append();
    fieldsTable.SetValue("FIELDNAME", "POSNR"); // Sales Document Item
    fieldsTable.Append();
    fieldsTable.SetValue("FIELDNAME", "MATNR"); // Material number
    

    如果您不这样做,调用将因为超出数据缓冲区而失败,正如您所提到的。这是因为RFC_READ_TABLE 函数中的DATA 结构是TAB512 类型,这意味着每行最多只能包含512 个字符。您查询的表 (VBAP) 中组合的所有列的内容长度约为 1500 个字符。 Here you can see the length of each field.

    然后你也想过滤表,类似于 SQL 中的WHERE 子句。

    IRfcTable options = fn.GetTable("OPTIONS");
    options.Append();
    options.SetValue("TEXT", "VBELN = '000000000' AND POSNR = '000000'");
    options.Append();
    options.SetValue("TEXT", " OR VBELN = '000000001' AND POSNR = '000001'");
    

    这里您也需要小心,因为每个选项文本的长度最多应为 72 个字符。如果您需要多个或更长的WHERE 子句,只需附加新选项,如fileds。 我注意到,OR 在某些表上会导致一些性能问题。

    设置好函数的这两个属性后,你应该可以成功调用它了。

    【讨论】:

      【解决方案3】:

      使用 RFC_READ_TABLE 的“选项”和“字段”表选项来缩小查询范围。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-07-20
        • 1970-01-01
        • 1970-01-01
        • 2021-10-10
        • 1970-01-01
        • 2018-12-08
        • 1970-01-01
        相关资源
        最近更新 更多