2016-08-24 16 views
1

私はJCO、例えば次のコードのためのutilのSAPを使用してクエリを作成しています:または複数のオペレータSAPのJava

public static void TEST() throws JCoException { 
      JCoDestination destination; 
      JCoRepository sapRepository; 

      destination = JCoDestinationManager.getDestination(ABAP_AS); 
      JCoDestinationManager.getDestination(ABAP_AS); 
      System.out.println("Attributes:"); 
      System.out.println(destination.getAttributes()); 
      System.out.println(); 

      try { 
       JCoContext.begin(destination); 
       sapRepository = destination.getRepository(); 

       if (sapRepository == null) { 
        System.out.println("Couldn't get repository!"); 
        System.exit(0); 
       } 
       JCoFunctionTemplate functionTemplate = sapRepository.getFunctionTemplate("EM_GET_NUMBER_OF_ENTRIES"); 
       JCoFunction function = functionTemplate.getFunction(); 
       JCoTable itTable = function.getTableParameterList().getTable("IT_TABLES"); 
       itTable.appendRow(); 

       itTable.setValue("TABNAME", "USR02"); 
//    JCoTable returnOptions_ = function.getTableParameterList().getTable("OPTIONS"); 
//    returnOptions_.appendRow(); 
////    //returnOptions.setValue("TEXT", "MODDA GE '20140908' AND MODTI GT '000000'"); 
//    returnOptions_.setValue("TEXT", "BNAME EQ 'USER'"); 
       function.execute(destination); 
       System.out.println(function.getTableParameterList().getTable("IT_TABLES").getInt("TABROWS")); 
       JCoFunctionTemplate template2 = sapRepository.getFunctionTemplate("RFC_READ_TABLE"); 
       System.out.println("Getting template"); 
       JCoFunction function2 = template2.getFunction(); 
       function2.getImportParameterList().setValue("QUERY_TABLE", "USR02"); 
       function2.getImportParameterList().setValue("DELIMITER", ","); 
       function2.getImportParameterList().setValue("ROWCOUNT",5); 
       function2.getImportParameterList().setValue("ROWSKIPS",5); 



       System.out.println("Setting OPTIONS"); 
//    Date date = new Date(1410152400000L); 
       SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); 
//    String dateString = formatter.format(date); 

//    String dt = dateString.substring(0, 8); 
//    String tm = dateString.substring(8); 
//    System.out.println("dt > " + dt + ", tm > " + tm); 

       JCoTable returnOptions = function2.getTableParameterList().getTable("OPTIONS"); 
       returnOptions.appendRow(); 
       //returnOptions.setValue("TEXT", "MODDA GE '20140908' AND MODTI GT '000000'"); 
       returnOptions.setValue("TEXT", "BNAME LIKE 'S%'"); 

//    returnOptions.appendRow(); 
//    returnOptions.setValue("TEXT", "AND TYPE = 'DN'"); 

       System.out.println("Setting FIELDS"); 
       JCoTable returnFields = function2.getTableParameterList().getTable("FIELDS"); 
       returnFields.appendRow(); 
       returnFields.setValue("FIELDNAME", "BNAME"); 
       returnFields.appendRow(); 
       returnFields.setValue("FIELDNAME", "GLTGB"); 
       returnFields.appendRow(); 
       returnFields.setValue("FIELDNAME", "CLASS"); 
//    returnFields.appendRow(); 
       function2.execute(destination); 

//    JCoTable jcoTablef = function2.getTableParameterList().getTable("FIELDS"); 
       JCoTable jcoTabled = function2.getTableParameterList().getTable("DATA"); 

       int icodeOffSet = 0; 
       int icodeLength = 0; 


       int numRows = jcoTabled.getNumRows(); 
       System.out.println("numRows > " + numRows); 
       for(int i=0; i<numRows; i++) { 
        jcoTabled.setRow(i); 
        System.out.println(jcoTabled.getRow()); 
        String BNAME = "BNAE:" + jcoTabled.getString(0); 
//     String GLTGB = "GLTGB:" + jcoTabled.getString(2); 
//     String cls = "GLTGB:" + jcoTabled.getString(3); 
        System.out.println(BNAME + "..."); 
       } 

      } catch (Exception e) { 
       e.printStackTrace(); 
       System.out.println("ERROR: " + e.getMessage()); 
      } finally { 
       JCoContext.end(destination); 
      } 
     } 
     static void createDestinationDataFile(String destinationName, Properties connectProperties) 
     { 
      File destCfg = new File(destinationName+".jcoDestination"); 
      try 
      { 
       FileOutputStream fos = new FileOutputStream(destCfg, false); 
       connectProperties.store(fos, "for tests only !"); 
       fos.close(); 
      } 
      catch (Exception e) 
      { 
       throw new RuntimeException("Unable to create the destination files", e); 
      } 
     } 

私はEQ演算子を使用する場合、前のコードがうまく働きました。 しかし、私はIN演算子を使用する場合:

BNAME IN ('USER1','USER','USER3') 

または

BNAME EQ 'USER1' OR BNAME EQ 'USER' OR BNAME EQ 'USER3' 

それは例外スロー:

Unexpected dynamic conditionが条件サイズに制限事項はありますか? IN条件に22フィールドあり、各値のサイズは10ですか?

答えて

0

valid OpenSQL conditionを指定する必要がある場合は、rules for dynamic conditionsを観察し、条件が72文字の行に正しく分割されていることを確認する必要があります。私の推測では、22の条件を指定している場合、最後のビットが問題になっている可能性があります。

関連する問題