SORT-MERGE/XL Programmer's Guide (32650-90884)
36 Chapter2
Creating Core Routines That Sort and Merge
Example of Core Sorting Routine
procedure DO_SORT;
var
inputfiles : array [1..3] of INTEGER;
outputfile : array [1..2] of INTEGER;
outputOption : INTEGER;
numKeys : INTEGER;
keys : array [1..4] of INTEGER;
altseq : packed array [1..2] of CHAR;
message : packed array [1..80] of CHAR;
length : INTEGER;
statistics : array [1..6] of INTEGER;
begin
inputfiles [1] := tempFileNum;
inputfiles [2] := permFileNum;
inputfiles [3] := 0;
outputfile [1] := outFileNum; {from
HPFOPEN}
outputfile [2] := 0;
outputOption := 0; {output record format same as input record format}
numKeys := 1; {one key }
keys[1] := 1; {key begins}
keys[2] := 20; {key length}
keys[3] := 0; {byte data }
keys[4] := 0; {ascending order}
altseq[1] := CHR(255); {data = ASCII; sequence = ASCII}
altseq[2] := CHR(255); {256 characters in ASCII}
HPSORTINIT (status, inputfiles, outputfile, outputOption,,, numKeys, keys,
altseq,,,,,);
if status <> 0 then {If error in HPSORTINIT }
begin {Get message and write it to screen}
Message := ' ';
HPSORTERRORMESS (status, message, length);
writeln (message);
end;
HPSORTEND (status, );
if status <> 0 then {If error in HPSORTEND }
begin {Get message and write it to screen}
message := ' ';
HPSORTERRORMESS (status, message, length);
writeln (message)
end;
end;
procedure CLOSE_FILES;
var
disposition : SHORTINT;