 |
» |
|
|
 |
The following program sorts the personnel files, TEMPEMP and
PERMEMP, that were also used for the last example. They are sorted
by last name. The output records are altered before they are sent
to $STDLIST. Example 3-2 SORTREC_OUT Program program SORTREC_OUT (input,output); {This program reads data from the TEMPEMP and PERMEMP files, sorts them by last {name, outputs them by record, alters the output record, and prints the record to ($STDLIST.} var tempFileNum: INTEGER; permFileNum: INTEGER; status : INTEGER; procedure HPFOPEN ; intrinsic; procedure HPSORTINIT; intrinsic; procedure HPSORTOUTPUT; intrinsic; procedure HPSORTEND; intrinsic; procedure FCLOSE; intrinsic; procedure OPEN_FILES; const designator = 2; domain = 3; access = 11; var tempfile : packed array [1..10] of CHAR; permfile : packed array [1..10] of CHAR; permanent : INTEGER; begin tempfile := '%TEMPEMP%'; permanent := 1; HPFOPEN (tempFileNum, status, designator, tempfile, domain, permanent); permfile := '%PERMEMP%'; HPFOPEN (permFileNum, status, designator, permfile, domain, permanent); end; procedure DO_SORT; var inputfiles : array [1..3] 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; buffer : packed array [1..80] of CHAR; begin inputfiles [1] := tempFileNum; inputfiles [2] := permFileNum; inputfiles [3] := 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,, outputOption,,, numKeys, keys, altseq,,,,,); repeat {get output record and alter it} HPSORTOUTPUT (status, buffer, length); strmove (7, 'Empl. #',1, buffer, 33); strmove (10, 'Hire Date:', 1, buffer, 50); if length >0 then writeln (buffer); until length <0; HPSORTEND (status, ); end; procedure CLOSE_FILES; var disposition : SHORTINT; securityCode : SHORTINT; begin disposition := 0; securityCode := 0; FCLOSE (tempFileNum, disposition, securityCode); FCLOSE (permFileNum, disposition, securityCode); end; begin {main} OPEN_FILES; DO_SORT; CLOSE_FILES; end.
When this program is executed, the output is written to the
screen: Everett, Joyce Empl. # 000029 Hire Date: 10/19/87 Gangley, Tomas Empl. # 000003 Hire Date: 06/06/87 Jackson, Jonathan Empl. # 000006 Hire Date: 06/06/87 Jackson, Rosa Empl. # 000022 Hire Date: 08/15/87 Jones, Eliza Empl. # 000001 Hire Date: 06/06/87 Rields, Evelyn Empl. # 000007 Hire Date: 07/12/87 Smith, James Empl. # 000005 Hire Date: 06/06/87 Washington, Lois Empl. # 000014 Hire Date: 07/23/87 |
|