Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 50
Positioning, Reading, and Writing With Key-
Sequenced Files
one record each time it goes through the loop. The READX procedure returns an
error when the end-of-file is reached; you can use this condition to exit the loop.
LITERAL APPROX = 0;
.
.
KEY^VALUE := "CAAAAAAAAAAAAAAA";
CALL KEYPOSITION(NAME^FILE^NUM,
KEY^VALUE,
!key^specifier!,
!length^word!,
APPROX);
WHILE 1 DO
BEGIN
CALL READX(NAME^FILE^NUM,
BUFFER,
$LEN(RECORD),
BYTES^READ);
IF <> THEN ...
END;
.
.
Generic key positioning uses a partial key to reference a group of records that
contain the partial key. If you use the key value “C” with generic positioning, then
your program accesses the first record whose primary key begins with “C,” if one
exists. If there is no such record, the KEYPOSITION call returns without error but
the I/O operation that attempts to access the record does return an error.
To use generic key positioning, you must also supply the length of the part of the
key that will be used to start the generic access. In the example given below, the
single letter “C” is used, therefore the key length is set to 1.
In the following example, a READX call returns an end-of-file indication as soon as
the key value no longer matches the generic key given in the KEYPOSITION call:
LITERAL GENERIC = 1;
.
.
KEY^VALUE := "C";
KEY^LENGTH := 1;
CALL KEYPOSITION(NAME^FILE^NUM,KEY^VALUE,
!key^specifier!,
KEY^LENGTH,GENERIC);
WHILE 1 DO
BEGIN
CALL READX(NAME^FILE^NUM,BUFFER,
$LEN(RECORD),BYTES^READ);
IF <> THEN ...
END;
.
.