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

Chapter 2 21
Creating Core Routines That Sort and Merge
Initializing a Sort or Merge
When programming in COBOL, you can sort and merge records directly through the
COBOL SORT and MERGE statements. These statements allow you to specify the key,
collating sequence, and file or record output to be used by the SORT-MERGE/XL utility.
For further information, refer to COBOL II Reference Manual and COBOL II/XL
Reference Manual Supplement.
You will find FORTRAN information in Appendix D of this manual.
Creating Input Files in a Database Creating SORT-MERGE/XL input files from a
database depends on your database and access method. For information about creating
files and loading information to them from a database, refer to your database manual set.
Accessing the Input File
The SORT and MERGE intrinsics access input files through their file numbers. You pass
the identification numbers in the
inputfiles
parameter of the HPSORTINIT or
HPMERGEINIT intrinsic. The
inputfiles
parameter is an array. The last number in the
array must be zero, as shown in the example below.
To get the file identification numbers, open the input files with the intrinsic HPFOPEN (or
FOPEN), as in the example.
The following is from the example at the end of the chapter. The first part opens the files
TEMPEMP and PERMEMP, and gets their file numbers, (tempFileNum and permFileNum). The
second part puts these identification numbers in an array for the
inputfiles
parameter of
the HPSORTINIT or HPMERGEINIT intrinsics.
const
designator : 2; {HPFOPEN formaldesignator= option}
domain : 3; {HPFOPEN file domain= option}
access : 11; {used later for output file}
var
tempFileNum : INTEGER; {HPFOPEN will return}
permFileNum : INTEGER; { with file numbers }
status : INTEGER; {error check}
tempFile : packed array [1..10] of CHAR;
permFile : packed array [1..10] of CHAR;
permanent : INTEGER;
newFile := '%TEMPEMP%';
permanent := 1;{file is permanent, in system file domain}
HPFOPEN (tempFileNum, status, designator, tempFile,
domain, permanent);
PermFile := '%PERMEMP%';
HPFOPEN (permFileNum, status, designator, permFile,
domain, permanent);