Enscribe Programmer's Guide
Note that the sequence skips empty records (records 12, 13, and 16 in the sample file).
Reading Sequentially by Alternate Key
This sequence defines the desired key value as 60, the desired key specifier as DP (department
code), both the compare length and key length as 2 and exact positioning (2):
key^value := "60";
CALL FILE_SETKEY_(filenum, key^value:2,”DP”,2);
Using those specifications and the sample file illustrated in “Sample Relative File” (page 147), a
subsequent sequence of five READ calls accesses data records from the file as:
CALL READ (filenum, buffer, read^count); ! reads record 2
CALL READ (filenum, buffer, read^count); ! reads record 3
CALL READ (filenum, buffer, read^count); ! reads record 7
CALL READ (filenum, buffer, read^count); ! reads record 9
CALL READ (filenum, buffer, read^count); ! reads record 10
Writing Sequentially by Primary Key
You write data to empty physical records in a relative file by using FILE_WRITE64_/WRITE procedure
calls. The current access path must be the primary key field, which is the default when a relative
file is first opened.
Assuming that records 0 through 4 are currently empty, this sequence of five WRITE calls issued
immediately after opening the file would do this:
error := FILE_OPEN_ (filename:length, filenum)
! sets the access path = 0
! (primary key) and the
! next-record pointer = 0
CALL WRITE (filenum, buffer, write^count); ! writes to rec. 0
CALL WRITE (filenum, buffer, write^count); ! writes to rec. 1
CALL WRITE (filenum, buffer, write^count); ! writes to rec. 2
CALL WRITE (filenum, buffer, write^count); ! writes to rec. 3
CALL WRITE (filenum, buffer, write^count); ! writes to rec. 4
If you attempt to WRITE data to a record that is not empty, the operation fails with an error 10
(duplicate record).
To append new records to the end of a relative file, you use the FILE_SETPOSITION_ procedure
to point to the current EOF position and then issue successive WRITE calls. Assuming that the EOF
pointer currently contains the value 260, this sequence of calls appends five records to the end of
a relative file.
CALL FILE_SETPOSITION_(filenum,-1F);! sets next-rec.ptr.
= -1
CALL WRITE (filenum, buffer, write^count);!writes to rec. 260
CALL WRITE (filenum, buffer, write^count);!writes to rec. 261
CALL WRITE (filenum, buffer, write^count);!writes to rec. 262
CALL WRITE (filenum, buffer, write^count);!writes to rec. 263
CALL WRITE (filenum, buffer, write^count);!writes to rec. 264
Note that this sequence also causes the EOF pointer to be incremented appropriately.
After any of the write operations, you can obtain the address of the newly appended record by
issuing this procedure call:
item := 202;
error := FILE_GETINFOLIST_ (filenum, item, 1, primary^key, 8);
To insert a new data record into any available empty physical record, you supply the value -2 in
a FILE_SETPOSITION_ call and then issue a WRITE call.
CALL FILE_SETPOSITION_ (filenum, -2F);
CALL WRITE (filenum, buffer, write^count);
148 Relative Files