Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 63
Key-Sequenced File Programming Example
! Save the record for later comparison
SAVE^REC ':=' PART^RECORD FOR $LEN(PART^RECORD) BYTES;
! Display the record on the terminal:
CALL DISPLAY^RECORD;
! Prompt the user for the updated record:
CALL ENTER^RECORD(OLD);
! Now that we have the user's changes, reread the record
! and check to see whether someone else changed it while
! the user was responding.
CALL READUPDATELOCKX(PARTFILE^NUM,CHECK^REC,
$LEN(PART^RECORD));
IF <> THEN CALL FILE^ERRORS(PARTFILE^NUM);
IF CHECK^REC <> SAVE^REC FOR $LEN(PART^RECORD) BYTES THEN
BEGIN
CALL UNLOCKREC(PARTFILE^NUM);
PRINT^BLANK;
PRINT^STR("The record was changed by someone else " &
"while you were working on it.");
PRINT^STR("Your change was not made.");
RETURN;
END;
! Write the new record to the file:
CALL WRITEUPDATEUNLOCKX(PARTFILE^NUM,PART^RECORD,
$LEN(PART^RECORD));
IF <> THEN CALL FILE^ERRORS(PARTFILE^NUM);
END;