SORT-MERGE/XL Programmer's Guide (32650-90884)

38 Chapter2
Creating Core Routines That Sort and Merge
Example of Core Merging Routine
Example of Core Merging Routine
The following program merges the personnel files shown at the beginning of the previous
example. The input files are already sorted by employee number.
In this example, the files are merged by employee number. The record size is determined
by the input files. The
status
parameter is checked after the calls to HPMERGEINIT and
HPMERGEEND.
Example 2-2. MERGEFILE Program
program MERGEFILE (input,output);
{This program reads the files, TEMPEMP and PERMEMP, merges}
{them by employee number, and outputs to the file, ALLEMP }
var
tempFileNum: INTEGER;
permFileNum: INTEGER;
outFileNum : INTEGER;
status : INTEGER;
procedure HPFOPEN ; intrinsic;
procedure HPMERGEINIT; intrinsic;
procedure HPMERGEERRORMESS; intrinsic;
procedure HPMERGEEND; intrinsic;
procedure FCLOSE; intrinsic;
procedure OPEN_FILES;
const
designator = 2;
domain = 3;
access = 11;
record_size = 19;
var
tempFile : packed array [1..10] of CHAR;
permFile : packed array [1..10] of CHAR;
outFile : packed array [1..10] of CHAR;
permanent : INTEGER;
new : INTEGER;
write : INTEGER;
size : INTEGER;
tempFile := '%TEMPEMP%';
permanent := 1;
HPFOPEN (tempFileNum, status, designator, tempFile, domain, permanent)
;
permFile := '%PERMEMP%';
HPFOPEN (permFileNum, status, designator, permFile, domain, permanent)
;
new := 4;
write := 1;