NET/MASTER Network Control Language (NCL) Programmer's Guide

Working With Single Key-Sequenced Files
Working With Files
106160 Tandem Computers Incorporated 12–65
Getting a Record From a Delimited Key-Sequenced File
The following code segment gets all records from a delimited key-sequenced file,
beginning at the last record:
/* Get records and displays them on OCS window */
FILE GET OPT=BWD VARS=&field*
DO WHILE &SYS.FILE.RC = 0
DO &fno = 1 TO &SYS.VARCNT
/* Use | to show exact field length */
SAY "Field "&fno" is |"&field&fno"|"
END /*do*/
FILE GET OPT=SEQ VARS=&field*
END /*do while*/
Updating a Record The FILE PUT verb updates an existing record in a key-sequenced file. You can
update existing records in mapped, unmapped, and delimited key-sequenced files.
When you update a record, the new data in the record overwrites the old data in the
record. You must specify the value of the record key, using the KEY operand, either
before updating the record, using the FILE SET verb, or when you update the record,
using the FILE PUT verb.
Note See the discussion on adding a record to an entry-sequenced file earlier in this section for information on
how to construct a record before updating the record in a file.
Update Techniques
There are two general techniques you can use to update an existing record. You can
either read the record first, using the FILE GET verb, before replacing the record with
FILE PUT, or you can replace it directly with FILE PUT without reading it. The
method you choose is determined by the requirements of your NCL procedure.
Locking a Record Before an Update
If more than one NCL process may attempt to concurrently update the same record in
a file, you must ensure that updates are not lost or overwritten. You can do so by
locking a record when it is retrieved by the FILE GET verb before using the FILE PUT
verb to update it. You can use either the OPT=UPD or UPDATE operand of the FILE
GET verb to retrieve a record and lock it.
If a record is already in use, the FILE GET operation fails. The system variable
&SYS.FILE.RC is set to 8 and the system variable &SYS.FILE.ERROR contains the
corresponding Guardian error number, which is 73. The NCL process can then take
alternative action, such as delaying processing for a short period of time, using the
DELAY verb, before retrying the FILE GET operation. When the FILE GET verb is
finally successful, the NCL process can issue FILE PUT to complete the update
operation.