19
Fri, Apr
5 New Articles

How and Why to Copy Spooled Files

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

Copying spooled files can be easily accomplished using standard CL. It has its advantages and limitations. Learn how, when and why to use this technique.

Spooled files do not reside on the AS/400 as objects; therefore, they can't be manipulated or even saved to offline storage like other objects. However, spooled files can be copied to and from physical files, providing an indirect path to manipulate them.

Copying a spooled file to a physical file and back to a spooled file again can be easily accomplished using a few standard CL commands. This technique is not revolutionary. In fact, it has been around for a long time. Many utilities written over the years have been built around this concept (e.g., the SAVSPLF and RSTSPLF commands published in the October 1991 issue of MC).

In this article, I want to do more than just explain what steps you need to perform to accomplish this task. I want to give you some reasons for using this technique, as well as some warnings about when not to use it.

Possible Uses

A typical reason for wanting to copy a spooled file is for archival purposes. When you save an output queue using one of the save commands (e.g., SAVLIB, SAVOBJ), any spooled files within that output queue are not saved. By copying the spooled file to a physical file, you can then save the file to tape or diskette.

Subsequently, if you find that you need to print the spooled file but it is no longer on the system, you can restore the file, copy it back to a spooled file again and print it.

For your typical, text-based spooled files such as standard RPG output or system commands which provide OUTPUT(*PRINT), this technique works well. But, if a spooled file contains elements like graphics, barcodes, special fonts or Intelligent Printer Data Stream (IPDS) data, they would be lost when a spooled file is copied. For a better technique to handle these types of spooled files, see "Beyond CPYSPLF-Saving Everything in a Spooled File" in this issue.

Another use for copying a spooled file is the ability to change its attributes. Most attributes of a spooled file can be changed using the Change Spooled File Attributes (CHGSPLFA) command. However, you might want to modify a few attributes (most commonly, characters per inch) that the CHGSPLFA command cannot control.

For example, suppose you ran a 12-hour job which produced a 132-column report at 10 characters per inch. This report would print perfectly on 11" x 17" computer paper, but what if you need to print it on 8-1/2" x 11" paper? You could rerun the 12-hour job. Or, you could copy the spooled file to a physical file and then copy it back to a spooled file at 15 characters per inch in a matter of minutes.

Yet another reason for wanting to copy a spooled file is to modify the spooled file's contents. When a spooled file has been copied to a physical file, you can change its contents using DFU or any file utility. Then the contents of the physical file can be copied back to a spooled file again with any changes that have been made still in effect.

Obviously, there are some security issues to be dealt with here. For example, suppose a spooled file contains payroll checks. An employee with access to the spooled file who knows this technique could conceivably change the dollar amount on his paycheck. Therefore, you need to be sure you have adequate security measures in place. For some ideas on how to secure spooled files, see "Security Patrol" in this issue.

However, there are legitimate reasons for wanting to modify a spooled file. A spooled file that needs minor corrections or that you want to use for documentation is a good example. (There is a utility in QUSRTOOL called Copy Spooled File to Text Member [CPYSPLTXT] which allows you to perform these functions.) A limitation to copying a spooled file is that it doesn't save the spooled file attributes. This shouldn't be a problem for standard reports; but not having the attributes for special reports may prevent you from restoring them with the same attributes. There are ways to get around this, as I will explain later.

Another limitation to copying a spooled file is that it allows only one spooled file to be copied at a time. For copying and restoring an entire OUTQ at one time, you might consider using the Copy from Output Queue (CPYFRMOUTQ) and Copy to Output Queue (CPYTOOUTQ) commands from the QUSRTOOL library. Both of these commands are discussed in this month's "From the Toolbox."

Here's How to Do It

Before you copy a spooled file, you need to determine how many columns it contains. Use the Work with Spooled File Attributes (WRKSPLFA) command to find out the page width. You then need to create a physical file to contain the spooled file data. Create the physical-file record length one byte larger than the page width. The reason for this is that the first character of the physical file gets loaded with a First Character Forms Control (FCFC) character. These FCFC characters control the line spacing and page breaks of the spooled file. The rest of the positions of the physical file get loaded with the actual spooled file data.

