2016-08-24 83 views
1

我創建使用JCO,SAP UTIL用於例如下面的代碼查詢:或多個運營商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?

回答