Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 74
Using Alternate Keys With a Key-Sequenced File
description is variable in length, the key length is specified in the call to
KEYPOSITION.
You can add further options to the following code to access records by supplier name,
inventory level, or price.
!------------------------------------------------------------
! Procedure for reading records. The user selected function
! "r." The start of the read is selected by approximate key
! positioning. The user has the option of sequentially
! reading subsequent records.
!------------------------------------------------------------
PROC READ^RECORD;
BEGIN
INT COUNT^READ;
INT ERROR;
INT KEY^SPEC;
INT POSITIONING^MODE;
INT COMPARE^LEN;
LITERAL APPROX = 0;
LITERAL GENERIC = 1;
! Prompt the user for the key to access the record by:
PRINT^BLANK;
PRINT^STR("Type 'p' to access by part number");
PRINT^STR("Type 'd' to access by part description");
PRINT^BLANK;
SBUFFER ':=' "Choice: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER, @S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
CASE SBUFFER[0] OF
BEGIN
"p", "P" ->
! Prompt the user for the part number:
PRINT^BLANK;
SBUFFER ':=' "Enter Part Number: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
! Set the key specifier to zero for the primary key:
KEY^SPEC := 0;