It is a good idea to specify the name of the printer file which was used to create the spooled file in the TEXT parameter of the Create Physical File (CRTPF) command. That way, you will know what printer file to use when you want to obtain the attributes to recreate the spooled file. You can copy the spooled file to the physical file using the Copy Spooled File (CPYSPLF) command. Be sure to use *FCFC for the Control Character (CTLCHAR) parameter to specify that you want the FCFC character to be placed in the first position of the physical file. 1 contains an example.

It is a good idea to specify the name of the printer file which was used to create the spooled file in the TEXT parameter of the Create Physical File (CRTPF) command. That way, you will know what printer file to use when you want to obtain the attributes to recreate the spooled file. You can copy the spooled file to the physical file using the Copy Spooled File (CPYSPLF) command. Be sure to use *FCFC for the Control Character (CTLCHAR) parameter to specify that you want the FCFC character to be placed in the first position of the physical file. Figure 1 contains an example.

Recreating a Spooled File

Once you have copied a spooled file to a physical file, you can save it or modify the data in the physical file. At some point, you may want to copy the physical file back to a spooled file.

To do this, you basically use the Copy File (CPYF) command to copy the physical file to a printer file. However, there are two variations in the way you do this.

The method used depends on what type of printer file (program-described or externally described) you used to create the spooled file and if any overrides were in effect at the time the spool file was created.

1. If the printer file used to create the original spooled file is program- described and no overrides were used when the spooled file was created, use the original printer file name in the TOFILE parameter of the CPYF command. If any attributes were overridden at the time the spooled file was created, you must execute an Override Printer file (OVRPRTF) command to change the attributes of the printer file to match the values used at spooled-file creation time.

2. For spooled files created with externally described printer files, the method is a little different. The TOFILE parameter of CPYF cannot contain an externally described printer file. Therefore, instead of using the original printer file name in the TOFILE parameter, use a program-described printer file that closely matches the attributes of the report (for standard reports, QPRINT or QSYSPRT should work). Match the attributes from the program-described file to the attributes from the external printer file, if there are any mismatches, by using the Override Printer File (OVRPRTF) command prior to performing the copy. Also, override any parameters that may have been overridden at the time the spooled file was created.

The CPYF command will translate the FCFC character to the correct line spacing and page breaks for the spooled file if the CTLCHAR attribute of the printer file is *FCFC. This can be accomplished by specifying CTLCHAR(*FCFC) on either the Create Printer File (CRTPRTF) command, the Change Printer File (CHGPRTF) command or the Override Printer File (OVRPRTF) command.

Use the Display File Description (DSPFD) command on the printer file to determine the current setting of the CTLCHAR parameter. Since *NONE is the default parameter on the CRTPRTF and CHGPRTF commands, you will most likely need to execute the OVRPRTF command.

After the CPYF, you will have a spooled file in the OUTQ associated with your job. The lines of code in 2 illustrate how to recreate a spooled file.

After the CPYF, you will have a spooled file in the OUTQ associated with your job. The lines of code in Figure 2 illustrate how to recreate a spooled file.

Some Examples

Let's take a look at an example of how you can use this technique to archive your spooled files to tape or diskette. To save a spooled file, first copy it to a physical file and then save it. To get the spooled file back, restore it and then copy it back to a physical file. The commands would look something like those in 3.

Let's take a look at an example of how you can use this technique to archive your spooled files to tape or diskette. To save a spooled file, first copy it to a physical file and then save it. To get the spooled file back, restore it and then copy it back to a physical file. The commands would look something like those in Figure 3.

In order to change the attributes of a spooled file, you need to copy the spooled file to a physical file. Copy the physical file to a printer file and specify the new attributes using OVRPRTF. The commands for this example appear in 4.

In order to change the attributes of a spooled file, you need to copy the spooled file to a physical file. Copy the physical file to a printer file and specify the new attributes using OVRPRTF. The commands for this example appear in Figure 4.

