Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 60
Key-Sequenced File Programming Example
!------------------------------------------------------------
! Procedure for reading records. The user selected function
! "r." The start of the read is selected by approximate key
! positioning. The user has the option of sequentially
! reading subsequent records.
!------------------------------------------------------------
PROC READ^RECORD;
BEGIN
INT COUNT^READ;
INT ERROR;
! Prompt the user for the part number:
PRINT^BLANK;
SBUFFER ':=' "Enter Part Number: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
! Position approximately to the selected record:
CALL KEYPOSITION(PARTFILE^NUM,SBUFFER,
!key^specifier!,
COUNT^READ,0);
IF <> THEN CALL FILE^ERRORS(PARTFILE^NUM);
! Loop reading and displaying records until user declines
! to read the next record (any response other than "y"):
DO BEGIN
PRINT^BLANK;
! Read a record from the part file.
! If end-of-file is reached,
! return control to the main procedure.
CALL READX(PARTFILE^NUM,PART^RECORD,$LEN(PART^RECORD));
IF <> THEN
BEGIN
CALL FILE_GETINFO_(PARTFILE^NUM,ERROR);
IF ERROR = 1 THEN
BEGIN
PRINT^STR("No such record");
RETURN;
END;
CALL FILE^ERRORS(PARTFILE^NUM);
END;
! Display the record on the terminal:
CALL DISPLAY^RECORD;