NET/MASTER Network Control Language (NCL) Programmer's Guide
Working With Entry-Sequenced Files
Working With Files
106160 Tandem Computers Incorporated 12–53
Example—Adding Records to an Entry-Sequenced File
The following NCL procedure adds four records to a mapped entry-sequenced file. It
obtains the records by pausing and waiting for input typed in at the OCS command
input line. One line of input is regarded as one field in a record. Each record has four
fields.
zex1204n: PROCEDURE
 /* Adds records to a mapped entry-sequenced UDB */
 ON ERROR FLUSH
 IF &1 = "" THEN DO
 SAY "Must enter file name as first parameter"
 FLUSH
 END
 ELSE
 &filename = &1
 &id = MESUDB
 CALL create_file SHARE &filename,&id
 CALL open_file SHARE &filename,&id
 CALL add_records SHARE &filename,&id
 CALL close_file SHARE &filename,&id
 EXIT
 /* ==================== CREATE FILE ==================== */
 create_file: PROCEDURE SHARE &filename
 /* Use FUP to create new entry-sequenced file */
 SAY "Creating file "&filename
 INTCMD "OPSYS SEND FUP CREATE "&filename", TYPE E, REC 512"
 DO UNTIL &msgno = NNM0999
 INTREAD VARS=(&msgno(7),*,&text) TYPE=ANY PARSE=NO
 IF POS("ERR 10",&text) > 0 THEN DO
 /* File exists, so flush NCL process */
 SAY "Must enter new file name"
 FLUSH
 END /*do*/
 END /*do until*/
 INTCMD "OPSYS KILL FUP"
 INTREAD
 END create_file
 /* ==================== OPEN FILE ==================== */
 open_file: PROCEDURE SHARE &filename,&id
 /* Open file for NonStop NET/MASTER and NCL */
 SAY "Opening "&filename
 INTCMD "UDBCTL OPEN="&filename" ID="&id
 INTREAD
 FILE OPEN ID=&id FORMAT=MAPPED MAP=$NCL
 SELECT &SYS.FILE.RC
 WHEN 0 THEN SAY "0 Read-only access"
 WHEN 4 THEN SAY "4 Read and write access"
 WHEN 8 THEN SAY "8 Read, write, and delete access"
 WHEN 12 THEN SAY "12 No access"
 WHEN 16 THEN SAY "16 "&SYSMSG
 OTHERWISE
 SAY Unexpected error
 END /*select*/
 END open_file










