Using KSAM/XL and KSAM 64 (32650-90886)

265
C HP C/iX Example Program
The following example program shows how a KSAM XL file can be created, accessed, and
updated from an HP C/iX program. This program uses features of ANSI C. Compile with
INFO=-Aa + e.
This example program uses the assert macro to do quick error checking. In a production
program, more comprehensive error checking and reporting would be desirable.
The KSAM XL file has the following layout:
1 - 5 Employee number (primary key)
6 - 25 Name (secondary key)
26 - 34 Social Security Number
35 - 38 Department Number (secondary key)
39 - 44 Date of hire
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpe.h>:
#pragma intrinsic FCLOSE, FFINDN, FLOCK
#pragma intrinsic FREAD, FREADBYKEY, FREMOVE
#pragma intrinsic FUNLOCK, FUPDATE, FWRITE
#pragma intrinsic HPCICOMMAND, HPFOPEN
#define FILENAME "KSAMD"
typedef char record_t[44];
static int filenum;
static void close_file(void);
static void create_file(void);
static void delete_records(void);
static void dump_file(void);
static void list_sequential(void);
static void list_sequential_primary(void);
static void list_sequential_secondary(int location);
static void lock_file(void);
static void open_file(void);
static void unlock_file(void);
static void update_records(void);
static void write_new_records(void);
static void write_record(const char *record);
main(void)
{
create_file();
open_file();
dump_file();
write_new_records();
update_records();
delete_records();