COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
HIT-EOF.
STOP RUN.
Prompting the Terminal Operator for Input
This topic assumes that you are using the terminal as a file (see Using a Terminal as a File).
HP COBOL has a useful extension that can be used with terminal input and output. The HP COBOL
READ statement is extended to include a PROMPT phrase. If you want to enter a dialogue with a
user at a terminal, just using alternate WRITE statements for prompts and READ statements to collect
the reply causes the prompt to appear on one line of the screen and the reply to be collected from
the next line. You can achieve a more natural effect of having the prompt and its reply appear on
the same line by using the PROMPT phrase.
When an HP COBOL process executes a READ statement that includes a PROMPT phrase, the
HP COBOL run-time routine that performs terminal input and output first delivers the characters in
the data item whose name appears in the PROMPT phrase to the terminal, leaving the terminal
cursor at the next available character position. Next, the routine clears the file’s record area to
spaces. When the terminal operator enters a sequence of zero or more characters, terminated by
pressing Return, the routine delivers the sequence of characters into the record area and returns
control to the process.
Example 292 READ Statement With PROMPT Phrase
IDENTIFICATION DIVISION.
PROGRAM-ID. TERMINAL-READ-WRITE.
AUTHOR. FLO COBOL.
DATE-WRITTEN. 29 FEBRUARY 1984.
DATE-COMPILED.
*************************************************************
* This program illustrates the use of READ PROMPT *
* for a terminal 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).
WORKING-STORAGE SECTION.
01 TAUNT PIC X(17) VALUE "What do you want?".
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 WITH PROMPT TAUNT
AT END GO TO HIT-EOF.
* Insert response.
892 Terminal Input and Output










