Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 43
Entry-Sequenced File Programming Example
!------------------------------------------------------------
! 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 GET^REC^ADDR := ZSYS^VAL^FINF^CURRRECPOINTER;
INT COUNT^READ;
INT WIDTH;
INT(32) REC^ADDR;
INT ERROR;
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);
! Get the record address and display it on the terminal:
ERROR := FILE_GETINFOLIST_(LOGNUM,GET^REC^ADDR,1,
REC^ADDR,$LEN(REC^ADDR));
IF ERROR <> 0 THEN
CALL FILE^ERRORS^NAME(LOGNAME:LOGLEN,ERROR);
START^LINE;
PUT^STR("Record address is: ");
PUT^DOUBLE(REC^ADDR);
CALL WRITE^LINE(SBUFFER,@S^PTR '-' @SBUFFER);
END;