Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 62
Key-Sequenced File Programming Example
!------------------------------------------------------------
! Procedure for updating a record. The user selected
! function "u." The user is prompted to enter the part
! number of the record to be updated, then the old contents
! are displayed on the user's terminal before the user
! is prompted to enter the updated record.
!------------------------------------------------------------
PROC UPDATE^RECORD;
BEGIN
INT COUNT^READ;
INT ERROR;
STRUCT .SAVE^REC(PART^RECORD);
STRUCT .CHECK^REC(PART^RECORD);
PRINT^BLANK;
! Prompt the user for the part number of the record to be
! updated:
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 exactly to the selected record.
! SBUFFER[COUNT^READ] ':=' [PARTSIZE*[" "]];
CALL KEYPOSITION(PARTFILE^NUM,SBUFFER,
!key^specifier!,
COUNT^READ,2);
IF <> THEN CALL FILE^ERRORS(PARTFILE^NUM);
! Read the selected record. If no such record exists,
! the procedure informs the user and returns control to
! the main procedure:
CALL READUPDATEX(PARTFILE^NUM,PART^RECORD,
$LEN(PART^RECORD));
IF <> THEN
BEGIN
CALL FILE_GETINFO_(PARTFILE^NUM,ERROR);
IF ERROR = 11 THEN
BEGIN
PRINT^BLANK;
START^LINE;
PUT^STR("No such record");
PRINT^LINE;
RETURN;
END
ELSE CALL FILE^ERRORS(PARTFILE^NUM);
END;