× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: AS/400 Tookit - ProgramCall & passing numerics
  • From: "Lee, John" <JLee@xxxxxxxx>
  • Date: Fri, 3 Aug 2001 14:27:22 -0400

Has anyone tried & been successful using ProgramCall to call an RPG ILE
program which expects a mixture of text and numeric input/output parameters?

I've had no problem using ProgramCall and ServiceProgramCall when all
input/output parameters are text. However, if any parms are zoned-decimal
(using AS400ZonedDecimal) or packed-decimal (using AS400PackedDecimal), my
java programs blow-up when trying to retrieve ANY (numeric or text) output
data from the call. This happens when using the IBM Enterprise Toolkit for
AS/400 (in VAJ) or the JAVA Toolkit located on the AS/400 (V5R1). 

I believe I'm passing the parameters correctly since the RPG programs run
fine. I've also used the debugger while they were running (using STRSRVJOB)
and verified that the parms looked good.

The problem occurs when I attempt to retrieve a text parameter's output data
(String result = (String)
AS400Text.toObject(ProgramParameter.getOutPutData())).  It's dying inside
one of the Toolkit's classes. Using the Exception's printStackTrace() I get
the following errors:

========================================================================
java.lang.ArrayIndexOutOfBoundsException
        java.lang.Throwable()
        java.lang.Exception()
        java.lang.RuntimeException()
        java.lang.IndexOutOfBoundsException()
        java.lang.ArrayIndexOutOfBoundsException()
        int com.ibm.as400.access.ConvTableInputStream.read(byte [], int,
int)
        int com.ibm.as400.access.ConvTableInputStream.read(byte [], int,
int)
        int java.io.InputStream.read(byte [])
        int java.io.InputStreamReader.fill(char [], int, int)
        int java.io.InputStreamReader.read(char [], int, int)
        java.lang.String
com.ibm.as400.access.ConvTable.byteArrayToString(byte [], int, int)
        java.lang.String
com.ibm.as400.access.ConverterImplRemote.byteArrayToString(byte [], int,
int)
        java.lang.Object com.ibm.as400.access.AS400Text.toObject(byte [])
        boolean ers.expensereport.ExpenseItem.validateData(java.lang.String,
java.util.Date, int, com.ibm.as400.access.AS400, ers.ERSMessages)
        boolean ers.expensereport.ExpenseItem.validate(java.lang.String,
java.util.Date, int, com.ibm.as400.access.AS400, ers.ERSMessages)
        boolean ers.expensereport.ExpenseReport.validateExpenseItems()
        boolean ers.expensereport.ExpenseReport.validate()
        void
ers.expensereport.ChangeExpenseReport.performTask(javax.servlet.http.HttpSer
vletRequest, javax.servlet.http.HttpServletResponse)
        void
