John Sutor wrote:

I am trying to get a return Parameter from a variable that is changed in
a CL program. My code looks as following

AS400Text text3 = new AS400Text(5); byte[] parm3 = text3.toBytes(milesParm); parameterList[3] = new ProgramParameter(parm3);

THEN I call the program

byte[] getMiles = parameterList[3].getOutputData();
milesParm = getMiles.toString();

Fairly new to this so not sure that I am even trying to do this the
correct way can someone point me in the right direction??
You should use the same type to get data out, as you used to put data in. I wrote a small class to help getting it right which might be useful to you. First you create an AS400FunctionCall instance which may then be called several times. I use Jakarta Commons Lang and Log4j here but that can easily be removed. Note: I have only actually tried with AS400Text as datatypes.

--- usage

AS400DataType[] dataTypes = new AS400DataType[] { new AS400Text(1024), new AS400Text(1024) }; AS400FunctionCall call = new AS400FunctionCall(as400, "BASSCHTD.PGM", dataTypes);
       List l = String[] {setup, "2X" + jobNumber});
       String fixparm = (String) l.get(1);

----- class

package foobar.utils;

import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.log4j.Logger;


public class AS400FunctionCall {

   private static Logger log = Logger.getLogger(AS400FunctionCall.class);
   private AS400DataType[] dataType;
   private String programName;
   private ProgramCall programCall;

public AS400FunctionCall(AS400 as400, String programName, AS400DataType[] dataType) { if (programName.indexOf("/") == -1) {
           programName = "/QSYS.LIB/%LIBL%.LIB/" + programName;
this.programName = programName;
       this.dataType = dataType;
ProgramParameter[] parameter = new ProgramParameter[dataType.length];
       for(int i = 0; i < dataType.length; i++) {
parameter[i] = new ProgramParameter(dataType[i].getByteLength());
Log4JUtils.debug(log, "Creating ProgramCall to " + programName + " on AS400: " + as400);
       programCall = new ProgramCall(as400, programName, parameter);
public List run() {
       return run(new String[0]);
public List run(String[] values) {
       if (values == null)   {
           throw new IllegalArgumentException("values is null");
       try {
           long start = System.currentTimeMillis();
           List result = run_(values);
           long end = System.currentTimeMillis();
           log.debug("Execution took " + (end - start) + " ms");
           return result;
       } catch (Exception e) {
           throw new RuntimeException("Error calling AS/400 function", e);

public List run_(String[] values) throws PropertyVetoException, AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException {

Log4JUtils.debug(log, "Calling " + programName + " with " + Arrays.asList(values)); ProgramParameter[] parameter = programCall.getParameterList(); if (values != null) {
           for(int i = 0; i < values.length; i++) {
               try {
               } catch (ExtendedIllegalArgumentException e) {
throw new IllegalArgumentException("argument " + i + " does not work with data type " + ToStringBuilder.reflectionToString(dataType[i]) + " ("+ e + ")");
log.debug("User library list before run() : " + Arrays.asList(programCall.getServerJob().getUserLibraryList()));

       boolean run =;
if (run) {
           List l = new ArrayList();
           for(int i = 0; i < dataType.length; i++) {
Object o = dataType[i].toObject(parameter[i].getOutputData());
log.debug("User library list after run(): " + Arrays.asList(programCall.getServerJob().getUserLibraryList()));
           Log4JUtils.debug(log, "Returning " + l);
           return l;
       } else {
           // Figure out what to tell caller
           AS400Message[] messageList = programCall.getMessageList();
           AS400Message message = messageList[0];
           String id = message.getID();
if ("MCH0802".equals(id)) { // ID: MCH0802 text: Total parameters passed does not match number required. throw new IllegalArgumentException(programName+ ": " + ToStringBuilder.reflectionToString(message));
// Unknown reason, give details
           Job serverJob = programCall.getServerJob();
           JobLog jobLog = serverJob.getJobLog();
throw new RuntimeException(ToStringBuilder.reflectionToString(jobLog) + ToStringBuilder.reflectionToString(messageList));


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.