24
Sun, Nov
1 New Articles

Working with Temporary Files

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

Working with temporary files may confuse some AS/400 programmers. Suppose you run the Display Object Description (DSPOBJD) command, directing output to an outfile, because you need to process a series of objects. Where do you put the outfile (a temporary file), and what do you call it? This article addresses these questions.

Any IBM-supplied command that produces an outfile uses a model file. Model files are empty physical files (they have no members) that IBM has placed in library QSYS. Model files have a rather elaborate record layout, full of useful fields that you can put to immediate use. For instance, the DSPOBJD command uses a model file named QADSPOBJ, which has, among its many fields, the date the object was created, its size, the name of its owner, the date of last use, and the date it was last backed up. (It's easy to determine the name of the model file: Prompt for the command, move the cursor to the OUTFILE parameter, and press the Help key.)

You don't have to do anything special to use all these fields. Whenever you run DSPOBJD with output to an outfile, OS/400 automatically creates an empty file using QADSPOBJ as a model and then populates the file with valid information. The problem is, rather, how to use the file. The problem is that temporary files are created, more often than not, in library QTEMP. Due to QTEMP's nature, files in QTEMP are ephemeral. Consider the following scenario:

Imagine you are writing code for a new application that uses a list of objects created with DSPOBJD. In a CL program, you code a DSPOBJD command to write an outfile named OBJECTSinQTEMP,andthenyoucallanRPGprogramtoprocessthatfile.IntheRPG program, you code OBJECTS in the F-spec and use external file definition. Yet the RPG program fails to compile, because there's no OBJECTS file anywhere-why should there be? You haven't yet run DSPOBJD to create OBJECTS.

Aha! You decide, then, to use the Override with Database File (OVRDBF) command from the command line before compiling the RPG program, like this:

OVRDBF +

FILE(OBJECTS) +

TOFILE(QADSPOBJ)

Then, you submit the compile to batch. The compilation fails again, because the file override applies to the interactive job you're running at your display station, not to the batch job you're submitting therefrom. You have to compile the RPG program interactively, and that's a sure way to get yourself in trouble with other programmers, your boss, and (worst of all) the end users.

To avoid these problems, it's best that you give the outfile the same name as the model file- QADSPOBJ. That done, you can compile the RPG program without trouble, because the compiler finds QADSPOBJ in QSYS (it doesn't matter to the compiler or the program whether the file it finds is empty or not).

One question I haven't addressed yet is where to put the outfile. Do yourself a favor and don't place it in (a) any IBM-supplied library, such as QGPL or QUSRSYS, or (b) any user-created libraries. The reason for not placing the temporary file in user libraries is that such libraries are permanent in nature. If you create an outfile in, say, QGPL, the outfile remains there after completion of your job. Worse, if someone else wants to run the same application at the same time, the second job's outfile wipes out the data from the first one, perhaps before the first job has a chance to use the data. Or you may run into object lock contention, and so on. It's a headache you can avoid by placing your outfiles in QTEMP. QTEMP is especially useful for this type of application:

o It creates a private file that only one job can process. Two or more users may be running the same application, all creating the same file in QTEMP, and no conflict is created. That's because OS/400 maintains a separate QTEMP library for each job, whether it's interactive or batch. Using QTEMP, therefore, eliminates conflicts between jobs.

o If the job aborts for whatever reason, the temporary file is immediately deleted; the system doesn't keep leftover junk files that might accumulate and waste disk space.

Logs and accounting journals (not AS/400 journals!) require a different kind of temporary file. By definition, a log or a journal contains data that is relevant only for a certain period of time. Let's see how we can address this issue.

The problem arises when you need to accumulate data across job boundaries. For instance, suppose you need to keep a daily log of cash transactions and you want to keep a week's worth of them. QTEMP is out of the picture in a case such as this, because several users might want to record cash transactions, but QTEMP is private to each job and is destroyed when the user signs off. Clearly, you need to store the cash transactions in a "regular" user library. Let's say you have a library named CASHMGT and you decide to put the cash transaction log there.

You could design the cash log so it includes a date field to store the date each transaction was logged. The problem here is one of maintenance-on the eighth day, you'll have to rid the log of the cash transactions logged on the first day. This means writing a program to delete those records (or using SQL or a Query Management query) and reorganizing the file to reclaim the space the deleted records occupied.

It's easier to use separate members instead. Each day, you could add a member to the cash log and store the transactions in that member. When you need to clean up old records, all you'll have to do is remove the member using a single command-Remove Member (RMVM). For

simplicity's sake, give each member a name that can be derived automatically. For example, they could be named CASHmmdd, where mmdd represents the month and day of the system date. This way, you can retrieve system values QMONTH and QDAY prior to writing a cash transaction, build the name of the member, and write records to this unique member.

There are three problems with using separate members, however:

o You have to use the OVRDBF command to point to the correct member within the file. If you neglect to do this, transactions will be logged to the first member the system finds, which is probably wrong.

o If you need to write a program that reads cash transactions for more than one day, your program needs to read records from more than one member. But a high-level language's (HLL's) view of a file reaches the end-of-file condition (*INLR in RPG) when the current member ends. To solve the problem, use OVRDBF before calling the HLL program, making sure to specify MBR(*ALL). Your HLL program won't reach end-of-file until all members have been processed.

o If you need a logical view of the cash transactions, the logical file member may have to span more than one physical file member-and the limit is 32 members.

You have to weigh the pros and cons of each approach to see which one is best for you and your installation. For example, if you run a 24/7 installation (i.e., one that works 24 hours a day, seven days a week), you cannot employ a method that requires using the Reorganize Physical File Member (RGZPFM) command, since this command attempts to place an exclusive lock on the member. Such a lock may be impossible to obtain if someone is writing records to the cash log, which would make RGZPFM fail. Or RGZPFM may obtain an exclusive lock on the member, only to prevent a user from logging cash transactions at the time they happened-which could be crucial if the time is two minutes before midnight.

Ernie Malaga is a senior technical editor for Midrange Computing. He may be reached by fax at 305-387-8263 or by email at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

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: