1

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

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

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 表的帮助。提前致谢

4

1 回答 1

0

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

  • 参数QUERY_TABLE - 在此处指定表名
  • (可选)参数ROWSKIPS - 跳过第一条记录
  • (可选)参数ROWCOUNT - 要加载的最大行数,出于性能考虑
于 2016-07-06T08:31:22.083 回答