Getting Started as an MPE/iX Programmer Programmer's Guide: HP 3000 Computer MPE/iX Computer Systems > Chapter 7 Data ManagementKSAM/V |
|
KSAM is an acronym for Keyed Sequential Access Method. KSAM/V provides a disc file structure for organizing and accessing records in a file according to the contents of key fields. It is Hewlett-Packard's implementation of indexed sequential processing. KSAM/V allows you to access records in two ways:
A KSAM file consists of two associated MPE/iX files:
The data file contains the actual data. It can consist of fixed-length or variable-length records. Each record in the data file contains one primary key field and may have a maximum of 15 alternate key fields. Data records are stored in a KSAM file in chronological order (this is the order in which they were written to the file), without regard to key sequence. In KSAM mode, you can specify standard access if you wish. In addition to KSAM mode, you can specify standard (NOKSAM) mode. The associated key file must be used to access the data records. KSAM procedures add, delete, read, and update KSAM records and are callable from user applications. KSAMUTIL allows you to manipulate, verify, and analyze KSAM files. Because KSAM file structure is different from MPE/iX file structure, you cannot create a KSAM file with the MPE/iX command :BUILD. You can rename it with the MPE/iX command :RENAME, but it is inadvisable because it destroys the cross reference between the data file and the associated key file. Therefore, it is extremely useful to have KSAMUTIL commands that are designed to operate specifically on KSAM files and preserve the proper cross referencing. Figure 7-1 “Building a KSAM File” shows an example of building a KSAM file. The KSAMUTIL command BUILD requires the following parameters:
The first key specified becomes the primary key. Each subsequent key specified becomes an alternate key. Notice in the example that the first alternate key allows records to have duplicate values in that field. The fourth subparameter of the KEY field is the key blocking factor. Default blocking is one record per block, which usually results in wasted disc space. You can find the blocking factor by dividing the sector size (256) by the record length and then rounding down. You can use FCOPY with KSAM options that make it perform correctly for a KSAM file instead of an MPE/iX file. FCOPY provides many file manipulation services. For example, you can use it to:
The FCOPY utility has three KSAM options:
When using the KSAM options of FCOPY, consider the following information:
Figure 7-2 “Loading a KSAM File” shows an example of loading a KSAM file. The diagram shows how the key file is built on KSAM file information specified in the KSAMUTIL command BUILD. The steps required to reorganize a KSAM file are:
Figure 7-3 “Reorganizing a KSAM File” shows an example of reorganizing a KSAM file. KSAM procedures allow you to programmatically add, delete, read, and update KSAM files. The procedures vary depending on the language in which the program is written. You can access KSAM files through KSAM procedures in the native languages that run on the 900 Series HP 3000:
For detailed information on using KSAM procedures in HP C/iX, HP Pascal/iX, HP COBOL II/XL, and HP FORTRAN 77/iX, refer to KSAM/V Reference Manual (30000-90079). |