Specification for the list of all record keys.
For the cobfa_open() and cobfa_openW() function, the list of all record keys in the indexed file to be opened is specified with the struct fa_keylist type.
Values to be set for the struct fa_keylist type members that give the overall organization of record keys are explained below.
#define FA_NKEYS 126u /* max number of keys */ struct fa_keylist { long kl_nkeys; /* number of keydesc */ struct fa_keydesc *kl_key [FA_NKEYS]; /* keydesc address of each key */ };
Set the total number of record keys for <kl_nkeys>.
Since an indexed file always contains the primary record key, the total number of record keys is always 1 or greater. The maximum value for this total number is FA_NKEYS (typically 126).
<kl_key> maintains information on each record key and is declared by the struct fa_keydesc type pointer. For the struct fa_keydesc type, see "4.1.1 struct fa_keydesc".
The sum of key parts retained by the record keys must not exceed FA_NALLPARTS (typically 255).
The sum of lengths of key parts retained by the record keys must not exceed FA_NALLKEYSIZE (typically 255).
Practical examples
Example
The list of record keys in an indexed file is one primary record key and one alternate record key (2 keys).
The primary record key has two key parts and does not permit duplication.
The first key part is at the first byte and its length is 4, the second key part is at the seventh byte counted from the first byte and its length is 2.
The alternate record key has one key part can be duplicated.
The key part is at the twelfth byte counted from the first byte and its length is 3.
Byte: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Offset:|0--|1--|2--|3--|4--|5--|6--|7--|8--|9--|10-|11-|12-|13-|14-|15-| |============================================================.... |---+---+---+---| |---+---| |---+---+---| first part of the second part of the alternate record key primary record key primary record key
COBOL program
001000 environment division. 001100 configuration section. 001200 input-output section. 001300 file-control. 001400 select FILENAME-1 assign to SYS006 001500 organization is indexed 001600 record key is part-1 part-2 001700 alternate record key is subpart with duplicates. : 002000 data division. 002100 file section. 002200 fd FILENAME-1. 002300 01 record-1. 002400 02 part-1 pic x(4). 002500 02 filler pic x(2). 002400 02 part-2 pic x(2). 002500 02 filler pic x(3). 002600 02 subpart pic x(3). 002700 02 filler pix x(...
C program
#include "f3bifcfa.h" struct fa_keylist keylist; /* for all keys structure */ struct fa_keydesc keydesc1; /* for prime record key */ struct fa_keydesc keydesc2; /* for alternate record key */ keylist.kl_nkeys = 2; /* number of keys: 2 (prim & alt) */ keylist.kl_key[0] = &keydesc1; /* prime key address */ keylist.kl_key[1] = &keydesc2; /* alternate key address */ keydesc1.k_flags = FA_NODUPS; keydesc1.k_nparts = 2; /* number of key parts: 2 */ keydesc1.k_part[0].kp_start = 0; /* 1 - 1 == 0 */ keydesc1.k_part[0].kp_leng = 4; keydesc1.k_part[0].kp_flags = FA_ANYKPCODE; keydesc1.k_part[1].kp_start = 6; /* 7 - 1 == 6 */ keydesc1.k_part[1].kp_leng = 2; keydesc1.k_part[1].kp_flags = FA_ANYKPCODE; keydesc2.k_flags = FA_DUPS; keydesc2.k_nparts = 1; /* number of key parts: 1 */ keydesc2.k_part[0].kp_start = 11; /* 12 - 1 == 11 */ keydesc2.k_part[0].kp_leng = 3; keydesc2.k_part[0].kp_flags = FA_ANYKPCODE;