Messages

AS400Message

AS400 Message object allows the Java program to retrieve an AS/400 message that is generated from a previous operation (for example, from a command call). From a message object, the Java program can retrieve the following:

The following example shows how to use the AS/400 Message object:

                       // Create a command call object.
     CommandCall cmd = new CommandCall(sys, "myCommand");

                       // Run the command
     cmd.run();

                       // Get the list of messages that are
                       // the result of the command that I
                       // just ran
     AS400Message[] messageList = cmd.getMessageList();

                      // Iterate through the list
                      // displaying the messages
     for (int i = 0; i < messageList.length; i++)
     {
        System.out.println(messageList[i].getText());
     }

Examples

The CommandCall example shows how a message list is used with CommandCall.

The ProgramCall example shows how a message list is used with ProgramCall.

QueuedMessage

The QueuedMessage class extends the AS400Message class. The QueuedMessage class accesses information about a message on an AS/400 message queue. With this class, a Java program can retrieve:

The following example prints all messages in the message queue of the current (signed-on) user:

                      // The message queue is on this as400.
      AS400 sys = new AS400(mySystem.myCompany.com);

                      // Create the message queue object.
                      // This object will represent the
                      // queue for the current user.
      MessageQueue queue = new MessageQueue(sys, MessageQueue.CURRENT);

                      // Get the list of messages currently
                      // in this user's queue.
      Enumeration e = queue.getMessages();

                      // Print each message in the queue.
      while (e.hasMoreElements())
      {
         QueuedMessage msg = e.getNextElement();
         System.out.println(msg.getText());
      }

Start changeMessageFile

The MessageFile class allows you to receive a message from an AS/400 message file. The MessageFile class returns an AS400Message object that contains the message. Using the MessageFile class, you can do the following:

The following example shows how to retrieve and print a message:

	AS400 system = new AS400("mysystem.mycompany.com");
	MessageFile messageFile = new MessageFile(system);
	messageFile.setPath("/QSYS.LIB/QCPFMSG.MSGF");
	AS400Message message = messageFile.getMessage("CPD0170");
	System.out.println(message.getText());End change

MessageQueue

The MessageQueue class allows a Java program to interact with an AS/400 message queue. It acts as a container for the QueuedMessage class. The getMessages() method, in particular, returns a list of QueuedMessage objects. The MessageQueue class can do the following:

The following example lists messages in the message queue for the current user:

                      // The message queue is on this as400.
      AS400 sys = new AS400(mySystem.myCompany.com);

                      // Create the message queue object.
                      // This object will represent the
                      // queue for the current user.
      MessageQueue queue = new MessageQueue(sys, MessageQueue.CURRENT);

                      // Get the list of messages currently
                      // in this user's queue.
      Enumeration e = queue.getMessages();

                      // Print each message in the queue.
      while (e.hasMoreElements())
      {
         QueuedMessage msg = e.getNextElement();
         System.out.println(msg.getText());
      }


[ Legal | AS/400 Glossary ]