- TEMPEMP
 
  Information file about temporary employees:
 
 Last Name           First Name       Employee Number       Hire Date
 Gangley,            Tomas               000003              06/06/87
 Rields,             Evelyn              000007              07/12/87
 Everett,            Joyce               000029              10/19/87
 0        1         2         3         4         5         6         7
 1234567890123456789012345678901234567890123456789012345678901234567890
  - PERMEMP
 
  Information file about permanent employees:
 
 Last Name          First Name        Employee Number       Hire Date
 Jones,              Eliza               000001              06/06/87
 Smith,              James               000005              06/06/87
 Jackson,            Johnathon           000006              06/06/87
 Washington,         Lois                000014              07/23/87
 Jackson,            Rosa                000022              08/15/87
 0        1         2         3         4         5         6         7
 1234567890123456789012345678901234567890123456789012345678901234567890
Example 3-1 SORTREC_IN Program
  program SORTREC_IN (input,output);
  {This program reads the files, TEMPEMP & PERMEMP, }
  {   alters the TEMPEMP records,                       }
  {passes all records to SORT/XL, and outputs to the file, ALLEMP.}
  
  var
     tempFileNum: INTEGER;
     permFileNum: INTEGER;
     outFileNum : INTEGER;
     status     : INTEGER;
  procedure HPFOPEN; intrinsic;
  procedure HPSORTINIT; intrinsic;
  function  FREAD : SHORTINT; intrinsic;
  procedure HPSORTINPUT; intrinsic;
  procedure HPSORTEND; 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;
  begin
     tempfile := '%TEMPEMP%';
     permanent := 1;
     HPFOPEN (tempFileNum, status, designator, tempfile, domain,
              permanent);
     permfile := '%PERMEMP%';
     HPFOPEN (permFileNum, status, designator, permfile, domain,
              permanent);
     new := 4;
     write := 1;
     size := 80;
     outfile := '%ALLEMP%';
     HPFOPEN (outFileNum, status, designator, outfile, domain, new,
              access, write, record_size, size);
  end;
  
  
  procedure DO_SORT;
  var
     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;
     lngth        : SHORTINT;
     buffer       : packed array [1..80] of CHAR;
     recLength    : INTEGER;
  begin
     outputfile [1] := outFileNum;                     {From HPFOPEN}
     outputfile [2] := 0;
     outputOption := 0;   {output record format same as input record}
     recLength := 80;                         {maximum record length}
     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}
  end;
    HPSORTINIT (status,, outputfile, outputOption,
                recLength,, numKeys, keys, altseq,,,,,);
    length := 72;                                {read 72 characters}
    repeat                   {read temporary employee file by record}
       Lngth := FREAD (TempFileNum, Buffer, Length);
       Buffer[40] := '*';                           {Mark the record}
       if Lngth <> 0 then
         HPSORTINPUT (Status, Buffer, Length);
    until Lngth = 0;
    repeat                   {read permanent employee file by record}
      lngth := FREAD (permfilenum, buffer, length);
      if lngth <> 0 then
         HPSORTINPUT (status, buffer, length)
    until lngth = 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);
     disposition := 1;
     FCLOSE (outFileNum, disposition, securityCode);
  end;
  begin {main}
     OPEN_FILES;
     DO_SORT;
     CLOSE_FILES;
  end.
When this program is executed, the output is written to ALLEMP. To view ALLEMP:
 :print allemp
 Everett,            Joyce              *000029              10/19/87
 Gangley,            Tomas              *000003              06/06/87
 Jackson,            Jonathan            000006              06/06/87
 Jackson,            Rosa                000022              08/15/87
 Jones,              Eliza               000001              06/06/87
 Rields,             Evelyn             *000007              07/12/87
 Smith,              James               000005              06/06/87
 Washington,         Lois                000014              07/23/87