Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 97
Using Alternate Keys With a Relative File
!-----------------------------------------------------------
! Procedure for updating a record. The user selected
! function "u." The user is prompted for the key of the
! record to update. The procedure displays the current
! contents and prompts for the new. After the user enters
! the new contents, the procedure updates the log file.
!-----------------------------------------------------------
PROC UPDATE^RECORD;
BEGIN
LITERAL EXACT = 2;
INT KEY^SPEC;
INT COUNT^READ;
INT STATUS;
INT ERROR;
! Prompt the user to select a record:
CALL GET^DATE;
! Position the current-record and next-record pointers to
! the selected record:
KEY^SPEC ':=' "DA";
CALL KEYPOSITION(LOGNUM,SBUFFER,KEY^SPEC,
!length^word!,
EXACT);
IF <> THEN CALL FILE^ERRORS(LOGNUM);
! Read the record. Return to LOGGER if the record does not
! exist:
CALL READX(LOGNUM,RECORD,$LEN(RECORD),COUNT^READ);
IF <> THEN
BEGIN
CALL FILE_GETINFO_(LOGNUM,ERROR);
IF (ERROR = 1) OR (ERROR = 11) THEN
BEGIN
PRINT^STR("No such record");
RETURN;
END;
CALL FILE^ERRORS(LOGNUM);
END;
! Write the record to the terminal screen:
PRINT^BLANK;
PRINT^STR("Date: " & RECORD.DATE FOR DATESIZE);
PRINT^STR("Comments: " & RECORD.DATA FOR
RECORD.DATA^LEN);
! Prompt the user for the updated record:
PRINT^BLANK;
SBUFFER ':=' "Enter Revised Comments: " -> @S^PTR;