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

Working With Entry-Sequenced Files
Working With Files
106160 Tandem Computers Incorporated 12–47
The following code segment adds records to a mapped entry-sequenced file:
ASSIGN MDO=&rec. MAP=$NCL
/* 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*/
ASSIGN MDO=&rec. MAP=$NCL FROM VARS=&field*
SAY "Adding record "&rno" to "&filename
FILE ADD MDO=&rec.
END /*&rno do*/
It creates an MDO variable—&REC.—mapped by the map $NCL. It uses a DO loop to
obtain four records. It uses a nested DO loop to obtain four fields in each record that it
places in the ordinary variables—&FIELD*. After it obtains all fields for each record, it
uses the ASSIGN verb to transfer the data from the &FIELD* variables to the MDO
variable &REC.. The FILE ADD verb adds each record to the mapped
entry-sequenced file using the MDO variable &REC..
Adding a Record to an Unmapped Entry-Sequenced File
When you add a record to an unmapped entry-sequenced file, NCL uses the variables
you specify to create a record. The data in all variables are written contiguously. It is
good practice, if not essential, to pad short fields and truncate long fields to the desired
length, for example, using the LEFT built-in function, before writing a record so that
the length of each record in the unmapped UDB is the same.
The following code segment adds a record to an unmapped entry-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
/* Fix length of field at 20 bytes */
&field&fno = LEFT(&field&fno,20)
END /*&fno do*/
SAY "Adding record "&rno" to "&filename
FILE ADD VARS=&field*
END /*&rno do*/