/** * 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); } }
/** * 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$ }