←Part 14  Part 16→

The HP 3000 — For Complete Novices
Part 15: The Life Expectancy Of A File


By George Stachnik

We've spent a lot of time in the last two articles looking at ways of using MPE commands to manage files. We've learned how to create files on your HP 3000, and how to control the sizes of the files that we create. We've seen how to assign them certain characteristics such as the record size and format. We've also seen some examples of how to use file equations to assign temporary aliases to files, so that we can be flexible in the way application programs open the files and access them.

This month, we're going to begin looking at how to get rid of files. At first glance, it doesn't sound like a terribly complex topic, but in fact MPE gives you at least three diffferent ways of deleting the files that you create:

• Files can be deleted manually using a :PURGE command.

• Files can be deleted automatically when you logoff the system.

• And finally, files can be deleted automatically when the process that created them terminates.

One of the more irksome parts of managing a large server, regardless of whether it's a mainframe, an IBM AS/400, an HP 9000 UNIX-based server, an NT (or NetWare)-based HP NetServer, or an MPE-based HP 3000, is the ongoing management your disk space. No matter how much disk storage you buy, it seems to have a way of becoming clogged up with useless old files that you don't need any longer. The key to preventing this from happening is to make certain that files that you won't need again are deleted automatically. But before we proceed to the automatic deletion of files, let's begin by reviewing what we've learned about deleting files manually.

As we've learned in earlier articles, the simplest way to create a file on the HP 3000 is with a :BUILD command. Perhaps the simplest example is:

:BUILD MYFILE

This command creates a file called MYFILE. Because we haven't specified any parameters but the file name, MPE creates the file with default characteristics. It will be a binary file, with fixed length records that are 128 words (256 bytes) long. It will be able to hold no more than 1023 records. These are some of the default file characteristics that we've studied in earlier articles in this series. But there's another default file characteristic that we haven't studied. By default, this file will be a permanent file.

Permanent Files

Permanent files are used for long term data storage on the HP 3000. When you create a permanent file, it will remain on your HP 3000 permanently, or at least until you take action to delete it. If you use an application program to load a permanent file with data, MPE will keep that data safe and sound on your HP 3000 until you (or some other user) specifically tell MPE to delete the file.

The most straightforward way to delete a permanent file is using an MPE :PURGE command. Here's an example of the command that you'd use to delete the file called "MYFILE".

:PURGE MYFILE

Alternatives to :BUILD and :PURGE

The :BUILD and :PURGE commands can be used to create and delete permanent files. Another way is through the use of file commands, together with application programs. Last month's article showed how file equations are used to establish a linkage between the "formal file designator" specified by an application program, and the filename used by MPE. Now we're going to see how you can enable your application programs to create and delete files "on the fly".

