ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/vpgm.htm

157 lines
8.9 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="Vaccess ProgramCall classes" />
<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="vpgm" />
<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>Vaccess ProgramCall classes</title>
</head>
<body id="vpgm"><a name="vpgm"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Vaccess ProgramCall classes</h1>
<div><p></p>
<div class="section"><p>The program call components in the vaccess package allow a Java™ program
to present a button or menu item that calls a server program. Input, output,
and input/output parameters can be specified using <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#NAVBAR_TOP"> ProgramParameter</a> objects. When the program runs, the
output and input/output parameters contain data returned by the server program.</p>
</div>
<div class="section"><p>A <a href="javadoc/com/ibm/as400/vaccess/ProgramCallButton.html#NAVBAR_TOP"> ProgramCallButton</a> object represents a button that calls
an server program when pressed. The ProgramCallButton class extends the Java Foundation
Classes (JFC) JButton class so that all buttons have a consistent appearance
and behavior.</p>
</div>
<div class="section"><p>Similarly, a <a href="javadoc/com/ibm/as400/vaccess/ProgramCallMenuItem.html#NAVBAR_TOP"> ProgramCallMenuItem</a> object represents a menu item that
calls an server program when selected. The ProgramCallMenuItem class extends
the JFC JMenuItem class so that all menu items also have a consistent appearance
and behavior.</p>
</div>
<div class="section"><p>To use a vaccess program call component, set both the system and
program properties. Set these properties by using a constructor or through
the setSystem() and setProgram() methods.</p>
</div>
<div class="section"><p><span class="synph" id="vpgm__vpgmex1"><a name="vpgm__vpgmex1"><!-- --></a><span class="kwd"></span></span>The following example creates
a ProgramCallMenuItem. At run time, when the menu item is selected, it calls
a program:</p>
</div>
<div class="section"><div class="p"><pre> // Create the ProgramCallMenuItem
// object. Assume that "system" is
// an AS400 object created and
// initialized elsewhere. The menu
// item text says "Select Me", and
// there is no icon.
ProgramCallMenuItem menuItem = new ProgramCallMenuItem ("Select Me", null, system);
// Create a path name object that
// represents program MYPROG in
// library MYLIB
QSYSObjectPathName programName = new QSYSObjectPathName("MYLIB", "MYPROG", "PGM");
// Set the name of the program.
menuItem.setProgram (programName.getPath());
// Add the menu item to a menu.
// Assume that the menu was created
// elsewhere.
menu.add (menuItem);</pre>
</div>
</div>
<div class="section"><p>When a server program runs, it may return zero or more server
messages. To detect when the server program runs, add an <a href="javadoc/com/ibm/as400/access/ActionCompletedListener.html#NAVBAR_TOP"> ActionCompletedListener</a> to the button or menu item using
the addActionCompletedListener() method. When the program runs, it fires an <a href="javadoc/com/ibm/as400/access/ActionCompletedEvent.html#NAVBAR_TOP"> ActionCompletedEvent</a> to all such listeners. A listener
can use the getMessageList() method to retrieve any server messages that the
program generated.</p>
</div>
<div class="section"><p><span class="synph" id="vpgm__vpgmex2"><a name="vpgm__vpgmex2"><!-- --></a><span class="kwd"></span></span>This example adds an ActionCompletedListener
that processes all server messages that the program generated:</p>
</div>
<div class="section"><div class="p"><pre> // Add an ActionCompletedListener
// that is implemented by using an
// anonymous inner class. This is a
// convenient way to specify simple
// event listeners.
menuItem.addActionCompletedListener (new ActionCompletedListener ()
{
public void actionCompleted (ActionCompletedEvent event)
{
// Cast the source of the event to a
// ProgramCallMenuItem.
ProgramCallMenuItem sourceMenuItem = (ProgramCallMenuItem) event.getSource ();
// Get the list of server messages
// that the program generated.
AS400Message[] messageList = sourceMenuItem.getMessageList ();
// ... Process the message list.
}
});</pre>
<strong>Parameters</strong></div>
</div>
<div class="section"><p><a href="javadoc/com/ibm/as400/access/ProgramParameter.html#NAVBAR_TOP"> ProgramParameter</a> objects are used to pass parameter
data between the Java program and the server program. Input data is set
with the <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#SETINPUTDATA(BYTE[])"> setInputData()</a> method. After the program is run, output
data is retrieved with the <a href="javadoc/com/ibm/as400/access/ProgramParameter.html#GETOUTPUTDATA()"> getOutputData()</a> method.</p>
</div>
<div class="section"><p>Each parameter is a byte array. It is up to the Java program
to convert the byte array between Java and server formats. The <a href="dtad.htm#dtad">data
conversion</a> classes provide methods for converting data.</p>
</div>
<div class="section"><p>You can add parameters to a program call graphical user interface
component one at a time using the addParameter() method or all at once using
the setParameterList() method.</p>
</div>
<div class="section"><p>For more information about using ProgramParameter objects, see
the <a href="pgmc.htm#pgmc">ProgramCall access class</a>.</p>
</div>
<div class="section"><p><span class="synph" id="vpgm__vpgmex3"><a name="vpgm__vpgmex3"><!-- --></a><span class="kwd"></span></span>The following example adds
two parameters:</p>
</div>
<div class="section"><div class="p"><pre> // The first parameter is a String
// name of up to 100 characters.
// This is an input parameter.
// Assume that "name" is a String
// created and initialized elsewhere.
AS400Text parm1Converter = new AS400Text (100, system.getCcsid (), system);
ProgramParameter parm1 = new ProgramParameter (parm1Converter.toBytes (name));
menuItem.addParameter (parm1);
// The second parameter is an Integer
// output parameter.
AS400Bin4 parm2Converter = new AS400Bin4 ();
ProgramParameter parm2 = new ProgramParameter (parm2Converter.getByteLength ());
menuItem.addParameter (parm2);
// ... after the program is called,
// get the value returned as the
// second parameter.
int result = parm2Converter.toInt (parm2.getOutputData ());</pre>
<strong><span class="synph" id="vpgm__vpgmexamples"><a name="vpgm__vpgmexamples"><!-- --></a><span class="kwd"></span></span>Examples</strong></div>
</div>
<div class="section"><p>Example of using a <a href="programcallbuttonexample.htm#programcallbuttonexample">ProgramCallButton</a>
in an application. Figure 1 shows how the ProgramCallButton looks:</p>
</div>
<div class="section"><p><strong>Figure 1: Using ProgramCallButton in an application</strong></p>
</div>
<div class="section"><p><img src="rzahh084.gif" alt="Using ProgramCallButton in an application" /></p>
</div>
</div>
</body>
</html>