COBOL Manual for TNS and TNS/R Programs
Terminal Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
29-13
Reading and Writing Numeric Data
The compiler accepts this form of the ACCEPT statement only if it has already
encountered an entry in the SPECIAL-NAMES paragraph associating MY-NAME-FOR-
DOLLAR-QQQ with some device or process; for example:
SPECIAL-NAMES.
FILE "$QQQ" IS MY-NAME-FOR-DOLLAR-QQQ.
Each time an ACCEPT statement in a process executes, the process opens the
terminal or process, collects the characters, and closes the terminal or process. Some
other process could open the terminal or process for exclusive use and hold it open,
causing the next ACCEPT or DISPLAY statement that tries to reach it to get a “device
in use” error.
Reading and Writing Numeric Data
The ANSI standard is not very specific on the details of the behavior of ACCEPT. The
ACCEPT statement, as implemented in HP COBOL, allows you some flexibility in
entering numeric data that some other implementations do not.
HP COBOL allows you to enter a sequence of characters that correspond to a numeric
literal, such as would be legal in an HP COBOL source program. The ACCEPT run-
time routine converts this numeric representation into an appropriate form for storage
in the designated data item, only as if you had a MOVE statement that specified the
numeric literal as its source and the data item as its destination.
The DISPLAY statement is equally versatile, converting a stored data value to a
convenient external format. In Example 29-6, both ACCEPT and DISPLAY handle
signed and unsigned numeric, numeric edited, and computational items.
Example 29-6. Reading and Writing Numeric Data (page 1 of 2)
IDENTIFICATION DIVISION.
PROGRAM-ID. FRIENDLY-ACCEPT.
AUTHOR. KIT COBOL.
INSTALLATION. TRANSACTIONS ANONYMOUS.
DATE-WRITTEN. 29 FEBRUARY 1984.
DATE-COMPILED.
******************************************************
* This program shows the flexibility of the ACCEPT *
* statement. *
******************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. HP TXP.
OBJECT-COMPUTER. HP TXP.
SPECIAL-NAMES.