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.

Index

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
DB2 for i SQL – String Manipulation – POSSTR-LOCATE-LOCATE_IN_STRING (EN)

Introduction Often, in our applications, we need to work with text strings, and DB2 SQL can come in very useful Read more

DB2 for i – FAQ & Howtos (EN)

DB2 Database and SQL ... maybe the most important things on IBM i platform: here's a collection of FAQs, tips Read more

IBM i 7.4 Announcement (En)

Comes directly with the Easter egg this IBM announcement for the news of the IBM i 7.4 version, iNext version Read more

Generated Always Columns (EN)

Introduction "Generated Always Column": are columns, table fields, filled by DB2 engine: something like columns with a default value but Read more

Recent Posts

VsCode Extention: Bob Cozzi’s RPG IV to RPG Free Conversion

👉 Review: Bob Cozzi’s RPG IV to RPG Free Conversion – a useful VS Code extension for RPG modernization If…

8 months ago

IBM i & SQL Tips #010 – Locating Programs in the Call Stack with STACK_INFO

Hello everyone, I’d like to highlight another excellent contribution by Massimo Duca, part of his ongoing IBM i & SQL…

8 months ago

Trying out “Display File DDS Edit” for VS Code

Intrigued by some recent posts from Cristian Larsen on LinkedIn (New Release – Display File DDS Edit v 0.10.1), I…

8 months ago

Project Bob: the next-gen AI partner for IBM i and IBM Z application development

Hello everyone, Today I’d like to draw your attention to a major new announcement from IBM: Project Bob — a…

8 months ago

IBM i & SQL Tips #6: Calling REST APIs and Parsing JSON Responses with SQL

I want to share with you a particularly useful article by Massimo Duca in the IBM i & SQL Tips…

9 months ago

How Parameter Passing Works in IBM i Programs (RPG / Cobol)

Hello everyone, I’d like to highlight a very useful article by Marco Riva on Markonetools, where he clearly explains how…

9 months ago