169 lines
8.5 KiB
HTML
169 lines
8.5 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="ProgramCall class" />
|
||
|
<meta name="abstract" content="" />
|
||
|
<meta name="description" content="" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="pgmc" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>ProgramCall class</title>
|
||
|
</head>
|
||
|
<body id="pgmc"><a name="pgmc"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">ProgramCall class</h1>
|
||
|
<div><p></p>
|
||
|
<div class="section"><p>The <a href="javadoc/com/ibm/as400/access/ProgramCall.html#NAVBAR_TOP"> ProgramCall</a> class allows the Java™ program
|
||
|
to call an iSeries™ program.
|
||
|
You can use the <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#NAVBAR_TOP"> ProgramParameter</a> class to specify input, output, and
|
||
|
input/output parameters. If the program runs, the output and input/output
|
||
|
parameters contain the data that is returned by the iSeries program. If the iSeries program
|
||
|
fails to run successfully, the Java program can retrieve any resulting iSeries messages
|
||
|
as a list of <a href="javadoc/com/ibm/as400/access/AS400Message.html#NAVBAR_TOP"> AS400Message</a> objects.</p>
|
||
|
<p>Required parameters are
|
||
|
as follows:</p>
|
||
|
<ul><li>The program and parameters to run</li>
|
||
|
<li>The <a href="javadoc/com/ibm/as400/access/AS400.html#NAVBAR_TOP">AS400</a> object that represents the iSeries server that has the program.</li>
|
||
|
</ul>
|
||
|
<p>The program name and parameter list can be set on the constructor,
|
||
|
through the <a href="javadoc/com/ibm/as400/access/ProgramCall.html#SETPROGRAM(JAVA.LANG.STRING)"> setProgram()</a> method, or on the <a href="javadoc/com/ibm/as400/access/ProgramCall.html#RUN()">run()</a> method The run() method calls the program.</p>
|
||
|
<p>Using
|
||
|
the ProgramCall class causes the AS400 object to connect to the iSeries server.
|
||
|
See <a href="mngcon.htm#mngcon">managing connections</a> for information
|
||
|
about managing connections.</p>
|
||
|
</div>
|
||
|
<div class="section" id="pgmc__pgmcex1"><a name="pgmc__pgmcex1"><!-- --></a><p><strong>Example: Using ProgramCall</strong></p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> Read
|
||
|
the <a href="codedisclaimer.htm#codedisclaimer">Code example disclaimer</a> for
|
||
|
important legal information.</div>
|
||
|
<p>The following example shows how to use
|
||
|
the ProgramCall class:</p>
|
||
|
<pre> // Create an AS400 object.
|
||
|
AS400 sys = new AS400("mySystem.myCompany.com");
|
||
|
|
||
|
// Create a program object. I choose
|
||
|
// to set the program to run later.
|
||
|
ProgramCall pgm = new ProgramCall(sys);
|
||
|
|
||
|
// Set the name of the program.
|
||
|
// Because the program does not take
|
||
|
// any parameters, pass null for the
|
||
|
// ProgramParameter[] argument.
|
||
|
pgm.setProgram(QSYSObjectPathName.toPath("MYLIB", "MYPROG", "PGM"));
|
||
|
|
||
|
// Run the program. My program has
|
||
|
// no parms. If it fails to run, the failure
|
||
|
// is returned as a set of messages
|
||
|
// in the message list.
|
||
|
if (pgm.run() != true)
|
||
|
{
|
||
|
// If you get here, the program
|
||
|
// failed to run. Get the list of
|
||
|
// messages to determine why the
|
||
|
// program didn't run.
|
||
|
AS400Message[] messageList = pgm.getMessageList();
|
||
|
|
||
|
// ... Process the message list.
|
||
|
}
|
||
|
|
||
|
// Disconnect since I am done
|
||
|
// running programs
|
||
|
sys.disconnectService(AS400.COMMAND);</pre>
|
||
|
<p>The ProgramCall object
|
||
|
requires the <a href="ifspath.htm#ifspath"> integrated file system path
|
||
|
name</a> of the program.</p>
|
||
|
<p>The default behavior is for iSeries programs
|
||
|
to run in a separate server job, even when the Java program and the iSeries program are on the same server.
|
||
|
You can override the default behavior and have the iSeries program run in the Java job
|
||
|
using the <a href="javadoc/com/ibm/as400/access/CommandCall.html#SETTHREADSAFE(BOOLEAN)"> setThreadSafe()</a> method.</p>
|
||
|
</div>
|
||
|
<div class="section" id="pgmc__usingprogparamobjects"><a name="pgmc__usingprogparamobjects"><!-- --></a><h4 class="sectiontitle">Using ProgramParameter objects</h4><p>You
|
||
|
can use the <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#NAVBAR_TOP"> ProgramParameter objects</a> to pass parameter data between
|
||
|
the Java program
|
||
|
and the iSeries program.
|
||
|
Set the input data with the <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#SETINPUTDATA(BYTE[])"> setInputData()</a> method. After the program is run, retrieve
|
||
|
the output data with the <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#GETOUTPUTDATA()"> getOutputData()</a> method. Each parameter is a byte array.
|
||
|
The Java program
|
||
|
must convert the byte array between Java and iSeries formats. The <a href="dtad.htm#dtad">data
|
||
|
conversion</a> classes provide methods for converting data. Parameters
|
||
|
are added to the ProgramCall object as a list.</p>
|
||
|
</div>
|
||
|
<div class="section" id="pgmc__pgmcex2"><a name="pgmc__pgmcex2"><!-- --></a><p><strong>Example: Using ProgramParameter</strong></p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> Read
|
||
|
the <a href="codedisclaimer.htm#codedisclaimer">Code example disclaimer</a> for
|
||
|
important legal information.</div>
|
||
|
<p>The following example shows how to use
|
||
|
the ProgramParameter object to pass parameter data.</p>
|
||
|
<pre> // Create an AS400 object
|
||
|
AS400 sys = new AS400("mySystem.myCompany.com");
|
||
|
|
||
|
// My program has two parameters.
|
||
|
// Create a list to hold these
|
||
|
// parameters.
|
||
|
ProgramParameter[] parmList = new ProgramParameter[2];
|
||
|
|
||
|
// First parameter is an input
|
||
|
// parameter
|
||
|
byte[] key = {1, 2, 3};
|
||
|
parmList[0] = new ProgramParameter(key);
|
||
|
|
||
|
// Second parameter is an output
|
||
|
// parameter. A four-byte number
|
||
|
// is returned.
|
||
|
parmList[1] = new ProgramParameter(4);
|
||
|
|
||
|
// Create a program object
|
||
|
// specifying the name of the
|
||
|
// program and the parameter list.
|
||
|
ProgramCall pgm = new ProgramCall(sys, "/QSYS.LIB/MYLIB.LIB/MYPROG.PGM", parmList);
|
||
|
|
||
|
// Run the program.
|
||
|
if (pgm.run() != true)
|
||
|
{
|
||
|
|
||
|
// If the iSeries cannot run the
|
||
|
// program, look at the message list
|
||
|
// to find out why it didn't run.
|
||
|
AS400Message[] messageList = pgm.getMessageList();
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Else the program ran. Process the
|
||
|
// second parameter, which contains
|
||
|
// the returned data.
|
||
|
|
||
|
// Create a converter for this
|
||
|
// iSeries data type
|
||
|
AS400Bin4 bin4Converter = new AS400Bin4();
|
||
|
|
||
|
// Convert from iSeries type to Java
|
||
|
// object. The number starts at the
|
||
|
// beginning of the buffer.
|
||
|
byte[] data = parmList[1].getOutputData();
|
||
|
int i = bin4Converter.toInt(data);
|
||
|
}
|
||
|
|
||
|
// Disconnect since I am done
|
||
|
// running programs
|
||
|
sys.disconnectService(AS400.COMMAND);</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|