  | 
»  | 
 | 
  
 | 
 | 
As discussed in Chapter 2, a file can be created when it is opened using the HPFOPEN or FOPEN intrinsics. The file characteristics must be specified, as well as the formal file designator, the domain, and the access method. The most common item numbers used to create and open KSAM XL files with the HPFOPEN intrinsic include: - 2
 The file designator. - 10
 A file type of 3 for KSAM XL files. - 11
 An access option of 1 for writing records to a new file. - 19
 The record length. - 35
 The maximum file length. - 50
 Either a disposition of 2 for a temporary file or 1 for a permanent file. - 53
 ASCII or binary record data. - 54
 The KSAM key parameter defining primary and alternate key descriptions. 
 Figure 4-2 “Opening a New KSAM XL File with HPFOPEN” presents a portion of a program that builds and opens a KSAM XL file. Figure 4-2 Opening a New KSAM XL File with HPFOPEN 
type
   bit1=0..1;
   bit4=0..15;
   bit7=0..127;
   bit8=0..255;
   bit12=0..4095;
   bit15=0..32767;
   bit16=0..65535;
   pac80  = packed array [1..80] of char;
   ksam_rec = packed record
              case integer of
              1 : (bitword : bit16);
              2 :  (lang_id : bit16);
              3 : (resrvd0 : bit8;
                   select_blk_size;
                   cm      : bit1;
                   chg_primary : bit1;
                   kslang  : bit1;
                   ksreuse : bit1;
                   seq_random : bit1;
                   rec_numbering : bit1;
                   resrvd2 : bit1);
              4 : (resrvd3 : bit8;
                   num_keys : bit8);
              5 : (key_type : bit4;
                   key_length : bit12);
              6 : (dflag : bit1;
                   maxkeyblk : bit15);
              7 : (resrvd5 : bit8;
                   rflag : bit1;
                   resrvd6 : bit7);
              8 : (key_location : bit16); 
              end;
   ksam_struc = ARRAY[0..80] OF ksam_rec;
.
.
.
var 
   file_num  : integer;
   status    : integer;
   file_name      : pac80;
   ksam_type      : integer;
   write_access   : integer;
   line_len       : integer;
   file_len       : integer;
   save_perm      : integer;
   ascii          : integer;
   ksamparam      : ksam_struc;
   keylocation,
   reserved       : bit16;
.
.
.
begin
   file_num        := 0;
   status          := 0;
   file_name       := '%ARMSTR.MGR.AR%';
   ksam_type       := 3;
   write_access    := 1;
   rec_len         := 80;
   file_len        := 100;
   save_perm       := 1;
   ascii           := 1;
.
.
.
 ksamparam[10].lang_id  := 5; 
ksamparam[16].resrvd3  := 0;
ksamparam[16].num_keys := 1;
ksamparam[17].key_type := 2;
ksamparam[17].key_length := 5;
keylocation := 5;
ksamparam[18].bitword := keylocation;
.
.
.
HPFOPEN(file_num, status,
       2, file_name,
       10, ksam_type
       11, write_access
       19, rec_len,
       35, file_len
       50, save_perm,
       53, ascii
       54, ksamparam
       );
   if status <> 0 then handle_file_error (file_num, status);
end;
 |  
 To create a new KSAM XL file using the FOPEN intrinsic, file characteristics and KSAM key information are specified in the positional parameters.  In most cases, the foption, aoption, recsize, ksamparam, and filesize parameters must be specified.  Commas identify those positional parameters for which the default specifications are used.  Figure 4-3 “Opening a New KSAM XL File with FOPEN” provides an FOPEN intrinsic call that creates a KSAM XL file with write access to build the file. Figure 4-3 Opening a New KSAM XL File with FOPEN 
type 
   bit1=0..1;
   bit4=0..15;
   bit7=0..127;
   bit8=0..255;
   bit12=0..4095;
   bit15=0..32767;
   bit16=0..65535;
   pac80          = packed array [1..80] of char;
   ksam_rec       = packed record
                      case integer of
                        1 : (bitword : bit16);
                        2 :  (lang_id : bit16);
                        3 : (resrvd0 : bit8;
                             select_blk_size;
                             cm      : bit1;
                             chg_primary : bit1;
                             kslang  : bit1;
                             ksreuse : bit1;
                             seq_random : bit1;
                             rec_numbering : bit1;
                             resrvd2 : bit1);
                        4 : (resrvd3 : bit8;
                             num_keys : bit8);
                        5 : (key_type : bit4;
                             key_length : bit12);
                        6 : (dflag : bit1;
                             maxkeyblk : bit15);
                        7 : (resrvd5 : bit8;
                             rflag : bit1;
                             resrvd6 : bit7);
                        8 : (key_location : bit16); 
                    end;
   ksam_struc     = ARRAY[0..80] OF ksam_rec;
var
   file_num       : integer;
   file_name      : pac80;
   ksamparam      : ksam_struc;
   keylocation    : bit16;
begin
   file_num                 := 0;
   file_name                := 'ARMSTR.MGR.AR ';
   ksamparam[10].lang_id    := 5;
   ksamparam[16].resrvd3    := 0;
   ksamparam[16].num_keys   := 1;
   ksamparam[17].key_type   := 2;
   ksamparam[17].key_length := 5;
   keylocation              := 5;
   ksamparam[18].bitword    := keylocation;
   file_num:=FOPEN(file_name,6148,1,-80,,ksamparam,,,,100)
end;
 |  
  
 |