示例#1
0
 /**
  * Executes RFC_READ_TABLE with the current set of selected fields but without selection criteria.
  *
  * @return the contents read
  * @throws JCoException
  */
 public ITableContents read() throws JCoException {
   JCoFunction readFunction = template.getFunction();
   readFunction.getImportParameterList().setValue("QUERY_TABLE", tableName); // $NON-NLS-1$
   readFunction.getTableParameterList().getTable("OPTIONS").clear(); // $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$
 }
示例#2
0
 /**
  * Retrieves the table structure from the SAP R/3 system.
  *
  * @throws JCoException
  */
 private void loadStructure() throws JCoException {
   // call RFC_READ_TABLE without requesting any data
   JCoFunction readFieldListFunction = template.getFunction();
   readFieldListFunction
       .getImportParameterList()
       .setValue("QUERY_TABLE", tableName); // $NON-NLS-1$
   readFieldListFunction.getImportParameterList().setValue("NO_DATA", tableName); // $NON-NLS-1$
   readFieldListFunction.execute(destination);
   structure =
       new TableStructure(
           tableName,
           readFieldListFunction.getTableParameterList().getTable("FIELDS")); // $NON-NLS-1$
 }
示例#3
0
  /**
   * 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$
  }
示例#4
0
  public void run(ProcedureRunner runner) throws Exception {
    CompositeMap context = runner.getContext();
    logger = LoggingContext.getLogger(context, LOGGING_TOPIC);
    logger.config("jco-invoke");
    logger.config("===================================");
    logger.log(Level.CONFIG, "config:{0}", new Object[] {this});

    ServiceInstance service = (ServiceInstance) ServiceInstance.getInstance(context.getRoot());

    //		HttpServiceInstance service = (HttpServiceInstance) HttpServiceInstance
    //				.getInstance(context.getRoot());
    CompositeMap target = null;
    CompositeMap model = null;
    if (service != null) model = service.getServiceContext().getModel();
    else model = context.getRoot().getChild("model");
    if (model == null) model = context.getRoot().createChild("model");
    if (return_target != null) {
      String t = TextParser.parse(return_target, context);
      target = (CompositeMap) model.getObject(t);
      if (target == null) target = model.createChildByTag(t);
    }
    JCoDestination destination = sapConfig.getJCoDestination(sid);
    String functionName = function;

    JCoFunctionTemplate ftemplate = destination.getRepository().getFunctionTemplate(functionName);
    logger.info("function template:" + functionName);
    if (ftemplate == null) {
      logger.log(Level.SEVERE, "Function '" + function + "' not found in SAP system.");
      throw new IllegalArgumentException("Function '" + function + "' not found in SAP system.");
    }
    // Create a function from the template
    JCoFunction function = ftemplate.getFunction();
    JCoParameterList input = function.getImportParameterList();
    JCoParameterList output = function.getExportParameterList();
    if (parameters != null)
      for (int i = 0; i < parameters.length; i++) {
        Parameter param = parameters[i];
        if (param.Return_field == null) {
          Object o =
              param.Source_field == null ? param.Value : context.getObject(param.Source_field);
          String value = o == null ? "" : o.toString();
          input.setValue(param.Name, value);
          logger.log(Level.CONFIG, "parameter {0} -> {1}", new Object[] {param.Name, value});
        }
      }
    if (structures != null) {
      for (int i = 0; i < structures.length; i++) {
        Structure structure = structures[i];
        structure.setLogger(logger);
        if (structure.isImport()) {
          JCoStructure stc = structure.getJCOStructure(input);
          structure.fillJCOStructure(stc, context);
          input.setValue(structure.Name, stc);
        }
      }
    }
    // Set import table
    if (tables != null) {
      JCoParameterList list = function.getTableParameterList();
      for (int i = 0; i < tables.length; i++) {
        Table table = tables[i];
        table.setLogger(logger);
        if (table.isImport()) {
          JCoTable tbl = table.getJCOTable(list);
          Object o = context.getObject(table.Source_field);
          logger.config(
              "transfer import table " + table.Name + " from '" + table.Source_field + "':" + o);
          if (o instanceof CompositeMap) table.fillJCOTable(tbl, (CompositeMap) context);
        }
      }
    }

    // Call the remote system and retrieve return value
    logger.config("call function " + function);
    function.execute(destination);
    if (parameters != null) {
      for (int i = 0; i < parameters.length; i++) {
        Parameter param = parameters[i];
        if (param.Return_field != null) {
          if (target == null)
            throw new ConfigurationError(
                "<jco-invoke>:must set 'return_target' attribute if there is return field");
          String vl = output.getString(param.Name);
          if (vl == null && !param.Nullable)
            throw new IllegalArgumentException(
                "jco-invoke: return field " + param.Name + " is null");
          String f = TextParser.parse(param.Return_field, context);
          target.putObject(f, vl);
          logger.config("return: " + param.Name + "=" + vl + " -> " + f);
        }
      }
    }
    if (structures != null) {
      for (int i = 0; i < structures.length; i++) {
        Structure structure = structures[i];
        structure.setLogger(logger);
        if (structure.isImport()) continue;
        if (structure.Target == null)
          throw new ConfigurationError(
              "Must set 'target' attribute for Structures " + structure.Name);
        JCoStructure stc = structure.getJCOStructure(output);
        CompositeMap result = (CompositeMap) context.getObject(structure.Target);
        if (result == null) result = context.createChildByTag(structure.Target);
        structure.fillCompositeMap(stc, result);
      }
    }
    // Get export tables
    if (tables != null) {
      JCoParameterList list = function.getTableParameterList();
      if (list == null)
        throw new IllegalArgumentException("Function '" + function + "' doesn't return tables");
      for (int i = 0; i < tables.length; i++) {
        Table table = tables[i];
        if (table.isImport()) continue;
        if (table.Target == null)
          throw new ConfigurationError("Must set 'target' attribute for table " + table.Name);
        table.setLogger(logger);
        JCoTable records = table.getJCOTable(list);
        // Fetch as CompositeMap

        CompositeMap result = (CompositeMap) context.getObject(table.Target);
        if (result == null) result = context.createChildByTag(table.Target);
        table.fillCompositeMap(records, result);
        int rc = 0;
        if (result.getChilds() != null) rc = result.getChilds().size();
        logger.config(
            "loading export table "
                + table.Name
                + " into path '"
                + table.Target
                + "', total "
                + rc
                + " record(s)");
      }
    }
  }