COBOL Manual for TNS and TNS/R Programs
Terminal Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
29-6
Prompting the Terminal Operator for Input
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 29-3. READ Statement With PROMPT Phrase (page 1 of 2)
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.