java - 通过 JCo 访问 SAP 表

标签 java sap-erp jco

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

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

非常感谢有关如何通过仅指定表名称和列来访问 SAP 表的任何帮助。提前致谢。

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 表,请使用 RFC RFC_READ_TABLE (通过 RFC 对 R/3 表进行外部访问)

  • 参数QUERY_TABLE - 在此处指定表名称
  • (可选)参数ROWSKIPS - 跳过第一条记录
  • (可选)参数ROWCOUNT - 要加载的最大行数,出于性能考虑

关于java - 通过 JCo 访问 SAP 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661491/

相关文章:

java - 居中 jFrame

abap - 确定当前 MM 周期?

java - 管理对单个数据库的多线程访问的各种方法有哪些?

java - 如何使用 phantomjs headless 浏览器处理 selenium 中的警报

sap-erp - 是否可以将订单从 ECC 6.0 中的系统传输到 46C 中的 SAP R3 系统?

jco - SAP JCo 客户端与服务器

bapi - 使用 TransactionID 时 SAP JCo RETURN 表为空

java - 使用 JCo 打印 BAPI 列表

java - 源分析器 : command not found (mac)

python-3.x - 使用pyrfc获取FAGLL03H报告