Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 81
Using Alternate Keys
5 Communicating With Disk Files
Using Alternate Keys
This subsection examines how you can access a record in a structured file using a key
value other than the primary key. To do this, you need an alternate-key file to provide
the link between the alternate and primary keys.
Creating Alternate-Key Files
You can create primary-key and alternate-key files either interactively using the FUP
CREATE command or programmatically using the FILE_CREATELIST_ procedure. In
either case, you need to supply information about how to build the files, including the
attributes of the primary file as well as the attributes of the alternate-key file.
The simplest way to create alternate-key files is by using the FUP CREATE command
as shown below. This example creates a primary-key file like the one created in the
previous example and also creates two alternate-key files to access the data records
by part description (“DE specifier) and supplier name (“SU” specifier).
1> FUP
-SET TYPE R
-SET BLOCK 4096
-SET REC 130
-SET KEYOFF 0
-SET KEYLEN 8
-SET ALTKEY ("DE",FILE 0,KEYOFF 8,KEYLEN 60)
-SET ALTFILE (0,$ADMIN.OPERATOR.ALT2)
-SET ALTKEY ("SU",FILE 1,KEYOFF 66,KEYLEN 60)
-SET ALTFILE (1,$ADMIN.OPERATOR.ALT3)
-SHOW
TYPE K
EXT ( 1 PAGES, 1 PAGES )
REC 130
BLOCK 4096
ALTKEY ( "DE", FILE 0, KEYOFF 6, KEYLEN 60 )
ALTKEY ( "SU", FILE 1, KEYOFF 66, KEYLEN 60 )
ALTFILE ( 0, $ADMIN.OPERATOR.ALT2 )
ALTFILE ( 1, $ADMIN.OPERATOR.ALT3 )
ALTCREATE
MAXEXTENTS 16
-CREATE KEY2FILE
CREATED - $ADMIN.OPERATOR.KEY2FILE
CREATED - $ADMIN.OPERATOR.ALT2
CREATED - $ADMIN.OPERATOR.ALT3
.
.
-EXIT
2>
Refer to the File Utility Program (FUP) Reference Manual for more details on how to
create files using the FUP CREATE command.