Enscribe Programmer's Guide

Access Examples
The remainder of this section presents annotated examples illustrating the most common ways to
access Enscribe entry-sequenced files.
Example 1. Writing to an Entry-Sequenced File
To append a new data record to the end of an entry-sequenced file you use WRITE or WRITEX to
add your data record to the file.
CALL WRITE (filenum, buffer, write^count);
IF <> THEN ... ! error
If you need to obtain the actual record address of the newly appended data record, use
FILE_GETINFOLIST_:
error := FILE_GETINFOLIST_ (filenum, itemlist, 1, result);
where itemlist is defined as:
itemlist := 12 ! Return address of current record
Example 2. Reading Sequentially by Primary Key
Assume that the particular entry-sequenced file you are working with contains variable length
transaction summary records, the largest of which is 200 bytes in length. To read the entire file
sequentially, you merely open the file and then repeatedly call the READ system procedure until
you encounter the EOF mark.
error := FILE_OPEN_ (filename:length, filenum, ... );
read^count := 200;
eof := 0;
WHILE NOT eof DO
BEGIN ! read loop
CALL READ (filenum, buffer, read^count, count^read);
IF > THEN eof := 1
ELSE
IF < THEN ... ! error
ELSE
BEGIN
. ! process the record (the returned
. ! <countread> parameter tells
. ! the record length in bytes)
END;
END; ! read loop
Example 3. Reading Sequentially by Alternate Key
Assume that you want to read only those records that contain the terminal number ATM37 in a
particular data field that was defined during file creation as an alternatekey field. Assume also
that the key specifier for that field is TN. You use KEYPOSITION to specify TN as the key specifier
and ATM37 as the key value. You then execute a read loop. As a result of the KEYPOSITION call,
Enscribe uses the alternate-key file associated with TN to access the desired data records from the
primary file. The read loop terminates upon encountering the EOF mark in the alternate-key file.
STRING value [0:4];
INT specifier,
compare^length;
error := FILE_OPEN_ (filename:length, filenum, ... );
specifier := "TN";
value ':=' "ATM37";
compare^length := 5;
generic := 1;
CALL KEYPOSITION (filenum, value, specifier,
132 Entry-Sequenced Files