首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过JCO访问SAP表

通过JCO访问SAP表
EN

Stack Overflow用户
提问于 2014-09-04 09:11:00
回答 1查看 2.7K关注 0票数 1

我目前正在使用SAP连接到SAP,并从SAP表中获取数据。我使用内部BAPI函数从SAP表中获取数据。我想知道如何从SAP表中获取数据的方法,只需指定表名和应该从中检索数据的列。

下面是我用来通过BAPI函数获取数据的代码。

代码语言:javascript
复制
JCoFunction function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST");
    if(function == null)
        throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP.");

    try
    {
        function.execute(destination);
    }
    catch(AbapException e)
    {
        System.out.println(e.toString());
        return;
    }

    JCoStructure returnStructure = function.getExportParameterList().getStructure("RETURN");
    if (! (returnStructure.getString("TYPE").equals("")||returnStructure.getString("TYPE").equals("S"))  )   
    {
       throw new RuntimeException(returnStructure.getString("MESSAGE"));
    }

    JCoTable codes = function.getTableParameterList().getTable("COMPANYCODE_LIST");
    final FileWriter outFile = new FileWriter("D:\\out.csv");

    for (int i = 0; i < codes.getNumRows(); i++) 
    {
        codes.setRow(i);

    }


    codes.firstRow();
    for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) 
    {
        function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETDETAIL");
        if (function == null) 
            throw new RuntimeException("BAPI_COMPANYCODE_GETDETAIL not found in SAP.");

        function.getImportParameterList().setValue("COMPANYCODEID", codes.getString("COMP_CODE"));
        function.getExportParameterList().setActive("COMPANYCODE_ADDRESS",false);

        try
        {
            function.execute(destination);
        }
        catch (AbapException e)
        {
            System.out.println(e.toString());
            return;
        }

        returnStructure = function.getExportParameterList().getStructure("RETURN");
        if (! (returnStructure.getString("TYPE").equals("") ||
               returnStructure.getString("TYPE").equals("S") ||
               returnStructure.getString("TYPE").equals("W")) ) 
        {
            throw new RuntimeException(returnStructure.getString("MESSAGE"));
        }

        JCoStructure detail = function.getExportParameterList().getStructure("COMPANYCODE_DETAIL");

任何关于如何通过指定表名和列来访问SAP表的帮助都是非常感谢的。提前谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-07-06 08:31:22

若要仅通过指定表名和列来访问SAP表,请使用RFC 表格 (通过RFC外部访问R/3表)。

  • 参数QUERY_TABLE -在此处指定表名
  • (可选)参数ROWSKIPS -跳过第一条记录
  • (可选)参数ROWCOUNT - max行计数要加载,以考虑性能问题
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25661491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档