To modify a spooled file, copy it to a physical file just as before. Then modify the data in the physical file; and when you copy the physical file to the printer file, the newly recreated spooled file will contain the changes you made. 5 contains commands you would use in this case.

To modify a spooled file, copy it to a physical file just as before. Then modify the data in the physical file; and when you copy the physical file to the printer file, the newly recreated spooled file will contain the changes you made. Figure 5 contains commands you would use in this case.

To Sum It Up

As you can see by the techniques outlined in this article, copying spooled file data to and from physical files only takes a few CL commands. It allows you to perform various tasks on spooled files such as archiving, changing attributes and modifying contents. However, it does have limitations in that it won't work for all spooled files.

Now that you know under what conditions this technique can be used, you can begin to take advantage of its capabilities while avoiding its limitations.

Robin Klima is a senior technical editor at Midrange Computing.


How and Why to Copy Spooled Files

Figure 1 Copy from Spooled File

 /* COPY A SPOOLED FILE TO A PHYSICAL FILE */ CRTPF FILE(XXX/SPOOL) RCDLEN(133) TEXT('QPRINT') CPYSPLF FILE(QPRINT) TOFILE(XXX/SPOOL) + JOB(number/user/job) CTLCHAR(*FCFC) 
How and Why to Copy Spooled Files

Figure 2 Copy to Spooled File

 /* COPY PHYSICAL FILE BACK TO A SPOOLED FILE */ OVRPRTF FILE(QPRINT) CTLCHAR(*FCFC) CPYF FROMFILE(XXX/SPOOL) TOFILE(QPRINT) 
How and Why to Copy Spooled Files

Figure 3 Spooled File Save/Restore

 /* COPY A SPOOLED FILE TO A PHYSICAL FILE */ CRTPF FILE(XXX/SPOOL) RCDLEN(133) TEXT('QPRINT') CPYSPLF FILE(QPRINT) TOFILE(XXX/SPOOL) + JOB(number/user/job) CTLCHAR(*FCFC) /* SAVE THE PHYSICAL FILE TO TAPE */ SAVOBJ OBJ(SPOOL) LIB(XXX) DEV(TAP01) OBJTYPE(*FILE) . . . /* RESTORE THE PHYSICAL FILE FROM TAPE */ RSTOBJ OBJ(SPOOL) SAVLIB(XXX) DEV(TAP01) OBJTYPE(*FILE) /* COPY PHYSICAL FILE BACK TO A SPOOLED FILE */ OVRPRTF FILE(QPRINT) CTLCHAR(*FCFC) CPYF FROMFILE(XXX/SPOOL) TOFILE(QPRINT) 
How and Why to Copy Spooled Files

Figure 4 Change a Spooled File's Attribute (CPI)

 /* COPY A SPOOLED FILE TO A PHYSICAL FILE */ CRTPF FILE(XXX/SPOOL) RCDLEN(133) TEXT('QPRINT') CPYSPLF FILE(QPRINT) TOFILE(XXX/SPOOL) + JOB(number/user/job) CTLCHAR(*FCFC) /* COPY PHYSICAL FILE BACK TO A SPOOLED FILE WITH NEW ATTRIBUTES */ OVRPRTF FILE(QPRINT) CPI(15) CTLCHAR(*FCFC) CPYF FROMFILE(XXX/SPOOL) TOFILE(QPRINT) 
How and Why to Copy Spooled Files

Figure 5 Modify a Spooled File's Contents

 /* COPY A SPOOLED FILE TO A PHYSICAL FILE */ CRTPF FILE(XXX/SPOOL) RCDLEN(133) TEXT('QPRINT') CPYSPLF FILE(QPRINT) TOFILE(XXX/SPOOL) + JOB(number/user/job) CTLCHAR(*FCFC) /* MODIFY THE SPOOLED FILE DATA IN THE PHYSICAL FILE */ UPDDTA FILE(XXX/SPOOL) /* COPY PHYSICAL FILE BACK TO A SPOOLED FILE */ OVRPRTF FILE(QPRINT) CTLCHAR(*FCFC) CPYF FROMFILE(XXX/SPOOL) TOFILE(QPRINT) 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: