Example: Using CommandCall

This example uses the IBM® Toolbox for Java™ access class CommandCall.

Use the following as an example for your program.

Note: Read the Code example disclaimer for important legal information.
////////////////////////////////////////////////////
//
// This source is an example of "Job List".
//
/////////////////////////////////////////////////////
//
// The access classes are in the com.ibm.as400.access.package. 
// Import this package to use the IBM Toolbox for Java classes.
//
/////////////////////////////////////////////////////

import com.ibm.as400.access.*;                       

public class CmdCall
{
   public static void main(String[] args)
   {
      // Like other Java classes, IBM Toolbox for Java classes
      // throw exceptions when something goes wrong.  These must 
      // be caught by programs that use IBM Toolbox for Java.
      try Note 1 
      {
         AS400 system  = new AS400();                

         CommandCall cc = new CommandCall(system); Note 2 
           
         cc.run("CRTLIB MYLIB"); Note 3 

         AS400Message[] ml = cc.getMessageList(); Note 4 
 
         for (int i=0; i<ml.length; i++)
         {                                               
            System.out.println(ml[i].getText()); Note 5     
         }
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      
      System.exit(0);
   }
}
  1. IBM Toolbox for Java uses the "AS400" object to identify the target server. If you construct the AS400 object with no parameters, IBM Toolbox for Java prompts for the system name, userid and password. The AS400 class also includes a constructor that takes the system name, userid and password.
  2. Use the IBM Toolbox for Java CommandCall object to send commands to the server. When you create the CommandCall object, you pass it an AS400 object so that it knows which server is the target of the command.
  3. Use the run() method on the command call object to run a command.
  4. The result of running a command is a list of IBM i messages. IBM Toolbox for Java represents these messages as AS400Message objects. When the command is complete, you get the resulting messages from the CommandCall object.
  5. Print the message text. Also available are the message ID, message severity, and other information. This program prints only the message text.