For example – suppose you had an application program called MYPROG that was designed and written to write data to an output file called "OUTFILE". When you run such a program, it will open a file called :OUTFILE. By default, the program will expect OUTFILE to be an existing file. If such a file does not exist, the program will probably abort (although there are programming techniques for trapping the error that we won't be discussing in these articles).

One way to make sure that MYPROG executes successfully is to always make sure that OUTFILE exists befor you run it. You might do this by executing a series of MPE commands, like this:

:BUILD OUTFILE;REC-=80,,F,ASCII;DISC=10000
:RUN MYPROG

The first command creates the file (assigning it the characteristics that MYPROG expects OUTFILE to have), and the second command runs the program. But there's a downside to doing things this way.

Suppose you only run MYPROG once a year. If you create OUTFILE as a permanent file, it will be sitting around the other 364 days of the year, taking up disk space unnecessarily. Of course, in this case, OUTFILE is only 10000 records long. But if this were a much larger file, (or if we were talking about a collection of tens or even hundreds of files) we would want to look into a better way to go.

Instead of pre-creating the output file manually using the :BUILD command, we can let MYPROG create it's own output file. That way, we can put off tying up the disk space used by OUTFILE until the last possible minute. The file simply won't exist until MYPROG needs it. To do this, we're going to issue a file command that establishes the characteristics that we want OUTFILE to have. Here's what it might look like:

:FILE OUTFILE,NEW;REC=80,,F,ASCII;DISC=10000;SAVE

We're going to explore this file equation carefully, one parameter at a time. The first and most important thing to understand about this command is that it does not reserve any disk space, nor does it create a file (at least not yet). All that this file command does is to register a set of specifications for a file. In order to actually use the spec's to create the file, you'd have to run a program that opens a file using the formal file designator that you specified in the file equation (in this case, OUTFILE). This file command effectively tells your HP 3000: "if any program comes along and tries to open a file called MYFILE, be sure you use these spec's".

Keep in mind that file commands are not permanent. They are reset automatically when you logoff the system. In order for the above file command to work, it must be issued before you run the program that will create OUTFILE, and it must issued during the same job or session that runs the program.

Let's look at the specs, one at a time.

First of all, the file equation begins by naming the formal file designator, OUTFILE. This tells MPE that if a program tries to open a file using this name, then it should consult the specifications defined in the file command. So a program that uses any other file name won't be affected.

The formal file designator is followed by a comma (,) and the word NEW. The NEW parameter tells MPE that when a program tries to open a file called OUTFILE, it is to create a brand new file called OUTFILE. Remembr, OUTFILE won't get created until a program (in this case, MYPROG) tries to open a file by that name.

The next couple of parameters in the file command should look familiar by now. The "REC=" and "DISC=" keywords are identical to the ones that we saw being used by the :BUILD command in the last couple of articles in this series. Keep in mind, that by specifying these parameters in a file command, we are not creating any records or reserving any disk space. We are just telling MPE, "if an application program opens a file named OUTFILE, then don't look for an existing file. Instead create a NEW file, and use the file characterstics that I've specified here."

Finally, the file command has one new parameter: ";SAVE". This parameter is called the closing disposition. It tells MPE that when the application program closes the file, it should save OUTFILE as a permanent file.

We've just seen two new parameters to the file command: ",NEW" and ";SAVE". If you omit the ",NEW" parameter from a file command, then MPE will assume the default value of ",OLD". In other words, if you leave the ,NEW off of your file command, then when MYPROG tries to open OUTFILE, it will try to open an OLD (or existing) file by that name. If no file called OUTFILE exists, then the application program will probably fail. The only two options for this positional parameter are ,NEW or ,OLD (with OLD being the default).

In the example, we specified a closing disposition of ;SAVE. The closing disposition can have three values: ;SAVE, ;KEEP, or ;DELETE. Specifying ;SAVE means that this file should be made permanent when it's closed by the program that created it.

You might be wondering what would happen if you specified a closing disposition of ;SAVE for a file named OUTFILE if a file by that name already exists. For example – suppose that you've used the :BUILD command to create a permanent file called ;OUTFILE. Then suppose that you issue a file command such as the one we've been discussing, and ran a program that opens a ,NEW file that is also called OUTFILE.

It may surprise you to learn that this won't cause a problem – at least not yet. The application program will open OUTFILE and create a NEW file by that name. The NEW file called OUTFILE will exist side by side with the existing permanent file with the same name. There's no conflict because the NEW file isn't a permanent file yet. You can only have one permanent file called OUTFILE in your logon group. But the NEW file that you've created isn't a permanent file – it's a NEW file. When the program writes data to OUTFILE, it will be writing to the NEW file that it created.

But the story will take an ugly turn when MYPROG closes its NEW file. If you specified a closing disposition of ;SAVE, then MPE will try to save the NEW version of OUTFILE as a permanent file, and discover that there's already a file by that name. The application program will probably fail at that point, and the data that it wrote to OUTFILE will be lost. So remember, if you're going to use a file command to create a NEW permanent file, you must make sure that there won't already be a file in place with that same name.

You can also specify a closing disposition of ;DELETE. This effectively says, "when the program closes this file, there's no need to keep it around. Just delete it. A closing disposition of delete is useful for so-called "scratch pad" files. For example, large sorts often use scratch pad files for temporary storage. When the sort is finished, they can be deleted. The default closing disposition for NEW files is DELETE. So any file that is created by a program will automatically be deleted when the program closes the file, (unless you tell MPE to do something different in the file command – such as ;SAVEing the file).

The default closing disposition for permanent files is ;KEEP. So by default, if your program opens up a permanent file, the file will be kept on your system when the program closes the file.

Incidentally, you might be wondering what happens if your program doesn't close the file. If your application programmers are sloppy, and fail to code the instructions for closing files, then MPE automatically closes any files that are left open when the program terminates. Similarly, if a program aborts or terminates abnormally, any files that were left open at the time of the error will be closed automatically by MPE.

Temporary Files

The :LISTFILE command displays a list of the names of the permanent files on your system. For example: take a look at the following command.

:LISTFILE

The command shown above will display the names of the permanent files in your logon group. We've just learned about a new kind of file called a NEW file. If a file is created "on the fly" by an application program, then it is not a permanent file. So its name will not show up in a :LISTFILE command's output unless and until it is SAVEd as a permanent file when the program closes it.

Figure 1: Temporary Files

Now that you understand permanent files and NEW files a little better, we're going to explore a third class of files called "temporary files." Figure 1 shows the results of a simple little experiment that you can try. Type the following commands.

:build myfile;temp
:listfile ,2

This BUILD command creates a file called MYFILE, but designates it as a "temporary" file. Temporary files are like permanent files in every way but two –

1. When you logoff the system, any temporary files that you've created will be automatcially purged.
2. By default, they don't show up in the output of a :LISTFILE command.

Most operating systems have some kind of concept of "temporary" files. For example, on UNIX systems, any file created in the /tmp directory is designated as a temporary file. But there's nothing special about the /tmp directory itself. What makes files in /tmp temporary is the fact that the system administrator will periodically delete anything that's left laying around in that directory. On MPE, temporary files can be created in any directory (group or account) on the system – and they will be deleted automatically when the creator logs off. The system administrator need not take any action.

If you tried the experiment above, you probably noticed that MYFILE did not show up in the :output of the LISTFILE command. That's because :LISTFILE only displays information about permanent files, at least by default. But try issuing the :following command (as shown in figure 1):

:LISTFTEMP

This time you'll see the temporary file that you created. It's worth noting that your application programs don't have to be modified in order to take advantage of temporary files. For example, figure 2 shows an example of FCOPY being used to write some data to a temporary file called TEMPFILE. The example in figure 2 shows exactly the same file equations and commands being used that we showed you how to use last month, when we introduced you to FCOPY.

Figure 2: FCOPY with Temporary Files

Figure 3 shows an example of how you might use :LISTFTEMP to display the names of your temporary files. At the bottom of figure 3, the :PRINT command is being used to display the contents of the temporary file. If TEMPFILE had been a permanent file, you would have displayed its contents using the PRINT command in exactly the same way.

Figure 3: FCOPY with Temporary Files

Finally, figure 4 shows what happens if you should change your mind. What if you want to change a temporary file into a permanent file, so that it won't be deleted when you logoff? No problem, the MPE command to do this is :SAVE. For example, in figure 4, we've created a temporary file called TEMPFILE. But we've decided to make the file permanent by issuing the command:

:SAVE TEMPFILE

Figure 4: Changing Temporary Files into Permanent Files

The bottom of figure 4 shows that TEMPFILE now shows up in a :LISTFILE command output. It's a permanent file, and that data that it contains will now be available to future sessions.

  ←Part 14  Part 16→
     [3khat]3kRanger   [3khat]3kMail   Updated