NET/MASTER Network Control Language (NCL) Programmer's Guide
Working With Single Key-Sequenced Files
Working With Files
12–60 106160 Tandem Computers Incorporated
Adding a Record to a Delimited Key-Sequenced File
The following code segment adds records to a delimited key-sequenced file:
…
/* Allows you to enter 4 fields for 4 records */
DO &rno = 1 TO 4
DO &fno = 1 TO 4
SAY Enter record &rno field &fno
CMDLINE "-GO ID="&SYS.NCLID _
PAUSE VARS=&field&fno PARSE=NO
END /*&fno do*/
SAY "Adding record "&rno" to "&filename
FILE ADD KEY=&rno VARS=&field*
SAY "Key is "&SYS.FILE.KEY
END /*&rno do*/
…
The key to each record is the record number. The value of the record number is the
value of the control variable in the DO loop that obtains each record.
Getting a Record The FILE GET verb retrieves a record from a key-sequenced file. You can retrieve
records from mapped, unmapped, and delimited key-sequenced files. Each FILE GET
statement in an NCL process retrieves one record from a file; an NCL process must
issue multiple FILE GET statements to retrieve multiple records. When you are
retrieving records sequentially, by using one of the options listed earlier in this section
in Table 12-5 to specify retrieval direction, you need not specify a record key;
otherwise, you must specify the value of the record key.
Note See the discussion on getting a record from an entry-sequenced file, earlier in this section, for information
on sequential retrieval.
The method of retrieval determines how you specify the record key. In addition to
retrieving records sequentially, there are two other methods of retrieval from a
key-sequenced file: exact retrieval and generic retrieval.
Exact Retrieval
Exact retrieval by a specific key, specified by OPT=KEX, is the default. Exact retrieval
retrieves only records whose current key value contains a value that is both exactly as
long as the defined length and equal to the value of the current key. (If the specified
key is shorter than the defined length, it is padded with blanks for delimited files:
otherwise with nulls.)
You have two options when retrieving a record exactly. The first option requires two
FILE verbs to retrieve a record, and is outlined in the following steps:
1. Set the current key by using the FILE SET verb, for example:
FILE SET KEY=ABCDEF