コード例 #1
0
 @Override
 public void run(
     VariantTableContent content,
     Resource resource,
     IProgressMonitor monitor,
     Map<String, VCObject> seenObjects,
     List<Option> options)
     throws Exception {
   VariantTable table = content.getTable();
   JCoFunction deletefunc = maintainEntries(content, monitor, options, true);
   executeTransaction(monitor, "DELETE " + table.getName(), deletefunc);
   JCoFunction createfunc = maintainEntries(content, monitor, options, false);
   JCoTable entries = createfunc.getTableParameterList().getTable("VAR_TAB_ENTRIES");
   EList<Row> rows = content.getRows();
   List<VariantTableArgument> arguments = table.getArguments();
   for (Row row : rows) {
     for (VariantTableArgument arg : arguments) {
       String cstic = arg.getCharacteristic().getName();
       int index = arguments.indexOf(arg);
       entries.appendRow();
       Literal literal = row.getValues().get(index);
       entries.setValue("VTCHARACT", cstic);
       entries.setValue("VTLINENO", "" + rows.indexOf(row));
       entries.setValue("VTVALUE", getValue(literal));
     }
   }
   executeTransaction(monitor, "CREATE/CHANGE " + table.getName(), createfunc);
 }
コード例 #2
0
 /**
  * Transfers the contents of a typed list to a {@link JCoTable}.
  *
  * @param source
  * @param destination
  */
 public static void toTable(List<TransportShortText> source, JCoTable destination) {
   destination.deleteAllRows();
   for (TransportShortText entry : source) {
     destination.appendRow();
     entry.toStructure(destination);
   }
 }
コード例 #3
0
 /**
  * Transfers the contents of a {@link JCoTable} into a typed list.
  *
  * @param source the {@link JCoTable} to read the data from
  * @return a new {@link List} instance containing the data from the table
  */
 public static List<TransportShortText> fromTable(JCoTable source) {
   List<TransportShortText> list = new ArrayList<TransportShortText>();
   if (!source.isEmpty()) {
     source.firstRow();
     do {
       list.add(new TransportShortText(source));
     } while (source.nextRow());
   }
   return list;
 }
コード例 #4
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;
 }
コード例 #5
0
  public void run(
      Class object,
      Resource resource,
      IProgressMonitor monitor,
      Map<String, VCObject> seenObjects,
      List<Option> options)
      throws JCoException {
    beginTransaction();
    JCoFunction function = getJCoFunction(getBAPI(), monitor);
    JCoParameterList ipl = function.getImportParameterList();
    String classSpec = object.getName();
    String className = VcmlUtils.getClassName(classSpec);
    int classType = VcmlUtils.getClassType(classSpec);

    // handleOptions(options, ipl, "???", "???");

    ipl.setValue(getCLASSNUM(), className);
    ipl.setValue(getCLASSTYPE(), classType);
    JCoStructure classBasicDataNew = ipl.getStructure(getCLASSBASICDATA());
    classBasicDataNew.setValue("STATUS", VcmlUtils.createIntFromStatus(object.getStatus()));
    classBasicDataNew.setValue("CLASSGROUP", nullIfEmpty(object.getGroup()));
    classBasicDataNew.setValue("VALID_FROM", getToday()); // TODO set VALID_FROM for classes?
    classBasicDataNew.setValue("VALID_TO", "9999-12-31"); // TODO set VALID_TO for classes?
    JCoParameterList tpl = function.getTableParameterList();
    final JCoTable classDescriptionsNew = tpl.getTable(getCLASSDESCRIPTIONS());
    new DescriptionHandler() {
      @Override
      public void handleSingleDescription(Language language, String value) {
        classDescriptionsNew.appendRow();
        classDescriptionsNew.setValue("CATCHWORD", value);
        classDescriptionsNew.setValue("LANGU", VcmlUtils.getLanguageCharacter(language));
        classDescriptionsNew.setValue("LANGU_ISO", language.toString());
      }
    }.handleDescription(object.getDescription());
    JCoTable classCharacteristicsNew = tpl.getTable(getCLASSCHARACTERISTICS());
    List<Characteristic> cstics = object.getCharacteristics();
    classCharacteristicsNew.appendRows(cstics.size());
    for (Characteristic cstic : cstics) {
      classCharacteristicsNew.setValue("NAME_CHAR", cstic.getName());
      classCharacteristicsNew.nextRow();
    }
    execute(function, monitor, object.getName());
    if (processReturnTable(function)) {
      commit(monitor);
    }
    endTransaction();
  }
コード例 #6
0
ファイル: TableReader.java プロジェクト: freiric/fre-rcer
 /**
  * Adjusts the field list so that only the selected fields are read.
  *
  * @param readFunction
  */
 private void setFieldList(JCoFunction readFunction) {
   int length = 0;
   JCoTable fields = readFunction.getTableParameterList().getTable("FIELDS"); // $NON-NLS-1$
   fields.clear();
   if (selectedFields.isEmpty()) {
     for (final ITableField field : structure.getFieldList()) {
       length += field.getLength();
       fields.appendRow();
       fields.setValue("FIELDNAME", field.getFieldName()); // $NON-NLS-1$
     }
   } else {
     for (final String field : selectedFields) {
       try {
         length += structure.getField(field).getLength();
         fields.appendRow();
         fields.setValue("FIELDNAME", field); // $NON-NLS-1$
       } catch (FieldNotFoundException e) {
         throw new IllegalArgumentException(
             MessageFormat.format(Messages.TableReader_UnknownField, field), e);
       }
     }
   }
   if (length > 512) {
     throw new IllegalArgumentException(Messages.TableReader_ResultTooLong);
   }
 }
コード例 #7
0
ファイル: TableReader.java プロジェクト: freiric/fre-rcer
  /**
   * Executes RFC_READ_TABLE with a set of selection criteria specified as strings.
   *
   * @param selectionCriteria
   * @return the contents read
   * @throws JCoException
   */
  public ITableContents read(String... selectionCriteria) throws JCoException {
    JCoFunction readFunction = template.getFunction();
    readFunction.getImportParameterList().setValue("QUERY_TABLE", tableName); // $NON-NLS-1$

    JCoTable options = readFunction.getTableParameterList().getTable("OPTIONS"); // $NON-NLS-1$
    options.clear();
    if (selectionCriteria != null) {
      for (final String criterion : selectionCriteria) {
        if (criterion.length() > 72) {
          throw new IllegalArgumentException(Messages.TableReader_SelectionCriteriaTooLong);
        }
        options.appendRow();
        options.setValue("TEXT", criterion); // $NON-NLS-1$
      }
    }

    setFieldList(readFunction);
    readFunction.execute(destination);
    return new TableContents(
        tableName,
        readFunction.getTableParameterList().getTable("FIELDS"), // $NON-NLS-1$
        readFunction.getTableParameterList().getTable("DATA")); // $NON-NLS-1$
  }
コード例 #8
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
  }