Lesson 4 Using File Equations [ Using the 900 Series HP 3000: Advanced Skills Module 2: File Management ] MPE/iX 5.0 Documentation
Using the 900 Series HP 3000: Advanced Skills Module 2: File Management
Lesson 4 Using File Equations
Introduction
Lesson 4 presents the following file concepts:
* file equations
* device files
* formal file designators
* "backreferencing" file designators
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.
NOTE Before you read any further, make sure that you are logged
on as USERx in the CLASS group of the ACCTx account
(USERx.ACCTx,CLASS--where X is the student number assigned to you
by your system manager or course manager).
Writing file equations
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.
LISTEQ
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:
FILE filedesignator=sysfilename;
REC=recsize,blkfactor,rectype,filedatatype
Example:
FILE IN=$STDIN
FILE OUTPUT=TESTFILE;REC=-80,,F,ASCII
Another type of syntax equates a file designator with a device:
FILE filedesignator;DEV=device;ENV=environment_file
Example:
FILE MAILPRNT;DEV=LP;ENV=ELITE.HPENV.SYS
NOTE An environment file (ENV) is a special file that contains basic
information about page layout and type style.
Figure 2-7. File Equations
Here are some examples of file equations that you might see on your
system. All file equations begin with the keyword, FILE:
a. FILE IN=$STDIN
b. FILE OUT=$STDLIST
c. FILE OUTPUT=TESTFILE;REC=-80,,F,ASCII
d. FILE MAILPRNT;DEV=LP;ENV=ELITE.HPENV.SYS
e. FILE T;DEV=TAPE
--------------------------------------------------------------------------------------------
| |
| Q2-10 According to the syntax, in the first file equation in the example (a), IN |
| is actually an alias for $STDIN. What is $STDIN? |
| |
| |
| Q2-11 In the OUT equation (b), OUT is actually the alias for what? |
| |
| |
| Q2-12 The MAILPRNT equation (d) is used to print HP Desk messages. What device |
| prints these messages? |
| |
| |
--------------------------------------------------------------------------------------------
Benefits of the FILE command
Why should you learn about the FILE command and use file equations? For
two reasons:
* File equations let you define device files that treat a peripheral
device (line printer, laser printer, or tape drive) as though it
were a file.
* File equations also let you define formal files that reference a
temporary or permanent file by a generic name, even though the
actual file name may change. Formal files also give you a short
name to use when referencing a lengthy file description.
Backreferencing
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:
FILE OUTPUT=FILE1
The program would contain a code that would do the following:
write results to *OUTPUT
PRINT *OUTPUT
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.)
FILE OUTPUT=MYJOB1
PRINT *OUTPUT
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:
FILE OUTPUT=JOB2
PRINT *OUTPUT
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.)
Figure 2-8. Backreferencing File Equations
Teaching exercise 2-4:redirecting output with file equations.
This exercise provides hands-on experience redirecting output with file
equations.
1. Create a file equation for a file designator called OUTPUT. Enter
this file equation:
FILE OUTPUT=$STDLIST
This should direct the output to the standard output device, your
terminal screen, whenever you refer to *OUTPUT.
2. Print the contents of the JOB1 file by using the PRINT command
with its OUT option to direct the contents to *OUTPUT:
PRINT JOB1;OUT=*OUTPUT
Where does the output appear? Right. On your terminal screen.
3. Now change the file equation so that the output is redirected to a
file called TEMP1.
FILE OUTPUT=TEMP1
4. Enter the PRINT command again, using the *OUTPUT designator once
more:
PRINT JOB1;OUT=*OUTPUT
Does the formatted output appear on your screen? It shouldn't.
Instead, it should appear in the TEMP1 file. Use the PRINT
command (without any options) to view this file:
PRINT TEMP1
5. Lastly, change the file equation again so that the output is
redirected to another file, TEMP2. Enter the PRINT command once
more, using the same *OUTPUT designator:
PRINT JOB1;OUT=*OUTPUT
6. The output from the PRINT command is directed to *OUTPUT, which
actually refers to TEMP2, the file specified in the file equation.
Take a look at TEMP2 by using the PRINT command again:
PRINT TEMP2
You never changed the PRINT JOB1;OUT=*OUTPUT command; yet, you
were able to send the output of the PRINT command to different
destinations. All that you changed was the file equation that
defined OUTPUT. The formatted output was redirected each time you
changed the equation.
********** End of Exercise 2-4 **********
System-Defined designators
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
Figure 2-9. System-Defined File Designators
$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
FILE OUTPUT;DEV=$STDLIST
PRINT MYFILE1;OUT=*OUTPUT
Example #1b: Valid File Equation
FILE OUTPUT=$STDLIST
PRINT MYFILE1;OUT=*OUTPUT
You can equate a file designator to a device only with the DEV option of
a file equation:
Example #2a: Invalid File Equation
FILE OUTPUT=LP
PRINT MYFILE1;OUT=*OUTPUT
Example #2b: Valid File Equation
FILE OUTPUT;DEV=LP
PRINT MYFILE;OUT=*OUTPUT
$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:
FILE TERM=$STDIN
.
.
.
read from *TERM
$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:
FILE OUTLIST=$STDLIST
.
.
.
write to *OUTLIST
$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).
FILE INPUT=$NULL
.
.
.
read from *INPUT
FILE OUTPUT=$NULL
.
.
.
write to *OUTPUT
To illustrate this concept, use the FILE command to define a file
designator called ERROR that refers to $NULL:
FILE ERROR=$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:
CCXLLK HIC,HICP,*ERROR
The resulting executable program is HICP. The error listing (*ERROR) does
not exist because it was written to $NULL ("bit bucket").
User-defined files
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
--------------------------------------------------------------------------------------------
| |
| Q2-13 How might you change the file equation to redirect HP Desk messages to the |
| terminal screen? How might you change the file equation to redirect HP Desk |
| messages to the laser printer (designated as LP for this question)? |
| |
| |
--------------------------------------------------------------------------------------------
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.
FILE MAILPRNT;DEV=LP;ENV=ELITE.PUB.SYS
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 FILEIN=MYFILEA;REC=-80,,F,ASCII
File Equation #2:
FILE FILEOUT=MYFILEB;REC=-80,,F,ASCII
--------------------------------------------------------------------------------------------
| |
| Q2-14 According to the first file equation, what is the name of the actual file |
| associated with FILEIN? What are its characteristics? |
| |
| File name: |
| Record size: |
| Blocking factor: |
| Record type: |
| File type: |
| |
| Q2-15 According to the second file equation, what is the name of the actual file |
| associated with FILEOUT? What are its characteristics? |
| |
| File name: |
| Record size: |
| Blocking factor: |
| Record type: |
| File type: |
| |
--------------------------------------------------------------------------------------------
Clearing file equations
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:
RESET filedesignator
--------------------------------------------------------------------------------------------
| |
| Q2-16 If you no longer want the FILEIN or FILEOUT equations to be in effect, what |
| do you do? |
| |
| |
| |
| |
| |
| |
--------------------------------------------------------------------------------------------
Be Careful Do not enter RESET @ RETURN unless you want to cancel all of
the file equations in the current session or job.
Exercise 2-5: creating and using file equations.
1. Make sure that you are logged on as USERx.ACCTx, CLASS.
2. Enter the command to list all file equations:
You may see these equations:
FILE IN=$STDIN
FILE OUT=$STDLIST
FILE OUTPUT=TEMP2
FILE MAILPRNT;DEV=LP;ENV=ELITE.HPENV.SYS
FILE ERROR=$NULL
3. Assume that a program reads from *IN and writes to *OUT. Modify
each file equation as follows:
a. Change the following OUT file equation so that output goes
to the terminal instead of to the FILE2 file (as shown
below):
FILE OUT=FILE2;REC=-80,,F,ASCII
b. Change the following file IN equation so that input is read
from the FILE1 file, instead of from the terminal (as shown
below):
FILE IN=$STDIN
4. Identify each piece of the file equations (assume that LP is a
line printer and that PP is a laser printer):
a. FILE OUTPUT;DEV=LP
What is the name of the file designator?
What device does it refer to?
b. FILE FORMAT;DEV=LP;ENV=PICA.HPENV.SYS
What is the name of the file designator?
What device does it refer to?
What is the environment file?
What does this file equation do?
c. FILE INPUT=MYFILE1;REC=-80,,F,ASCII
What is the name of the file designator?
What file does it refer to?
What happens if a program reads from *INPUT?
What size records are in the actual file?
d. FILE OUTPUT=$NULL
What is the name of the file designator?
What device or file does *OUTPUT refer to?
What happens if you write to *OUTPUT?
5. According to the following file equations, what happens when the
specified commands are entered?
a. FILE MAILPRNT;DEV=LP
HPMAIL
PRINT 10 (this is the mail item number)
b. FILE OUTPUT=$STDLIST
PRINT MYFILE1;OUT=*OUTPUT
c. FILE INPUT=$STDIN
read FROM *INPUT
d. FILE INPUT=MYFILE
read FROM *INPUT
e. FILE OUTPUT=MYFILE;REC=-80,,F,ASCII
write to *OUTPUT
6. For programmers only: Practice redirecting the error listing
output when compiling/linking the HIC program.
_________________________________________________________________
NOTE Throughout this exercise, you should never have to alter the
compile/link command line, just the file equation.
_________________________________________________________________
a. Create a file equation that defines HIERR as the terminal
screen.
b. Enter the following compile/link command line for the C
program, HIC. Refer to the formal file designator for the
error listing.
CCXLLK HIC,,*HIERR
Where does the listing print?
c. Change the file equation so that the error listing will be
stored in a file called ERROR1 with default file
characteristics.
FILE HIERR=ERROR1
d. Compile and link the program again. Where does the error
listing print?
e. Change the file equation one more time to store the error
listing in the ERROR2 file and compile and link the
program. Where does the error listing print this time?
Lesson summary
1. System-defined files that can appear in file equations include the
following:
a. $STDIN
b. $STDLIST
c. $NULL
2. When using a system-defined file in a file equation, the format
must be the following:
FILE filedesignator = system-defined file
3. When using a user-defined file in a file equation, the format must
be the following:
FILE filedesignator= user-defined file
[;REC=.........]
4. When using a device in a file equation, the format must be the
following:
FILE filedesignator;DEV=device
MPE/iX 5.0 Documentation