If you've ever needed to save a spooled file on your PC, email a spooled file, or simply view the printed version of the spooled file, you know how difficult and time-consuming it can be. Typically, you would have to convert the spooled file on the iSeries/400 to a PC stream file on the IFS using a conversion program and then copy the PC file from the IFS directory to your local PC using emulation software. Other options might be to use a third-party spooled file viewer or email utility that matches your specific need.
I face this problem on a daily basis and, while I can perform all the command line tasks to get spooled files to my PC, most of my users can't. With this in mind, I felt that there needed to be an easier way for end users and developers to access iSeries/400 spooled files on their PCs. While developing a Web-enabled report for a client, I came up with the idea for the Work with CGI Spooled Files (WRKCGISPLF) program, which you can download by clicking here.
WRKCGISPLF is an RPG IV Common Gateway Interface (CGI) program that communicates with the iSeries/400's HTTP server to deliver real-time iSeries/400 data to the Web. The program attempts to mimic the iSeries/400's Work with Spooled Files (WRKSPLF) command by allowing the user to perform all the same "display only" spooled file functions using a Web browser. Since Web browsers are installed on most PCs, there is no need for third-party software, emulation software, or iSeries/400 command line access. The user is able to view the list of spooled files by User Name, Output Queue, and/or User Data. From the list of spooled files, that user is able to view the spooled file in HTML format or PDF format.
How WRKCGISPLF Works
WRKCGISPLF is totally self-contained and needs no additional programs or HTML code. WRKCGISPLF generates its own HTML input forms and returns its own HTML response. This CGI program is invoked by the iSeries/400's HTTP server each time a user sends a request to its URL. The request to the HTTP server contains the program parameters selected by the user in the HTML form, and these parameters define the task that the program will perform.
The first time the user requests the WRKCGISPLF program (with no parameters), a Work with CGI Spooled Files prompt is displayed (see Figure 1).
Figure 1: This screen is the Work with CGI Spooled Files prompt.
The prompt contains the same parameters that are included in the WRKSPLF command. Entering data into the text boxes gives the user the ability to select spooled files by User, Output Queue, and/or User Data. Pressing the Get Spooled Files button presents the user with a list of spooled files that meet the selection criteria (see Figure 2).
Figure 2: This screen provides the user with a list of spooled files that meet the selection criteria.
On the right side of each spooled file in the list are two HTML hyperlinks. The first hyperlink, HTML, displays the spooled file as an HTML document. The second hyperlink, PDF, displays the spooled file as an Adobe Acrobat document. By using the menu options available to the browser or the Acrobat Reader, the user is able to save the document to the PC hard drive.
WRKCGISPLF Technical Description
WRKCGISPLF consists of three components: WRKCGISPLF (the main program module), WSC_PROTO (the source member containing prototypes), and PWCSPARM (a physical file for parsing the parameters passed to the program). All the programming logic, procedures, and functions are contained within WRKCGISPLF. The program has four main processing tasks: process the parameters, list the spooled files, build the HTML document, and build the PDF document.
1) Process the Parameters
The parameters that are passed to the WRKCGISPLF program are the heart of its processing. These parameters are defined by the fields in physical file PWCSPARM. The APICvtDB function (QtmhCvtDb API) is used to parse the data from the input request buffer to an externally described data structure based on file PWCSPARM. The program then moves the data structure values to the file fields and writes a new record.
2) List the Spooled Files
Using the parameters that are passed to the program (specifically User, Output Queue. and User Data), the SndSplLst procedure generates the list of spooled files. The SndSplLst procedure uses the QUSLSPL API to load the selected list of spooled files into a temporary user space. As each spooled file entry is retrieved from the user space, the QUSRSPLA API is called to retrieve additional spooled file attributes that are loaded into data structure SplDataOut. Each spooled file entry is wrapped in HTML with the associated tags that hyperlink back to the CGI program for the HTML and PDF document requests. The HTML entry is then sent back to the HTTP server using the APIStdOut function (QtmhWrStout API).
When the program receives a request to display the spooled file as an HTML document, the $ProcHTML subroutine is executed. This subroutine copies the selected spooled file into SplOutput using the Copy Spooled Files (CPYSPLF) command, loops through the file, wraps the records in HTML, and delivers it to the user.
3) Build the HTML Document
4) Build the PDF Document
When the program receives a request to display the spooled file as a PDF document, the $ProcPDF subroutine is executed. This subroutine processes the same as the $ProcHTML subroutine, but it uses the PDF functions to build a proper PDF document. Each PDF document consists of four parts: the header (function PDFHeader), the body (function PDFPages), the cross-reference table (function PDFCrossRef) and the trailer (function PDFTrailer).
Compiling the Objects
CRTPF FILE(your_Lib_name/PWCSPARMS)
CRTRPGMOD PGM(your_Lib_name/WRKCGISPLF)
CRTPGM PGM(your_Lib_name/WRKCGISPLF)
MODULE(WRKCGISPLF)
BNDSRVPGM(QHTTPSVR/QZHBCGI)
Steven Goetjen is an independent consultant in New York with over 15 years of industry experience on IBM midrange systems and PC systems. He can be reached at
LATEST COMMENTS
MC Press Online