COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

statement to receive a record of exactly the length declared (explicitly or implicitly) in the file
description, and they raise a run-time error if too short a record is typed at the terminal. If a record
of more than the declared number of characters is typed at the terminal, the run-time routine does
not deliver the excess characters to the process.
When an HP COBOL process opens a file assigned to a terminal, it establishes communication
with that terminal. The default exclusion mode for terminals is SHARED. If a process is to have
private use of a terminal, with no command interpreter assigned to the terminal, the OPEN statement
should specify the exclusion mode EXCLUSIVE.
Use the ASSIGN clause of the file-control entry for a given file to associate a COBOL file name
with a device name or logical device number of a terminal. You can override this assignment at
the start of a process’s execution by using the TACL command ASSIGN. Establish the assignment
dynamically during process execution by specifying #DYNAMIC in the ASSIGN clause of the
file-control entry and calling the COBOL_ASSIGN_ routines to associate the terminal device name
or logical device number with a COBOL file name.
Example 291 shows the use of terminal $TRM053 as a file.
Example 291 Using a Terminal as a File
IDENTIFICATION DIVISION.
PROGRAM-ID. TERMINAL-READ-WRITE.
AUTHOR. BO COBOL.
DATE-WRITTEN. 29 FEBRUARY 1984.
DATE-COMPILED.
*************************************************************
* This program illustrates the use of a terminal as a *
* file *
*************************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. HP TXP.
OBJECT-COMPUTER. HP TXP.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT A-TERM
ASSIGN TO "$TRM053"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD A-TERM
RECORD CONTAINS 1 TO 79 CHARACTERS
LABEL RECORDS ARE OMITTED.
* Using 80 characters causes a blank line after
* the WRITE
01 A-TEXT-RECORD PICTURE X(79).
PROCEDURE DIVISION.
A.
* Open the terminal as a file, excluding other users.
OPEN I-O A-TERM EXCLUSIVE.
B.
* Read one 79-character record. If a CTRL/Y was entered,
* quit.
READ A-TERM
AT END GO TO HIT-EOF.
* Insert response.
MOVE "So what?" TO A-TEXT-RECORD.
* Deliver response.
WRITE A-TEXT-RECORD.
* Loop.
GO TO B.
Using a Terminal as a File 891