ers.expensereport.ChangeExpenseReport.doPost(javax.servlet.http.HttpServletR
equest, javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest
, javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
        void
com.ibm.servlet.engine.webapp.StrictServletInstance.doService(javax.servlet.
ServletRequest, javax.servlet.ServletResponse)
        void
com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(javax.servlet.
ServletRequest, javax.servlet.ServletResponse)
        void
com.ibm.servlet.engine.webapp.IdleServletState.service(com.ibm.servlet.engin
e.webapp.StrictLifecycleServlet, javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
        void
com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(javax.servlet.S
ervletRequest, javax.servlet.ServletResponse)
        void
com.ibm.servlet.engine.webapp.ServletInstance.service(javax.servlet.ServletR
equest, javax.servlet.ServletResponse,
com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
        void
com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(com.ibm.se
rvlet.engine.webapp.ServletInstanceReference, javax.servlet.ServletRequest,
javax.servlet.ServletResponse,
com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
        void
com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(javax.servle
t.ServletRequest, javax.servlet.ServletResponse,
com.ibm.servlet.engine.webapp.WebAppServletInvocationEvent)
        void
com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(c
om.ibm.servlet.engine.webapp.WebAppRequest,
com.ibm.servlet.engine.webapp.WebAppResponse, boolean)
        void
com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(javax.servlet
.ServletRequest, javax.servlet.ServletResponse, boolean)
        void
com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(javax.servlet.
ServletRequest, javax.servlet.ServletResponse)
        void
com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(java.lang.Obje
ct)
        void
com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(java.lan
g.Object)
        void
com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(java.lang.S
tring, com.ibm.servlet.engine.srp.ISRPConnection)
        void
com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(com.ibm.ser
vlet.engine.oselistener.api.IOSEConnection)
        void
com.ibm.servlet.engine.http_transport.HttpTransportHandler.handleConnection(
java.net.Socket)
        void
com.ibm.servlet.engine.http_transport.HttpTransportHandler.run()
        void java.lang.Thread.run()
========================================================================


I'd be grateful for any suggestions.  I include below the java code for the
method that calls the RPG program. 
Thank you.



private boolean validateData(
        String employeeNumber,
        Date weekEndingDate,
        int sequenceNumber,
        AS400 system,
        ERSMessages ersMessages) {

        boolean validatedOk = true;

        try {

                // converter classes
                AS400Text textConverter;
                SimpleDateFormat dateFormatter = new
SimpleDateFormat("yyyy-MM-dd");
                AS400Bin4 bin4Converter;
                AS400PackedDecimal packedDecimalConverter;
                AS400ZonedDecimal zonedDecimalConverter;
                String dateString;

                // start service
                if (!system.isConnected(AS400.COMMAND)) {
                        system.connectService(AS400.COMMAND);
                }

                // program call has 10 parameters, all input/output     
                ProgramParameter[] parmList = new ProgramParameter[10];

                // parameter 1 - employee number
                textConverter = new AS400Text(10, system.getCcsid(),
system);   // text converter
                parmList[0] =
                        new ProgramParameter(
                                textConverter.toBytes(employeeNumber),
                                textConverter.getByteLength());

                // parameter 2 - expense report week ending date.
                textConverter = new AS400Text(10, system.getCcsid(),
system);  // text converter         
                // format date
                dateString = dateFormatter.format(weekEndingDate);
                parmList[1] =
                        new ProgramParameter(
                                textConverter.toBytes(dateString),
                                textConverter.getByteLength());

                // parameter 3 - sequence number                
                zonedDecimalConverter = new AS400ZonedDecimal(2, 0);
                parmList[2] =
                        new ProgramParameter(
                                zonedDecimalConverter.toBytes(new
BigDecimal(sequenceNumber)),
                                zonedDecimalConverter.getByteLength());

                // parameter 4 - item number number
                zonedDecimalConverter = new AS400ZonedDecimal(2, 0);
                parmList[3] =
                        new ProgramParameter(
                                zonedDecimalConverter.toBytes(new
BigDecimal(itemNumber)),
                                zonedDecimalConverter.getByteLength());

                // parameter 5 - expense date
                textConverter = new AS400Text(10, system.getCcsid(),
system);   // text converter         
                // format date
                dateString = dateFormatter.format(expenseDate);
                parmList[4] =
                        new ProgramParameter(
                                textConverter.toBytes(dateString),
                                textConverter.getByteLength());

                // parameter 6 - expense amount
                packedDecimalConverter = new AS400PackedDecimal(9, 2);
                parmList[5] =
                        new ProgramParameter(
        
packedDecimalConverter.toBytes(expenseAmount),
                                packedDecimalConverter.getByteLength());

                // parameter 7 - explanation mandatory?
                textConverter = new AS400Text(1, system.getCcsid(), system);
// text converter
                parmList[6] =
                        new ProgramParameter(textConverter.toBytes(" "),
textConverter.getByteLength());

                // parameter 8 - explanation exist?
                textConverter = new AS400Text(1, system.getCcsid(), system);
// text converter
                parmList[7] =
                        new ProgramParameter(textConverter.toBytes(" "),
textConverter.getByteLength());

                // parameter 9 - error code
                textConverter = new AS400Text(7, system.getCcsid(), system);
// text converter
                parmList[8] =
                        new ProgramParameter(
                                textConverter.toBytes("      "),
                                textConverter.getByteLength());

                // parameter 10 - error description
                textConverter = new AS400Text(40, system.getCcsid(),
system);  // text converter
                parmList[9] =
                        new ProgramParameter(
                                textConverter.toBytes("
"),
                                textConverter.getByteLength());

                // set up program call
                ProgramCall pgm = new ProgramCall(system);
                QSYSObjectPathName fullPgmName =
                        new QSYSObjectPathName("*LIBL", "ERS9040SPI",
"PGM");
                try {
                        pgm.setProgram(fullPgmName.getPath(), parmList);
                } catch (Exception e) {
                        // if error, print error messages to stdout
                        AS400Message[] messageList = pgm.getMessageList();
                        for (int msg = 0; msg < messageList.length; msg++) {
                                System.out.println(messageList[msg]);
                                throw (e);
                        }
                }

                // run the program
                if (pgm.run() != true) {
                        // if error, print error messages to stdout
                        AS400Message[] messageList = pgm.getMessageList();
                        for (int msg = 0; msg < messageList.length; msg++) {
                                System.out.println(messageList[msg]);
                        }
                } else {
                        // retrieve if explanation is mandatory, and if
explanation exists                      
                        String explanationMandatory =
                                (String)
textConverter.toObject(parmList[6].getOutputData());   **** BOMBS HERE ***
                        String explanationExists =
                                (String)
textConverter.toObject(parmList[7].getOutputData());   **** BOMBS HERE ***
                        if (explanationMandatory.equals("Y") &&
!explanationExists.equals("Y")) {
                                validatedOk = false;
                                if (ersMessages != null) {
                                        ersMessages.setMessageId("ERR0095");
                                        ersMessages.setSubstitutionText("");
                                        errorMessages.add(
                                                "'Expense Item "
                                                        + itemNumber
                                                        + " for"
                                                        +
dateFormatter.format(expenseDate)
                                                        + ": "
                                                        +
ersMessages.getMessage());

                                }
                        }
                }

        } catch (Exception e) {
                e.printStackTrace();
        }

        return validatedOk;
}






John Lee     jlee@lear.com <mailto:jlee@lear.com> 
Information Technology
Lear Corporation
24467 Ten Mile Road 
Southfield, Michigan 48034 
(248) 368 8741 (direct)
(248) 372 7350 (fax)

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

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-2024 by midrange.com 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.