Search code examples
javaibm-midrangejt400

Create a Spooled File from Java with a specified Job name on iSeries


Is there a way to specifiy the JOB name when creating a spooled file? So that my created s.f. doesn't have the default "QPRTJOB".

My method that creates a spooled file with the default QPRTJOB job:


   public static SpooledFile createSpoolFile( com.ibm.as400.access.AS400 as, PrinterFile pPrinterFile,
         OutputQueue outq, String msg ) {
      SpooledFile result = null;
      try {
         PrintParameterList parms = new PrintParameterList();

         // create a PrintParameterList with the values that we want
         // to override from the default printer file...we will override
         // the output queue and the copies value.
         parms.setParameter( PrintObject.ATTR_PRINTER_FILE, pPrinterFile.getPath() );
         parms.setParameter( PrintObject.ATTR_JOBUSER, AS400.getUser().getUserProfileName() );
         parms.setParameter( PrintObject.ATTR_JOBNAME, "NASAOBRJVA" );
         parms.setParameter( PrintObject.ATTR_OUTPUT_QUEUE, outq.getPath() );
         parms.setParameter( PrintObject.ATTR_CHAR_ID, "*SYSVAL" );

         SpooledFileOutputStream spool = new SpooledFileOutputStream( as, parms, pPrinterFile,
               outq );


         SCS5256Writer scsWtr = new SCS5256Writer( spool, pPrinterFile.getSystem().getCcsid(), pPrinterFile.getSystem() );

         String[] redovi = msg.split( "\n" );
         for ( int i = 0; i < redovi.length; i++ ) {
            if (redovi[i].equals( "" ) || redovi[i].equals( " " )) {
               continue;
            }
            scsWtr.write( redovi[i].trim() );
            if (i < redovi.length - 1) {
               scsWtr.newLine();
            }
         }

         scsWtr.close();
         result = spool.getSpooledFile();
         System.out.println("Spool is in Job: " + result.getJobNumber() + "/" + result.getJobUser() + "/" + result.getJobName());
      }
      catch ( Exception e ) {
         LOG.error( e );
      }
      return result;
   }  

Solution

  • ATTR_JOBUSER and ATTR_JOBNAME are read-only attributes for a spooled file. I've noticed that whenever my Java programs talk to the AS/400--even those that are running natively on the AS/400--they talk to host server jobs and not necessarily the job that submitted the Java call. In this case, you are talking to a print server job on the 400 and all of your spooled files will get a QPRTJOB job name.

    An elaborate work-around would be to have your Java program submit a new job named NASAOBRJVA with a command to call some simple RPG program with the message text as a parameter. That's probably a lot of effort for a job name on a spooled file, but you know your project enough to know if it's worth that effort.