1

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;
   }  
mike
  • 1,233
  • 1
  • 15
  • 36
davorp
  • 4,156
  • 3
  • 26
  • 34
  • 2
    Note that at ANY time you are using an AS400 object you are essentially talking to pre-started jobs where the attributes for your own job does not apply. Only exception is for using "native code" locally AND you have to do it inThread. We found that to be fragile. – Thorbjørn Ravn Andersen Jul 22 '11 at 14:05

2 Answers2

3

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.

Tracy Probst
  • 1,839
  • 12
  • 13
  • You suggest that an RPG program creates a spool file? – davorp Aug 13 '09 at 00:00
  • Creating spooled files what RPG was originally designed to do. :) You have to submit the RPG program to a new job with the job name specified. It's an inelegant solution, but it will give you a spooled file with the job name you want. – Tracy Probst Aug 13 '09 at 12:13
  • I'll ask my colleague to write a simple RPG and try with a Command Call from Java. – davorp Aug 13 '09 at 14:53
  • Make sure the command call is a SBMJOB command specifying the job name you want. – Tracy Probst Aug 13 '09 at 17:11
  • I gave up trying to have the same jobname this way... i find out another way: SBMJOB CMD( RUNJVA CLASS('/myJar.jar') PROP((java.version '1.6')) JOB(NASAJAVA) OUTPUT(*PRINT) ) JOB(NASAJAVA) JOBQ(QBATCH) Which submits two jobs with the same jobname on the QBATCH subsystem. The created spooled file from within Java goes to an agreed OUTPUT QUEUE, so we look it there. – davorp Aug 17 '09 at 05:50
1

Job, user and job number are assigned by the system and cannot be changed. To the best of my knowledge anyway.

Mike Wills
  • 20,959
  • 28
  • 93
  • 149
  • 2
    the code I posted should run on iSeries, so my plan is to start the java program like this: RUNJVA CLASS('/home/username/myJar.jar') PROP((java.version '1.6')) JOB(MYJOBNAME) OUTPUT(*PRINT) So I would like that my spool file gets the jobname of the JOB that started the program. In this case MYJOBNAME – davorp Aug 13 '09 at 06:00