Using HP 3000 MPE/iX:\Advanced Skills Tutorial: HP 3000 MPE/iX Computer Systems > Chapter 3 Module 2: File ManagementLesson 4 Using File Equations |
|
Lesson 4 presents the following file concepts: You have worked with files that exist permanently or temporarily on disk. What about files that do not really exist, files that are not really files? These are formal files, files whose names are actually "aliases" for other files or devices.
As you have already seen, if you do a LISTFILE or LISTFILE;TEMP, you see names of actual files. What you don't see are names that serve as aliases and "point" to other files or devices. These names are defined in file equations. Enter the following command to list the file equations currently available on your system.
A file equation is something that equates a name (formal file designator) with a specific device or file. In other words, the formal file designator serves as an alias for an actual device or file. One type of syntax equates a file designator with another system, subsystem, or user defined file:
Example:
Another type of syntax equates a file designator with a device:
Example:
Here are some examples of file equations that you might see on your system. All file equations begin with the keyword, FILE:
Why should you learn about the FILE command and use file equations? For two reasons:
The process of referring to files and devices by a file designator is called backreferencing. The file designator always has an asterisk (*) in front of it for backreferencing. For example, suppose that you define a file equation with a file designator called OUTPUT. This designator points to a file where results from a program are stored. You then write a program that executes a number of calculations, stores the results in a file, and prints the contents of that file. In such a situation, you might enter this:
The program would contain a code that would do the following:
As a result, the program stores the results in FILE1 and prints the contents of FILE1, since FILE1 is pointed to by *OUTPUT. The program would not print the contents of a file called OUTPUT. The asterisk (*) in front of OUTPUT indicates that *OUTPUT is a file designator that refers to a file or device defined in a file equation. You can demonstrate the above scenario yourself by entering the following commands. (You are assumed to be in the CLASS group.)
You should see the contents of MYJOB1. If you change the file equation and reexecute the PRINT command, you see the contents of another file:
The file designator, *OUTPUT, does not change, even if the file equation does. In a program, you might wish to change the file equation to redirect output to different files or devices. For example, suppose the first time you run the program, you want the output to go to the screen. Then, the second time you run the program, you want the output to go to a file called TEMP1. Finally, the third time you run the program, you want the output to go to a file called TEMP2. Rather than editing the program each time, and changing the actual file name, you can leave the program as is and refer to *OUTPUT. Each time that you run the program, you need only enter a new FILE command to redefine the file equation. File equations last for the duration of the session, unless they are stored in a special file that goes into effect each time you log on. (You will learn about this in the UDC module.) This exercise provides hands-on experience redirecting output with file equations.
********** End of Exercise 2-4 ********** When you create file equations, you can use system-defined file designators, subsystem-defined file designators, and user-defined file designators. The system defines its own set of file designators, some of which were introduced in lesson 3 for programmers: $STDIN $STDLIST $NULL $OLDPASS $NEWPASS $OLDPASS and $NEWPASS are the system-defined temporary files generated during program compiling and linking. $NULL, $STDIN, and $STDLIST are the system-defined temporary files that are useful in file equations for redirecting input and output. System files cannot be equated to devices; they can only be equated to other file designators. Example #1a: Invalid File Equation
Example #1b: Valid File Equation
You can equate a file designator to a device only with the DEV option of a file equation: Example #2a: Invalid File Equation
Example #2b: Valid File Equation
$STDIN refers to the standard input device, which is, by default, the keyboard. $STDIN is a temporary system file, lasting only for the duration of the session. When writing programs, you can specify that the data be read from the standard input device as follows:
$STDLIST refers to the standard output device, which is by default the terminal screen. The output device can also be the line printer. When writing programs, you can specify that the data be written to the standard output device as follows:
$NULL is the system-defined file treated as an empty file ("bit bucket"). In the following example, one program reads from *INPUT and another program writes to *OUTPUT. Both INPUT and OUTPUT are file designators for $NULL. This means that one program reads from an empty file and receives an end-of-file marker. The other program writes to *OUTPUT, and no physical output is actually produced (it writes to no device or file).
To illustrate this concept, use the FILE command to define a file designator called ERROR that refers to $NULL:
Now compile and link the HIC program as shown below, and specify *ERROR as the error listing file. Normally the error listing would appear on the screen. Only this time, because the error listing has been written to *ERROR ($NULL), it has disappeared:
The resulting executable program is HICP. The error listing (*ERROR) does not exist because it was written to $NULL ("bit bucket"). You can create your own file equations using a file designator of your choice and an existing device or file of your choice. For example, when you run HP Desk (Hewlett-Packard's electronic mail facility) and enter PRINT, HP Desk assumes that you wish your mail messages printed on MAILPRNT (line printer using special environment file). This is because the following file equation already exists: FILE MAILPRNT;DEV=LP
You could further edit the equation so that the mail messages print in a particular type style. Do you remember where type style information is stored? Yes, it is stored in the environment file. So, you must change the ENV part of the file equation. Of course you would need that environment file on your system to print the messages in that type style.
Now, suppose that you also wish to run a program that reads from and writes to different files; however, you wish to refer to those files, generically, as FILEIN and FILEOUT within the program: File Equation #1:
File Equation #2:
If you no longer want a file equation to be in effect, you can use the RESET command to cancel it. The syntax for this command is very simple:
|