Some people in this world are gifted with tools, and some people are not. I are not. This became abundantly clear one recent Saturday afternoon when the lawnmower stopped lawn mowing. I took the lawnmower apart. I put it together. I did it again. For the life of me, I couldn't figure out what was wrong with the thing. I decided that since it was 107 degrees Fahrenheit, the problem was nothing that a good repair shop couldn't handle, so I took the stupid lawnmower to the shop, gave the kid down the street 10 bucks to mow the lawn, and drank a beer.
To some folks, transporting things across computer systems is kind of like fixing the lawnmower is to me. Some can do it themselves; some would rather hire it out. Fortunately, where putting spooled files into Web pages is concerned, both are reasonable and viable options, and I'll show you both ways. For the purposes of this article, I will assume that your iSeries/400 is not your Web server and that to publish spooled files you need to copy them into an HTML document on another machine. If your iSeries/400 is your Web server, I refer you to Chapter 10 of the excellent book iSeries and AS/400 APIs at Work by Doug Pence and Ron Hawkins (MC Press, 2001).
Stocking Your Toolbox
Since the goal here is to take a spooled output file from an AS/400 and put it on a Web page, you will find yourself faced with a process that consists of essentially two steps: Make a Web page out of a spooled file, and put it someplace where you can get to it so that you can copy it from your AS/400 to your Web server. This will not only save you paper, it will make your printout accessible to anyone with an Internet connection and a browser.
To create an HTML document from a spooled file, you must first copy the spooled file to a database file, then copy the database file to a document library file. From there, you can edit the file, move it to your Web server, and publish it on the Web.
If you do this a lot, it would be useful to have a toolbox of standard-issue components to build your HTML document. There will be some items that always go into your HTML documents, so it would help to create a database of those items. It would also help to be able to add some entries, such as a title, as you create the document. With a simple CL and RPG program, you can make creating HTML documents from spooled files relatively painless.
However, there is a caveat: In the example, I assume that the spooled file you wish to serve to the Web was created by your current interactive job. Adapting the example so that it works with any spooled file is left as an exercise for the reader. Evolving the example so that it does more is also left as an exercise for the reader.
The first step in moving a spooled file to a Web page is to copy the spooled file to a database file. The database file must exist, but it can exist in QTEMP, so the job can clean up after itself.
If you break that step down, it becomes clear that you need to create a standard file containing some HTML lines. These are entries that will always go into the result, no matter what the result is. Create a database file with a record length of 136, and call it STDHTM. The command to create the file is CRTPF FILE(MYLIB/STDHTM) RCDLEN(136). Using DFU, add the following three records:
You may want to modify the above HTML to provide different colors or perhaps a background image. I've found that the courier font works best with reports. You might also want to add META tags to your file as appropriate. Having standard entries that you can combine with a spooled file to create an HTML document saves you from having to edit that document to add the same entries every time you create a Web page from a spooled file.
Now that you have set up your repetitive entries, you can put them into a database and append your spooled file to that database. The result will be a database that contains standard HTML entries and the entries from your spooled file. When you've done this, you'll almost be ready to move the file to the document library system.
Take a look at the CL in Figure 1 (the CL presents a prompt screen, whose DDS is in Figure 2, with a sample in Figure 3).
Figure 1: This CL program forms the cornerstone of your building block.
Figure 2: This DDS gives a prompt screen asking the user for the values you need.
Figure 3: This prompt screen appears as your user sees it.
After first checking to be sure the database file isn't already there, create a new database file called SPLFDB in QTEMP by issuing the command CRTPF FILE(QTEMP/SPLFDB) SRCFILE(MYLIB/QDDSSRC) OPTION(*NOSRC *NOLIST) LVLCHK(*NO). (Figure 4 shows the DDS for SPLFDB).
Figure 4: This shows the SPLFDB DDS source.
This command creates the physical file you'll use as a container for the records from which you want to create a Web page. Note that the command prevents a source listing and specifies no level checking. Now that you've got your file, you'll copy in the standard HTML lines that you put in the STDHTM file. The CL program issues the following command:
CPYF FROMFILE(MYLIB/STDHTM) TOFILE(QTEMP/SPLFDB) MBROPT(*ADD) FMTOPT(*NOCHK)
This will copy your standard HTML lines into your SPLFDB file in QTEMP.Next, a prompt screen (see Figure 2 for DDS and Figure 3 for screen shot) asks for the spooled file name (&SPLFILE), the name of the document you wish to create (&DOCNAM), the folder in which you want the document to land (&FLDNAM), and a title for the document (&TITLE). These are all stored in variables within the CL program.
After doing some error checking to make sure you have all your values, add HTML
Figure 5: This RPG program lets you add HTML tags to your document and sets line breaks over spooled file records.
HADTITLE is very simple, indeed. Here's what it does: It looks for any record that doesn't begin with a tag marker(<) or end with a line break marker (
). If it finds a record meeting those criteria, it adds a line break marker to the end of the record. HADTITLE then writes whatever was passed to it at the end of the file.
Why would you do it this way? What you've done so far gives you a database file with one type of record: lines that consist of HTML tags wrapped around corresponding text. You can reasonably assume that all of those lines begin with a less than symbol (<).You don't want to change those lines, so the program looks for that symbol and ignores all lines that have < as their first character.
You want to add a title, but because your title will change from report to report, you can't really make that part of your standard HTML, so you create a program to add the title for you.
What you haven't done yet is to copy your spooled file records into your database file. These records will contain no HTML. I've found, by experimenting, that they need to end with a line break--
--or they all run together and look funny on the screen. After you've added the spooled file records, call HADTITLE once again to add those line breaks and append the tag to end the document.
To compile HADTITLE, you'll need to create an SPLFDB somewhere in your library list. On this first call of HADTITLE, it will ignore your STDHTM records (for the reasons described above) and add whatever title you keyed into your prompt screen.
Now that you've built the foundation of your HTML document, it's time to add the spooled file's records. The CL will issue the command CPYSPLF FILE(&SPLFILE) TOFILE(QTEMP/SPLFDB) MBROPT(*ADD). Note that the command as issued assumes that the spooled file was produced by the current interactive job. If you want to use any spooled file, you'll need to modify the code shown here to accommodate job name and number in addition to spooled file name.
With your spooled file records now in place in your database file, you'll want to close your document with the