01 - Programming (EN)01a - RPG (EN)

Last generated spoolfile

Linked to Massimo Duca‘s post Reading spoolfile with SQL I point out a simple technique that allows you to discover the infos of the last spoolfile generated.

The operating system provides us with the QSPRILSP API: just one single line of code to have all the spoolfile informations. Then combining the two techniques (find the spool and process it with SQL) it is possible to transform / improve the output of our programs with a few simple steps.

Example

Below an example of how to call up the API with variables that contain the spool data highlighted

   * API declaration
 dgetLastSpoolId   pr                  extpgm('QSPRILSP')            
 d ReceiverVariable…                                               
 d                                1    options(*varsize)             
 d ReceiverVariableLength…                                         
 d                               10i 0 const                         
 d FormatName                     8    const                         
 d errorCode                           likeds(QUSEC)                 
  * local variables                                                 
 d wait            s              1                                  
 
  * /copy declarations for spoolfile info ds and errors handling
  /copy qsysinc/qrpglesrc,qsprilsp                                   
  /copy qsysinc/qrpglesrc,qusec                                      
 
 * errors initialization                                    
   QUSBPrv = 0;                                                      

   monitor;                                                          
 * search for last spoolfile                                         
     getLastSpoolId(QSPL0100 :%size(QSPL0100) :'SPRL0100' :QUSEC);   
   on-error;                                                          
     clear QSPSN03;                                            
     clear QSPJN00;                                            
     clear QSPUN00;                                            
     clear QSPJNBR00;                                          
     clear QSPSNBR03;                                         
   endmon;                                                    
  * display last spoolfile data                         
   dsply ('Job ' + %trimr(QSPJN00) + '/' +                 
         %trimr(QSPUN00) + '/' + QSPJNBR00);              
   dsply ('Last spoolfile name ' + QSPSN03);                
   dsply ('Last spoolfile number ' + %char(QSPSNBR03)) ' ' Wait;   
    
   *inlr = *on;                                               
   return;                                                      

The monitor instruction has been inserted to be able to manage the eventuality that the job has not generated spool.

If instead of displaying (dsply) the search result we pass it to a module or service program that reads the spool and transforms it, it’s done. Furthermore, if the code of this example is transformed into a component with I/O parameters, it can be reused many times.

References

For more information, the official IBM documentation is available (https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_74/apis/QSPRILSP.htm)

Related Posts
HAVE YOU READ THE MANUAL?

It is the question I always ask my fellow programmers when they ask me something: "Have you read the manual?". Read more

SQL and DB2 for i – FAQ & Howtos – (Part 4 EN)

Here is the fourth part of this "FAQ & Howtos" for SQL and DB2 for i ... the previous 3 Read more

IBM i System Management: FAQ & Howto (Part 4) IT

This is the third part of the IBM i system management FAQ & Howto collection: you can see the other Read more

Writing messages to the job log with SQL

LPRINTF is a simple utility that allows you to write messages in the current job's log, directly with SQL. Let's Read more

About author

Head of Application development & Systems integration I have always worked on "i". Programmer, analyst, project manager, computer systems analyst, ... lots of hats but a single preferred platform. I collaborate with the FAQ400 community because I firmly believe in teamworking and I hope for a continuous and constant growth of the ecosystem of which I feel part.

Leave a Reply

%d bloggers like this: