Serving Spooled Files to the Web

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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.

Baby Steps

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).


/*********************************************************************/
/*********************************************************************/
/* */
/* PROGRAM ID - SPOOLTOHTM */
/* AUTHOR - Christopher J. Devous */
/* MODIFIED - 3/13/00 */
/* */
/*********************************************************************/
PGM

DCLF FILE(MYLIB/SPLTOHTMPM)
VAR(&XTITLE) VALUE('' *CAT &TITLE +<BR> *CAT '')
CHGVAR VAR(&PGMSGQ) VALUE('SPLTOHTM')

CHKOBJ OBJ(QTEMP/SPLFDB) OBJTYPE(*FILE)
MONMSG MSGID(CPF9801) EXEC(GOTO CMDLBL(NODEL))
DLTF FILE(QTEMP/SPLFDB)
NODEL:
CRTPF FILE(QTEMP/SPLFDB) SRCFILE(MYLIB/QDDSSRC) +
OPTION(*NOSRC *NOLIST) LVLCHK(*NO)
CPYF FROMFILE(MYLIB/STDHTM) +
TOFILE(QTEMP/SPLFDB) MBROPT(*ADD) +
FMTOPT(*NOCHK)

RDSPLY: SNDF RCDFMT(MSGCTL)
SNDRCVF RCDFMT(SPLTOHTMPM)
RMVMSG PGMQ(*SAME) CLEAR(*ALL)

IF COND(&IN03 *EQ '1') THEN(DO)
GOTO CMDLBL(DONE)
ENDDO

IF COND(&FLDNAM *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Folder name is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

IF COND(&TITLE *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Title is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

IF COND(&DOCNAM *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Document name is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

IF COND(&SPLFILE *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Spooled file name is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

OVRDBF FILE(SPLFDB) FRCRATIO(1)

CHGVAR VAR(&XTITLE) VALUE('')

CALL PGM(MYLIB/HADTITLE) PARM(&XTITLE)

CPYSPLF FILE(&SPLFILE) TOFILE(QTEMP/SPLFDB) +
MBROPT(*ADD)

CHGVAR     VAR(&TITLE) VALUE(''
CALL PGM(MYLIB/HADTITLE) PARM(&TITLE)

DLTOVR FILE(*ALL)

CPYTOPCD FROMFILE(QTEMP/SPLFDB) TOFLR(&FLDNAM) +
TODOC(&DOCNAM) REPLACE(*YES)

DLTF FILE(QTEMP/SPLFDB)

DONE:
RETURN

ENDPGM
Figure 1: This CL program forms the cornerstone of your building block.
A*****************************************************************
A*
A* FILE ID - SPLTOHTMPM
A* FILE NAME - Prompt Screen for Spooled Files to HTML conversion
A*
A*****************************************************************
A DSPSIZ(24 80 *DS3)
A PRINT
A R SPLTOHTMPM
A CF03(03 'EXIT')
A BLINK
A OVERLAY
A PUTOVR
A 1 73DATE
A EDTCDE(Y)
A 2 2SYSNAME
A 2 73TIME
A 23 5'Enter=Accept F3=Exit'
A DSPATR(HI)
A COLOR(BLU)
A 1 2'SPLToHTM'
A 1 23'Copy Spooled Files to Document Lib-
A rary'
A 9 18'Spooled File. . . . '
A SPLFILE 10A B 9 40
A 11 17'Document Name. . . .'
A DOCNAM 12A B 11 40
A 15 7'Title:'
A TITLE 50A B 15 16CHECK(LC)
A 13 17'Folder Name. . . . .'
A FLDNAM 10A B 13 40
A*
A R MSGRCD TEXT('MSG SFL RECORD')
A SFL SFLMSGRCD(24)
A MSGKEY SFLMSGKEY
A PGMSGQ SFLPGMQ
A*
A R MSGCTL TEXT('MSG SFL CONTROL')
A OVERLAY SFLCTL(MSGRCD) SFLSIZ(10)
A SFLPAG(1) SFLDSPCTL SFLDSP SFLINZ
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).

A*****************************************************************
A*
A* FILE ID - SPLFDB
A* FILE NAME - Container for Spooled File Records
A*
A*
A*****************************************************************
A R SPREC
A SPFLD 136A TEXT('Spool Records')
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 tags to the document title keyed into the prompt screen, and put the result in a variable called (&XTITLE). This will save you from having to enter the tags yourself in the prompt screen. Your next step is to add the title line to the HTML already stored in SPLFDB. To accomplish this, I've written the simple RPG program HADTITLE shown in <B>Figure 5</B>. </p><!------ callout box begin ---><TABLE cellspacing="0" border="0" align="center"><TR><TD align="middle" bgcolor="blue"><TABLE cellspacing="0" cellpadding="2" border="0" width="100%"><TR><TD align="lrft" bgcolor="#ebebeb" ><!----- callout content begin ---><pre><br>HDebug <br> *---------------------------------------------------------* <br> * * <br> * Program - HAdTitle * <br> * Add record to SPLFDB * <br> * Add <BR> tag to end of existing untagged *<br> * Lines *<br> * * <br> *---------------------------------------------------------* <br>FSPLFDB UF A E K Disk <br> * <br> * --------------------------------------------------------------- <br> * M a i n l i n e P r o c e s s i n g <br> * --------------------------------------------------------------- <br> * <br>C Read SPREC 99<br>C DoW *IN99 = *OFF <br>C If %subst(SPFLD:1:1) <>'<' <br>C and %subst(SPFLD:133:1) <>'<' <br>C Eval %subst(SPFLD:133:4) = '<BR>' <br>C Update SPREC <br>C EndIf <br>C Read SPREC 99<br>C EndDo <br>C Eval SPFLD = HTMLine <br>C Write SPREC <br> * <br>C Move *ON *INLR <br> *---------------------------------------------------------------* <br> * End of MainLine Processing <br> *---------------------------------------------------------------* <br>C *InzSR BegSr <br> *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -* <br> * <br> * Parameter List <br>C *ENTRY PList <br>C Parm HTMLine 65 <br> * <br> *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*<br>C EndSr <br> *---------------------------------------------------------------*</pre><!----- callout content end ---></TD></TR></TABLE></TD></TR></TABLE><!------ callout box end ---><h5 align="center">Figure 5: This RPG program lets you add HTML tags to your document and sets line breaks over spooled file records. </h5><p> 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 (<BR>). 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. </p> <p>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.</p> <p>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. </p><p>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--<BR>--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 </HTML> tag to end the document.</p> <p>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.</p><p>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.</p> <p>With your spooled file records now in place in your database file, you'll want to close your document with the </HTML> tag. Set that up as a parameter and, once again, call HADTITLE. This time, HADTITLE will add line break tags (<BR>) to the spooled file records and add the </HTML> tag at the end of the file before returning.</p> <p>Now that you've built a database file containing your HTML document as you want it to appear, you can take the final step and copy the database file to a folder in the document library. The CL does this by issuing the command CPYTOPCD FROMFILE(QTEMP/SPLFDB) TOFLR(&FLDNAM) TODOC(&DOCNAM) REPLACE(*YES). Then, clean up after yourself with DLTF FILE(QTEMP/SPLFDB).</p> <p>The Copy to PC Document (CPYTOPCD) command creates a document in the specified folder of the document library system. The document can be copied from the OS/400 IFS to your Web server and presented to the world. Please remember that the example was created for the purpose of showing the steps necessary to get a spooled file into an HTML document. You might want to add some error checking, like looking for the existence of a document name and warning of an overwrite, or checking to make sure the folder specified really exists, and perhaps tuning things up a bit. You might want to add some scripting code to the start of your document.</p><h3>I Don't Like Making My Own Stuff! </h3><p>Sometimes its easier (and safer!) to hire the kid down the street. A number of folks have produced spooled file utilities designed to help you publish reports to the Web. See the sidebar ("Tools to Help You Serve Spooled Files") for details.</p><p>If you've gotten to this point, you now have the basic tools necessary to create HTML documents from spooled files. I encourage you to play around with the code presented here and enhance it for your own environment. </p><p><B>Christopher J. Devous</B> is director of systems development for The Antigua Group, a manufacturer of fine casual apparel based in Scottsdale, Arizona. Chris has nearly 20 years of experience writing programs and designing and managing various types of computer systems. He can be reached by email at <A href="mailto: cdevous@antigua.com"><span id="cloakbef6ed7e87e2d8c9cab76fba586b1a72">This email address is being protected from spambots. You need JavaScript enabled to view it.</span><script type='text/javascript'> document.getElementById('cloakbef6ed7e87e2d8c9cab76fba586b1a72').innerHTML = ''; var prefix = 'ma' + 'il' + 'to'; var path = 'hr' + 'ef' + '='; var addybef6ed7e87e2d8c9cab76fba586b1a72 = 'cdevous' + '@'; addybef6ed7e87e2d8c9cab76fba586b1a72 = addybef6ed7e87e2d8c9cab76fba586b1a72 + 'antigua' + '.' + 'com'; var addy_textbef6ed7e87e2d8c9cab76fba586b1a72 = 'cdevous' + '@' + 'antigua' + '.' + 'com';document.getElementById('cloakbef6ed7e87e2d8c9cab76fba586b1a72').innerHTML += '<a ' + path + '\'' + prefix + ':' + addybef6ed7e87e2d8c9cab76fba586b1a72 + '\'>'+addy_textbef6ed7e87e2d8c9cab76fba586b1a72+'<\/a>'; </script></A>.</p><!------ callout box begin ---><TABLE cellspacing="0" border="0" width="50%" align="center"><TR><td class="post" align="middle" bgcolor="#3366cc"><TABLE cellspacing="0" cellpadding="2" border="0" width="100%"><TR><td class="post" align="left" bgcolor="#ebebeb"><!----- callout content begin ---><h3>Tools to Help You Serve Spooled Files</h3><p>Want to serve spooled files to the Web? No time to build the programs to do it? Here are some options, along with where you can find them on the Web:</p><ul> <li><B>BVS/Tools</B>' Spooled File Tools (SPLTOOL) is a shareware program that will help copy spooled files to folder documents, FTP, and email. Go to <A href="http://www.bvstools.com/">www.bvstools.com</A> for more information. <li><B>Kisco Information Systems</B>' WebReport/400 converts reports to HTML and sends them as email. Find it at <A href="http://www.kisco.com/">www.kisco.com</A>. <li><B>Business Computer Design Int'l</B>'s Spool-Explorer/400 pushes or pulls spooled files to PCs and the Web. Look for it at <A href="http://www.bcdsoftware.com/">www.bcdsoftware.com</A>. <li><B>Gumbo Software</B>'s Spool-a-Matic archives spooled files and sends them to the Web. Go to <A href="http://www.gumbo.com/">www.gumbo.com</A> for further information. <li><B>Evergreen Interactive Systems</B>'s AS/400 and iSeries Report Downloader sends report data to a variety of formats, including Microsoft Word, Excel, and HTML. Look for it at <A href="http://www.evergreeninteractive.com/">www.evergreeninteractive.com</A>. <li><B>Chouinard & Myhre</B>'s Spoolfile EMail'r distributes spooled files by email using Client Access/400 and ActiveX technology. Download an evaluation copy at <A href="http://www.cm-inc.com/what/index.html">www.cm-inc.com/what/index.html</A>. <li><B>Net400</B>'s NetMail400 lets you integrate your iSeries applications to email anything you can print. Find it at <A href="http://www.net400.com/">www.net400.com</A>. <li><B>RJS Software Systems</B>' WinSpool/400 supports Web integration, email integration, and electronic forms integration. For more information, visit <A href="http://www.rjssoftware.com/">www.rjssoft.com</A>. <li><B>DataTrade</B>'s SpoolView suite of report management products manages a variety of storage, archival, and retrieval options, including Internet-based PCs. Order a demo at <A href="http://www.datatrade.com/">www.datatrade.com</A>. <li><B>Broderick Data Systems</B>' SpoolOrganizer/400 supports email bundling of reports, as well as Internet access and many other features. Check it out at <A href="http://www.broderickdata.com/">www.broderickdata.com</A>.</li> </ul><!----- callout content end ---></td></TR></TABLE></td></TR></TABLE><!------ callout box end ---><p align="center">-Christopher J. Devous</p> </blockquote> <section class="article-content" itemprop="articleBody"> <p>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. <!-- Ad1 --> 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. </p> <p>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<A href="http://mc-store.com/isandasapatw.html"> iSeries and AS/400 APIs at Work </A>by Doug Pence and Ron Hawkins (MC Press, 2001).</p><h3>Stocking Your Toolbox</h3><p>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.</p> <p>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.</p><p>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.</p> <p>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.</p><h3>Baby Steps</h3><p>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. </p><p>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:</p><div style="font-family: 'Courier New', Courier, monospace;"><HTML><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p><br><BODY BGCOLOR="#ffffff" TEXT="#000000" LINK="#0080ff" VLINK="#ff0080" ALINK="#8080ff"><o:p></o:p><br><FONT FACE-="Courier"></div><p>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.</p> <p>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.</p> <p>Take a look at the CL in <B>Figure 1</B> (the CL presents a prompt screen, whose DDS is in <B>Figure 2</B>, with a sample in <B>Figure 3</B>). </p><!------ callout box begin ---><TABLE cellspacing="0" border="0" align="center"><TR><TD align="middle" bgcolor="blue"><TABLE cellspacing="0" cellpadding="2" border="0" width="100%"><TR><TD align="lrft" bgcolor="#ebebeb" ><!----- callout content begin ---><PRE><br>/*********************************************************************/<br>/*********************************************************************/<br>/* */<br>/* PROGRAM ID - SPOOLTOHTM */<br>/* AUTHOR - Christopher J. Devous */<br>/* MODIFIED - 3/13/00 */<br>/* */<br>/*********************************************************************/<br> PGM <br> <br> DCLF FILE(MYLIB/SPLTOHTMPM) <br> VAR(&XTITLE) VALUE('<TITLE>' *CAT &TITLE +<BR> *CAT '')
CHGVAR VAR(&PGMSGQ) VALUE('SPLTOHTM')

CHKOBJ OBJ(QTEMP/SPLFDB) OBJTYPE(*FILE)
MONMSG MSGID(CPF9801) EXEC(GOTO CMDLBL(NODEL))
DLTF FILE(QTEMP/SPLFDB)
NODEL:
CRTPF FILE(QTEMP/SPLFDB) SRCFILE(MYLIB/QDDSSRC) +
OPTION(*NOSRC *NOLIST) LVLCHK(*NO)
CPYF FROMFILE(MYLIB/STDHTM) +
TOFILE(QTEMP/SPLFDB) MBROPT(*ADD) +
FMTOPT(*NOCHK)

RDSPLY: SNDF RCDFMT(MSGCTL)
SNDRCVF RCDFMT(SPLTOHTMPM)
RMVMSG PGMQ(*SAME) CLEAR(*ALL)

IF COND(&IN03 *EQ '1') THEN(DO)
GOTO CMDLBL(DONE)
ENDDO

IF COND(&FLDNAM *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Folder name is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

IF COND(&TITLE *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Title is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

IF COND(&DOCNAM *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Document name is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

IF COND(&SPLFILE *EQ ' ') THEN(DO)
RMVMSG CLEAR(*NEW)
SNDPGMMSG MSG('Spooled file name is blank') TOPGMQ(*SAME)
GOTO CMDLBL(RDSPLY)
ENDDO

OVRDBF FILE(SPLFDB) FRCRATIO(1)

CHGVAR VAR(&XTITLE) VALUE('')

CALL PGM(MYLIB/HADTITLE) PARM(&XTITLE)

CPYSPLF FILE(&SPLFILE) TOFILE(QTEMP/SPLFDB) +
MBROPT(*ADD)

CHGVAR     VAR(&TITLE) VALUE(''
CALL PGM(MYLIB/HADTITLE) PARM(&TITLE)

DLTOVR FILE(*ALL)

CPYTOPCD FROMFILE(QTEMP/SPLFDB) TOFLR(&FLDNAM) +
TODOC(&DOCNAM) REPLACE(*YES)

DLTF FILE(QTEMP/SPLFDB)

DONE:
RETURN

ENDPGM

Figure 1: This CL program forms the cornerstone of your building block.
A*****************************************************************
A*
A* FILE ID - SPLTOHTMPM
A* FILE NAME - Prompt Screen for Spooled Files to HTML conversion
A*
A*****************************************************************
A DSPSIZ(24 80 *DS3)
A PRINT
A R SPLTOHTMPM
A CF03(03 'EXIT')
A BLINK
A OVERLAY
A PUTOVR
A 1 73DATE
A EDTCDE(Y)
A 2 2SYSNAME
A 2 73TIME
A 23 5'Enter=Accept F3=Exit'
A DSPATR(HI)
A COLOR(BLU)
A 1 2'SPLToHTM'
A 1 23'Copy Spooled Files to Document Lib-
A rary'
A 9 18'Spooled File. . . . '
A SPLFILE 10A B 9 40
A 11 17'Document Name. . . .'
A DOCNAM 12A B 11 40
A 15 7'Title:'
A TITLE 50A B 15 16CHECK(LC)
A 13 17'Folder Name. . . . .'
A FLDNAM 10A B 13 40
A*
A R MSGRCD TEXT('MSG SFL RECORD')
A SFL SFLMSGRCD(24)
A MSGKEY SFLMSGKEY
A PGMSGQ SFLPGMQ
A*
A R MSGCTL TEXT('MSG SFL CONTROL')
A OVERLAY SFLCTL(MSGRCD) SFLSIZ(10)
A SFLPAG(1) SFLDSPCTL SFLDSP SFLINZ
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).

A*****************************************************************
A*
A* FILE ID - SPLFDB
A* FILE NAME - Container for Spooled File Records
A*
A*
A*****************************************************************
A R SPREC
A SPFLD 136A TEXT('Spool Records')
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 tags to the document title keyed into the prompt screen, and put the result in a variable called (&XTITLE). This will save you from having to enter the tags yourself in the prompt screen. Your next step is to add the title line to the HTML already stored in SPLFDB. To accomplish this, I've written the simple RPG program HADTITLE shown in <B>Figure 5</B>. </p><!------ callout box begin ---><TABLE cellspacing="0" border="0" align="center"><TR><TD align="middle" bgcolor="blue"><TABLE cellspacing="0" cellpadding="2" border="0" width="100%"><TR><TD align="lrft" bgcolor="#ebebeb" ><!----- callout content begin ---><pre><br>HDebug <br> *---------------------------------------------------------* <br> * * <br> * Program - HAdTitle * <br> * Add record to SPLFDB * <br> * Add <BR> tag to end of existing untagged *<br> * Lines *<br> * * <br> *---------------------------------------------------------* <br>FSPLFDB UF A E K Disk <br> * <br> * --------------------------------------------------------------- <br> * M a i n l i n e P r o c e s s i n g <br> * --------------------------------------------------------------- <br> * <br>C Read SPREC 99<br>C DoW *IN99 = *OFF <br>C If %subst(SPFLD:1:1) <>'<' <br>C and %subst(SPFLD:133:1) <>'<' <br>C Eval %subst(SPFLD:133:4) = '<BR>' <br>C Update SPREC <br>C EndIf <br>C Read SPREC 99<br>C EndDo <br>C Eval SPFLD = HTMLine <br>C Write SPREC <br> * <br>C Move *ON *INLR <br> *---------------------------------------------------------------* <br> * End of MainLine Processing <br> *---------------------------------------------------------------* <br>C *InzSR BegSr <br> *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -* <br> * <br> * Parameter List <br>C *ENTRY PList <br>C Parm HTMLine 65 <br> * <br> *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*<br>C EndSr <br> *---------------------------------------------------------------*</pre><!----- callout content end ---></TD></TR></TABLE></TD></TR></TABLE><!------ callout box end ---><h5 align="center">Figure 5: This RPG program lets you add HTML tags to your document and sets line breaks over spooled file records. </h5><p> 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 (<BR>). 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. </p> <p>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.</p> <p>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. </p><p>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--<BR>--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 </HTML> tag to end the document.</p> <p>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.</p><p>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.</p> <p>With your spooled file records now in place in your database file, you'll want to close your document with the </HTML> tag. Set that up as a parameter and, once again, call HADTITLE. This time, HADTITLE will add line break tags (<BR>) to the spooled file records and add the </HTML> tag at the end of the file before returning.</p> <p>Now that you've built a database file containing your HTML document as you want it to appear, you can take the final step and copy the database file to a folder in the document library. The CL does this by issuing the command CPYTOPCD FROMFILE(QTEMP/SPLFDB) TOFLR(&FLDNAM) TODOC(&DOCNAM) REPLACE(*YES). Then, clean up after yourself with DLTF FILE(QTEMP/SPLFDB).</p> <p>The Copy to PC Document (CPYTOPCD) command creates a document in the specified folder of the document library system. The document can be copied from the OS/400 IFS to your Web server and presented to the world. Please remember that the example was created for the purpose of showing the steps necessary to get a spooled file into an HTML document. You might want to add some error checking, like looking for the existence of a document name and warning of an overwrite, or checking to make sure the folder specified really exists, and perhaps tuning things up a bit. You might want to add some scripting code to the start of your document.</p><h3>I Don't Like Making My Own Stuff! </h3><p>Sometimes its easier (and safer!) to hire the kid down the street. A number of folks have produced spooled file utilities designed to help you publish reports to the Web. See the sidebar ("Tools to Help You Serve Spooled Files") for details.</p><p>If you've gotten to this point, you now have the basic tools necessary to create HTML documents from spooled files. I encourage you to play around with the code presented here and enhance it for your own environment. </p><p><B>Christopher J. Devous</B> is director of systems development for The Antigua Group, a manufacturer of fine casual apparel based in Scottsdale, Arizona. Chris has nearly 20 years of experience writing programs and designing and managing various types of computer systems. He can be reached by email at <A href="mailto: cdevous@antigua.com"><span id="cloak197d9079ff2ec6f2d8c34bdf8a047c83">This email address is being protected from spambots. You need JavaScript enabled to view it.</span><script type='text/javascript'> document.getElementById('cloak197d9079ff2ec6f2d8c34bdf8a047c83').innerHTML = ''; var prefix = 'ma' + 'il' + 'to'; var path = 'hr' + 'ef' + '='; var addy197d9079ff2ec6f2d8c34bdf8a047c83 = 'cdevous' + '@'; addy197d9079ff2ec6f2d8c34bdf8a047c83 = addy197d9079ff2ec6f2d8c34bdf8a047c83 + 'antigua' + '.' + 'com'; var addy_text197d9079ff2ec6f2d8c34bdf8a047c83 = 'cdevous' + '@' + 'antigua' + '.' + 'com';document.getElementById('cloak197d9079ff2ec6f2d8c34bdf8a047c83').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy197d9079ff2ec6f2d8c34bdf8a047c83 + '\'>'+addy_text197d9079ff2ec6f2d8c34bdf8a047c83+'<\/a>'; </script></A>.</p><!------ callout box begin ---><TABLE cellspacing="0" border="0" width="50%" align="center"><TR><td class="post" align="middle" bgcolor="#3366cc"><TABLE cellspacing="0" cellpadding="2" border="0" width="100%"><TR><td class="post" align="left" bgcolor="#ebebeb"><!----- callout content begin ---><h3>Tools to Help You Serve Spooled Files</h3><p>Want to serve spooled files to the Web? No time to build the programs to do it? Here are some options, along with where you can find them on the Web:</p><ul> <li><B>BVS/Tools</B>' Spooled File Tools (SPLTOOL) is a shareware program that will help copy spooled files to folder documents, FTP, and email. Go to <A href="http://www.bvstools.com/">www.bvstools.com</A> for more information. <li><B>Kisco Information Systems</B>' WebReport/400 converts reports to HTML and sends them as email. Find it at <A href="http://www.kisco.com/">www.kisco.com</A>. <li><B>Business Computer Design Int'l</B>'s Spool-Explorer/400 pushes or pulls spooled files to PCs and the Web. Look for it at <A href="http://www.bcdsoftware.com/">www.bcdsoftware.com</A>. <li><B>Gumbo Software</B>'s Spool-a-Matic archives spooled files and sends them to the Web. Go to <A href="http://www.gumbo.com/">www.gumbo.com</A> for further information. <li><B>Evergreen Interactive Systems</B>'s AS/400 and iSeries Report Downloader sends report data to a variety of formats, including Microsoft Word, Excel, and HTML. Look for it at <A href="http://www.evergreeninteractive.com/">www.evergreeninteractive.com</A>. <li><B>Chouinard & Myhre</B>'s Spoolfile EMail'r distributes spooled files by email using Client Access/400 and ActiveX technology. Download an evaluation copy at <A href="http://www.cm-inc.com/what/index.html">www.cm-inc.com/what/index.html</A>. <li><B>Net400</B>'s NetMail400 lets you integrate your iSeries applications to email anything you can print. Find it at <A href="http://www.net400.com/">www.net400.com</A>. <li><B>RJS Software Systems</B>' WinSpool/400 supports Web integration, email integration, and electronic forms integration. For more information, visit <A href="http://www.rjssoftware.com/">www.rjssoft.com</A>. <li><B>DataTrade</B>'s SpoolView suite of report management products manages a variety of storage, archival, and retrieval options, including Internet-based PCs. Order a demo at <A href="http://www.datatrade.com/">www.datatrade.com</A>. <li><B>Broderick Data Systems</B>' SpoolOrganizer/400 supports email bundling of reports, as well as Internet access and many other features. Check it out at <A href="http://www.broderickdata.com/">www.broderickdata.com</A>.</li> </ul><!----- callout content end ---></td></TR></TABLE></td></TR></TABLE><!------ callout box end ---><p align="center">-Christopher J. Devous</p> </section> <div id="disqus_thread"></div> <script id="disqus_identifier_js" type="text/javascript"> disqus_identifier = "com_content:article:3949"; </script> <script id="disqus_js" type="text/javascript"> /** * var disqus_identifier; [Optional but recommended: Define a unique identifier (e.g. post id or slug) for this thread] */ disqus_shortname = 'mcpressonline'; var disqus_config = function(){ this.language = 'en'; }; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//mcpressonline.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=mcpressonline">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dq-powered">BLOG COMMENTS POWERED BY DISQUS</a> </div> </section> <section class="row article-navigation bottom"> </section> </article> </div> <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5c63616521cd1952"></script> <!-- sh404SEF sharing buttons javascript --> <script> !function(e,t){"use strict";var a=false;a=e.navigator.share&&a;const o=true,s="location=0,resizable=yes,scrollbars=1,status=1,menubar=0,toolbar=0,personalbar=0,alwaysRaised=yes";function r(e,a){t.querySelectorAll(e).forEach(e=>{e.classList.remove(a)})}function l(r){try{const l=t.querySelector("link[rel=canonical]"),n=t.getElementsByName("description"),i={url:l?l.href:location.href,shareUrl:r.href,title:t.title||"Share",text:n.length?n[0].content:""};a?async function(t){await e.navigator.share(t)}(i):o&&i.shareUrl.startsWith("http")?function(t){let a=e.innerHeight,o=e.innerWidth,r=Math.min(750,o-40),l=Math.min(650,a-40),n=Math.floor((o-r)/2),i=Math.floor((a-l)/2),c=e.open(t.shareUrl,"wbl-social-sharer",s+",width="+r+",height="+l+",left="+n+",top="+i);c.focus&&c.focus()}(i):location.href=i.shareUrl}catch(e){console.error("sh404SEF: unable to share content: ",e)}}function n(){try{a?(e=".wbl-social-desktop",s="wbl-social-hide",t.querySelectorAll(e).forEach(e=>{e.classList.add(s)}),r(".wbl-social-mobile","wbl-social-hide")):r(".wbl-social-desktop","wbl-social-hide"),(o||a)&&t.body.addEventListener("click",e=>{let t=e.target.closest("A");t&&t.classList.contains("wbl-social-link")&&(e.preventDefault(),l(t))})}catch(e){console.error("Error setting sh404SEF sharing buttons: "+e.message)}var e,s}"loading"!=t.readyState?n():t.addEventListener("DOMContentLoaded",n)}(window,document); // sh404sefsocial.js.map</script> <!-- End of sh404SEF sharing buttons javascript --> </body> </html>