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 に答える