[Info-vax] Indexed file read question

Arne Vajhøj arne at vajhoej.dk
Wed Nov 18 14:34:48 EST 2020


On 11/18/2020 11:35 AM, abrsvc wrote:
> On Wednesday, 18 November 2020 at 11:20:54 UTC-5, Stephen Hoffman wrote:
>> On 2020-11-18 15:23:13 +0000, abrsvc said:
>>> Situation: Indexed file with 2 keys, the first key no duplicates,
>>> second key no duplicates. For clarity, the first key is a record
>>> number and the second key is one of 4 values: A,B,L or blank.
>> With only four records possible, why is this even a file? Which
>> implies there *are* duplicates on the secondary?

> Update:  There are duplicates for the second key.

You did not tell what API.

I am too lazy to code it using direct RMS calls, but
Pascal is easier:

$ type keys.pas
program keys(input, output);

type
     fix50str = packed array [1..50] of char;
     arr10int = array [1..10] of integer;
     data = record
               k1 : [KEY(0,NODUPLICATES)] integer;
               k2 : [KEY(1, DUPLICATES)] char;
               v  : fix50str;
            end;

var
     f : file of data;
     d : data;
     ids : arr10int value [ 1:6; 2:2; 3:7; 4:1; 5:8; 6:3; 7:9; 8:10; 
9:5; 10:4 ];
     i, id : integer;
     letter : char;

begin
     open(f, 'keys.isq', new, organization := indexed, access_method := 
keyed);
     for i := 1 to 10 do begin
         id := ids[i];
         letter := chr(65 + (i mod 3));
         d.k1 := id;
         d.k2 := letter;
         d.v := 'Record #' + dec(i, 4);
         f^ := d;
         put(f);
     end;
     for i := 1 to 10 do begin
         id := ids[i];
         findk(f, 0, id);
         if not ufb(f) then begin
             d := f^;
             writeln('lookup k1=', id:2, ' : ', d.k1:2, ' ', d.k2, ' ', 
d.v);
             letter := d.k2;
             findk(f, 1, letter);
             if not ufb(f) then begin
                 d := f^;
                 writeln('lookup k2= ', letter, ' : ', d.k1:2, ' ', 
d.k2, ' ', d.v);
             end;
         end;
     end;
     close(f);
end.
$ pas keys
$ lin keys
$ run keys
lookup k1= 6 :  6 B Record #0001
lookup k2= B :  6 B Record #0001
lookup k1= 2 :  2 C Record #0002
lookup k2= C :  2 C Record #0002
lookup k1= 7 :  7 A Record #0003
lookup k2= A :  7 A Record #0003
lookup k1= 1 :  1 B Record #0004
lookup k2= B :  6 B Record #0001
lookup k1= 8 :  8 C Record #0005
lookup k2= C :  2 C Record #0002
lookup k1= 3 :  3 A Record #0006
lookup k2= A :  7 A Record #0003
lookup k1= 9 :  9 B Record #0007
lookup k2= B :  6 B Record #0001
lookup k1=10 : 10 C Record #0008
lookup k2= C :  2 C Record #0002
lookup k1= 5 :  5 A Record #0009
lookup k2= A :  7 A Record #0003
lookup k1= 4 :  4 B Record #0010
lookup k2= B :  6 B Record #0001

Arne




More information about the Info-vax mailing list