Example: Using JobList to list job identification information
///////////////////////////////////////////////////////////////////////////
//
// This program is an example of the Job support in the IBM Toolbox
// for Java. It lists job identification information for a specific
// user on the system.
//
// Command syntax:
// listJobs2 system userID password
//
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of using the IBM Toolbox for Java classes.
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// IBM Toolbox for Java
// (C) Copyright IBM Corp. 1998
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.lang.*;
import java.util.*;
import com.ibm.as400.access.*;
public class listJobs2 extends Object
{
// Create an object in case we want to call
// any non-staic methods.
public static void main(String[] parameters)
{
listJobs2 me = new listJobs2();
me.Main(parameters);
System.exit(0);
}
void Main(String[] parameters)
{
// If a system was not specified, display help text and exit.
if (parameters.length == 0)
{
showHelp();
return;
}
// Assign the parameters to variables. The
// first parameter is assumed to be the system
// name the second is a userID and the third
// is a password.
String systemName = parameters[0];
String userID = null;
String password = null;
if (parameters.length > 1)
userID = parameters[1].toUpperCase();
if (parameters.length >= 2)
password = parameters[2].toUpperCase();
System.out.println(" ");
try
{
// Create an AS400 object using the system name
// specified by the user. Set the userid and
// password if specified by the user.
AS400 as400 = new AS400(parameters[0]);
if (userID != null)
as400.setUserId(userID);
if (password != null)
as400.setPassword(password);
System.out.println("retrieving list ... ");
// Create a jobList object. This object is used
// to retrieve the list of active jobs on the AS/400.
JobList jobList = new JobList(as400);
// Get the list of active jobs.
Enumeration list = jobList.getJobs();
// For each job in the list ...
while (list.hasMoreElements())
{
// Get a job off the list. If a userID was
// specified then print identification information
// only if the job's user matches the userID. If
// no userID was specified then print information
// for every job on the system.
Job j = (Job) list.nextElement();
if (userID != null)
{
if (j.getUser().trim().equalsIgnoreCase(userID))
{
System.out.println(j.getName().trim() + "." +
j.getUser().trim() + "." +
j.getNumber());
}
}
else
System.out.println(j.getName().trim() + "." +
j.getUser().trim() + "." +
j.getNumber());
}
}
catch (Exception e)
{
System.out.println("Unexpected error");
e.printStackTrace();
}
}
// Display help text when parameters are incorrect.
void showHelp()
{
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("Parameters are not correct. Command syntax is:");
System.out.println("");
System.out.println(" listJobs2 System UserID Password");
System.out.println("");
System.out.println("Where");
System.out.println("");
System.out.println(" System = AS/400 to connect to");
System.out.println(" UserID = valid userID on that system ");
System.out.println(" Password = password for the UserID (optional)");
System.out.println("");
System.out.println("For example:");
System.out.println("");
System.out.println(" listJobs2 MYAS400 JavaUser pwd1");
System.out.println("");
System.out.println("");
}
}