コード例 #1
0
ファイル: JCoRdTB.java プロジェクト: shangyantao/dmapp
 protected List<Object> getTableParameter(String tableName) throws NotFoundException {
   List<Object> tableData = new ArrayList<Object>();
   JCoTable jt = this.jCoFunction.getTableParameterList().getTable(this.queryData);
   Class<?> cls = new ClassUtil(tableName).load();
   if (cls != null) {
     for (int i = 0; i < jt.getNumRows(); i++) {
       jt.setRow(i);
       Object obj = this.initialClass(cls, jt.getString(this.queryField));
       if (obj != null) {
         tableData.add(obj);
       }
     }
   }
   return tableData;
 }
コード例 #2
0
  /**
   * A slightly more complex example than before. Query the companies list returned in a table and
   * then obtain more details for each company.
   *
   * @throws com.sap.conn.jco.JCoException
   */
  public static void step4WorkWithTable() throws JCoException {
    JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
    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");
    for (int i = 0; i < codes.getNumRows(); i++) {
      codes.setRow(i);
      System.out.println(codes.getString("COMP_CODE") + '\t' + codes.getString("COMP_NAME"));
    }

    // move the table cursor to first row
    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"));

      // We do not need the addresses, so set the corresponding parameter to inactive.
      // Inactive parameters will be  either not generated or at least converted.
      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");

      System.out.println(
          detail.getString("COMP_CODE")
              + '\t'
              + detail.getString("COUNTRY")
              + '\t'
              + detail.getString("CITY"));
    } // for
  }