Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 68
Key-Sequenced File Programming Example
!------------------------------------------------------------
! Procedure for inserting a record. The user selected
! function "i." The user is prompted to enter comments. The
! procedure puts the comments in a new record at the end of
! the file.
!------------------------------------------------------------
PROC INSERT^RECORD;
BEGIN
INT COUNT^READ;
INT ERROR;
PRINT^BLANK;
! Prompt user for comments and read comments into the
! buffer:
CALL GET^DATE;
RECORD.DATE ':=' SBUFFER FOR DATESIZE;
SBUFFER ':=' "Enter comments: "
-> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
COMMENTSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
RECORD.DATA ':=' SBUFFER FOR COUNT^READ;
RECORD.DATA^LEN := COUNT^READ;
! Position to the end of file and write the new record:
CALL POSITION(LOGNUM,-1D);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
CALL WRITEX(LOGNUM,RECORD,$LEN(RECORD));
IF <> THEN
BEGIN
CALL FILE_GETINFO_(LOGNUM,ERROR);
IF ERROR = 10 THEN
BEGIN
PRINT^BLANK;
PRINT^STR
("There is already a record for that date.");
PRINT^STR("This comment was not entered.");
END ELSE BEGIN
CALL FILE^ERRORS(LOGNUM);
END;
END;
END;