1

I am developing a java class with JT400 and trying to get the result of the command “dspmsg qsysopr" with:

AS400 as400 = new AS400(system, user, password);
CommandCall cmd = new CommandCall(as400);
cmd.runCommand("dspmsg qsysopr");

I found out that the command runs in a JOB with the user QUSER, but an spool file with the result is generated under the user "user" specified when I instantiate the object AS400.

I can successfully run the command, but instead of the messages in the queue I have as result:

"Printer output created."

I get this result with the code:

Job job = cmd.getServerJob();
AS400Message[] messageList = cmd.getMessageList();
for (int i = 0; i < messageList.length; i++) {
    System.out.println(messageList[i].getText()); 
}

Question 1: Is there a way to not receive the messages in a spool file but have it returned to me as na AS400Message or something similar?

Not been able to do so, I am using the following method to get the spool file:

 public String getSpoolFile  (
         String splfname,     // splf name
         String splfnumbert,        // splf number
         String jobname,      // job name
         String jobuser,      // job user
         String jobfnumber // job number
         ) throws Exception  {

   int splno = Integer.parseInt(splfnumbert);

   SpooledFile sf = new SpooledFile( as400,        // system
                             splfname,     // splf name
                             splno,        // splf number
                             jobname,      // job name
                             jobuser,      // job user
                             jobfnumber               ); 




   PrintParameterList printParms = new PrintParameterList();
   printParms.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT, "/QSYS.LIB/QWPDEFAULT.WSCST");
   printParms.setParameter(PrintObject.ATTR_MFGTYPE, "*WSCST");

   // Create a page input stream from the spooled file
   PrintObjectPageInputStream is;
   String data ="";
   String response ="";

    is = sf.getPageInputStream(printParms);
       BufferedReader d = new BufferedReader(new InputStreamReader(is));
       while((data = d.readLine() )!=null)
       {
           response+=data+"\n";
       }

    return response; 
 }

The problem is: I don't have the parameters to call the method "getSpoolFile". If I manually log in AS400, check the spool file details and call the method with the manually obtained parameters, I successfully get the spool file. But the JOB object I receive under:

Job job = cmd.getServerJob();

After running:

cmd.runCommand("dspmsg qsysopr");

Is not the same Job that created the spool file. For example, If I check:

System.out.println(job.getUser());

I have "QUSER" as result, but the spool file is generated under “user” output queue.

Question 2: How can I get the JOB related to the generation of that spool file?

Question 3: can I also get the parameters related to the spool file generated like the spool file number and spool file name?

I need the following information in order to call the "getSpoolFile" method:

  • Spool file name
  • Spool file number
  • Job name
  • Job user
  • Job number

thanks, Carlos

2 Answers 2

3

You probably don't want to "print" the messages at all. You haven't said what you want to do with any messages once you get them (and getting QSYSOPR messages is probably not a good idea in the first place).

You might review AS/400 Message queue filtering - JT400 and then begin thinking how you want to proceed. There is a lot that can be done with messages.

3
  • Thank you for your reply. What I am trying to do is a class to run commands and get the reply of the results of the commands. It's a generic class that can be used to perform tasks or even do some monitoring on the system. Jan 30, 2016 at 1:05
  • It works well, except for this detail of the "dspmsg". When we run this command we obviously don't want to have as result "spool file created", but the messages of the queue qsysopr. If I got your point, you are telling me that for the dspmsg I should use another way to grab the messages, and not use the method "runCommand" to achieve this goal. Is that what you are saying? Ps. I am a real beginner in JT400.I will test the code of your link and read more about it. Jan 30, 2016 at 1:15
  • DSPMSG is practically never appropriate in any batch process, neither Java nor otherwise, except when a spooled report is explicitly needed for some reason. Use of JTOpen classes that are designed to access message queues are much better for you. Jan 30, 2016 at 1:57
2

Not specifically how to retrieve the spool file information but this will get you the QSYSOPR messages if that is your ultimate goal.

AS400 sys = new AS400(as400system,username,password);

//Get the user object for QSYSOPR
User u = new User(sys,"qsysopr");

//Get the path to the user's message queue
String qpath = u.getMessageQueue();

//Retrieve the message queue object
MessageQueue queue = new MessageQueue(sys, qpath);

// Get the list of messages currently in this user's queue.
queue.setListDirection(false);

//Get the first 15 messsages    
QueuedMessage[] qm = queue.getMessages(0,15);


//Loop through the messages
for (int i = qm.length -1; i >=0; i--)
       {

        System.out.println(qm[i].getText());

    }

Of course there are other properties, date, reply status, user that you can retrieve from the QueuedMessage class. No parsing needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.