SORT-MERGE/XL Programmer's Guide
> Chapter 2 Creating Core Routines That Sort and MergeInitializing a Sort or Merge |
||||||||||||||||||||||||||||||||||||
|
HPSORTINIT (status, inputfiles, outputfile, outputoption, reclength, numrecs, numkeys, keys, altseq, keycompare, errorproc, statistics, memsize, charseq); HPMERGEINIT (status, inputfiles, preprocessor, outputfile, postprocessor, keysonly, numkeys, keys, altseq, keycompare, errorproc, statistics, memsize, charseq);The core routine examples that follow do not use all of the parameters listed above. When you enter these intrinsics, you must maintain the position of any unused parameters with commas. The inputfiles and outputfiles parameters in this chapter are files; input and output by record is discussed in Chapter 3. The altseq and charseq parameters, which alter the collating sequence, are discussed in Chapter 4. The statistics parameters, which get SORT-MERGE/XL information, are discussed in Chapter 5. Specifying InputThe most common way to supply information to SORT-MERGE/XL is through an input file. Input considerations include:
Creating Input FilesSORT-MERGE/XL accepts one or more input files. You create these files with an editor, in a program, or from a database. You may not use $NULL as an input file. Remember that your data items must be in a fixed format. Each data item of the same type must start in the same column. If your data is not in a fixed format, your results will be unpredictable.Creating Input Files in an EditorYou can use any text editor to create fixed format data files stored in character format. For example, EDIT/3000 keeps your data items lined up by using tabs to separate them. This ensures a fixed format. To follow the example below, enter EDIT/3000, set the tab character to a displayable character, and indicate where you want the tabs to be set./tabchar = "%", tabs = (21,41,61)To verify that the tab character and the tabs are set the way you want them, enter: /verify tabchar, tabsYou will see EDIT/3000 display: tab character = "%" tabs = (21,41,61)Enter your information in the following manner: When you list this file, it will appear as follows: Give your file a meaningful name, save it with the KEEP command. This example file contains permanent employee information, so it is kept as PERMEMP. For more information about EDIT/3000, refer to the EDIT/3000 Reference Manual. Creating Input Files in a ProgramWith intrinsics, you can access SORT-MERGE/XL programmatically from any language. When you create a file from a program, the data can be any data type allowed by the language you are using. For information about creating input files and saving the output file, refer to the programmer's guide for your language, such as:
Creating Input Files in a DatabaseCreating 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 FileThe 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. Now that you have the file numbers, you can initialize the inputfiles parameter: If you do not specify anything in inputfiles in HPSORTINIT, SORT/XL assumes that input will be by individual record and that you are using the HPSORTINPUT intrinsic. For information about input by record, refer to Chapter 3.Using Tape Input (SORT/XL Only)If any of your files are stored on tape, HPSORTINIT needs to know the total number of records that you have on disc and tape. This is specified in the numrecs parameter. If you have tape files but do not specify this parameter, SORT/XL defaults to 10,000 records per tape file. SORT/XL takes the size of your disc files from the file label; if all your files are on disc, do not specify this parameter.Specifying OutputThe most common method of maintaining output from SORT-MERGE/XL is by specifying an output file. Output considerations include:
Creating the Output FileYou specify the output file by indicating its file identification number in the outputfile parameter in HPSORTINIT or HPMERGEINIT. The outputfile parameter is an array. The last number in the array must be zero, as shown in the example below. To get the file number, open the output file with HPFOPEN (or FOPEN), as in the example. The following is from the example at the end of the chapter. The first part creates a new permanent file named outFile with WRITE access and with logical records of 80 bytes. The second part puts the number of this file into an array for the outputfile parameter of the HPSORTINIT or HPMERGEINIT intrinsics. Now that you have the file numbers, you can initialize the inputfiles parameter: If you do not specify anything in outputfile SORT-MERGE/XL assumes that output will be by individual record and that you are using the HPSORTOUTPUT intrinsic.Output Record Format (SORT/XL)You specify the content of the SORT/XL output file with the outputoption parameter of HPSORTINIT. The part of the core routine example at the end of the chapter that specifys the outputoption in HPSORTINIT is: The options are outputoption equals:
Output Record Format (MERGE/XL)You specify the format of the MERGE/XL output file with the keysonly parameter of HPMERGEINIT. The part of the core routine example at the end of the chapter that specifys the keysonly in HPSORTINIT is: The options are keysonly equals:
Specifying KeysThe key indicates the part of each record that is compared to determine output record order. In HPSORTINIT or HPMERGEINIT, you indicate the number of keys with the numkeys parameter and give key information in the keys parameter. The part of the core routine example at the end of the chapter that specifies keys is: The keys parameter is an integer array; each key contains four elements you specify. The elements are:
Specifying Data and SequenceIf your key is a character or byte data type, you may use the altseq parameter to specify two things.
Using HPSORTINITThe following code segment demonstrates the the HPSORTINIT intrinsic. The parameters used are those already discussed. Using HPMERGEINITThe following code segment demonstrates the HPMERGEINIT intrinsic. The parameters used are those already discussed. Note that the HPMERGEINIT intrinsic call is different from the HPSORTINIT intrinsic call.
|