Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 27
Relative-File Programming Example
CALL FILE^ERRORS(LOGNUM);
END;
! Write the record to the terminal screen:
PRINT^BLANK;
CALL WRITE^LINE(SBUFFER,COUNT^READ);
! Prompt the user for the updated record:
PRINT^BLANK;
SBUFFER ':=' "Enter New Contents of Record: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
! Write new record to log file:
CALL WRITEUPDATEX(LOGNUM,SBUFFER,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
END;
!------------------------------------------------------------
! Procedure for appending a record. The user selected
! function "a." The user is prompted to enter comments. The
! procedure puts the comments in a new record at the end of
! the file.
!------------------------------------------------------------
PROC APPEND^RECORD;
BEGIN
INT COUNT^READ;
PRINT^BLANK;
! Prompt user for comments and read comments into the
! buffer:
SBUFFER ':=' "Enter today's comments: "
-> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
! Place the next-record pointer at the end-of-file and
! write the new record there:
CALL POSITION(LOGNUM, -1D);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
CALL WRITEX(LOGNUM,SBUFFER,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
END;