Concurrency Support | Integrated Preprocessor Interface |
COBOL recognizes various devices, either implicitly or explicitly. This chapter describes the COBOL aspects of the devices as well as their operating system dependent aspects. It describes how they can be configured for use and how they can then be accessed from COBOL.
The COBOL language recognizes various logical devices and the run-time system automatically maps them onto suitable physical devices. For files, you can override the automatic mapping by specifying a filename that is recognized as a device by either the run-time system or the operating system. Such filenames are operating system dependent and you should not use them if you require your program to be portable.
The COBOL language implicitly recognizes four categories of logical device:
COBOL files are typically mapped onto the file system supported by the operating system but can be mapped onto other devices or functions such as a physical printer, a print spooler, named pipes, logical devices or device drivers. The run-time system may recognize a particular name or may find out the type of file from the operating system and as a result direct the file to a special logical or physical device.
COBOL assumes a standard input device for a simple unformatted ACCEPT statement and assumes a standard output device for a simple unformatted DISPLAY or for a STOP literal statement. These two standard logical devices can be mapped directly to the operator console or indirectly via the operating system's standard input and output devices.
COBOL ACCEPT and DISPLAY statements can also handle full screen, non-scrolling forms which the COBOL run-time system maps onto the operator's physical or logical terminal device.
COBOL can identify logical device-dependent functions by specifying a function-name in the Configuration Section of your source program (see The Special Names Paragraph in your Language Reference). These are mapped onto suitable operating system facilities.
COBOL files are typically mapped onto the file system supported by the operating system, which hides any fixed or exchangeable media devices from the COBOL system (see your File Handling book).
Alternatively, the COBOL files can be mapped in other ways by using:
In all cases, if a COBOL file is mapped to something other than a file held on the standard file system, the COBOL program must adhere to any restrictions implied by using the special device. For example, a printer should not be used for input, a magnetic tape device should not be used for indexed files or random file access, and a named pipe should not use record locking syntax.
Table 15-1 shows the special names recognized by the COBOL run-time system for UNIX.
The Server Express run-time system is case-sensitive for device-names.
You should not attempt to access a file held on the file system with a filename that matches a special device-name recognized by the COBOL system.
Device Name | Implied Operating System Device |
:CI:
stdin |
Standard input stream |
:CO:
stdout |
Standard output stream |
:CE:
stderr |
Standard error stream or if not available standard output stream |
Table 15-1: COBOL Special Device Names
Table 15-2 gives examples of the special names typically recognized by the operating system in the environments shown. See your operating system documentation for an exhaustive list of such devices.
Filename | Facility Provided by Operating System |
---|---|
/dev/null | Device that discards output |
/dev/floppy | Floppy disk drive |
/dev/cart0 | Cartridge tape drive |
Table 15-2: Operating System Special Device Names
In addition, the operating system can identify any filename with a special type of file such as a named pipe.
The filenames used for devices such as the floppy disk or tape cartridge drives vary between versions of UNIX and sometimes even between different installations of the same version. The typical examples shown above are given only as an illustration.
A portable program should not attempt to access a file held on the file system with a filename that matches a special device name recognized by any other operating system.
The FILE-CONTROL paragraph names each file and enables specification of other file-related information, some of which is device-dependent. This is shown in Table 15-3.
Filename
|
Facility Provided by Operating System
|
---|---|
LINE ADVANCING | Printer-destined file |
MULTIPLE REEL | File that might extend over more than one unit |
MULTIPLE UNIT | File that might extend over more than one unit |
DISK | Phrase is documentary only |
KEYBOARD | Line sequential organization, default filename :CI: |
DISPLAY | Line sequential organization, default filename :CO: |
PRINTER | Printer-destined file, default filename LPT1 |
PRINTER-1 | Printer-destined file, default filename LPT2 |
Table 15-3: COBOL Special Device Clauses
LINE ADVANCING specifies that the file is destined for a printer and that the output format is a standard operating system independent printer format; see the chapter File Structures in your File Handling book for further details. Any WRITE statement referencing the file without a BEFORE or AFTER phrase automatically acts as if an AFTER 1 phrase had been specified. See the section The WRITE Statement in your Language Reference for further details.
MULTIPLE REEL and MULTIPLE UNIT are equivalent and specify that files might extend over more than one unit of media appropriate to the device. For example a floppy disk or tape cartridge. See your File Handling book for further details.
DISK is purely documentary and has no effect.
KEYBOARD specifies that the standard input device is to be treated as a file of records with line sequential file organization. If no explicit filename is specified a filename of :CI: is assumed, the standard input device.
DISPLAY specifies that the standard output device is to be treated as a file of records with line sequential file organization. If no explicit filename is specified a filename of :CO: is assumed, the standard output device.
PRINTER and PRINTER-1 are equivalent to specifying LINE ADVANCING and in addition, if no explicit filename is specified, a filename of LPT1 or LPT2 is assumed respectively. The files are mapped to a disk file named LPT1 or LPT2 respectively in the current directory.
This COBOL system provides for three special types of streams of messages, one for input and two for output, known as standard input, standard output and standard error respectively. These message streams can be accessed in a variety of ways from COBOL, via simple ACCEPT, DISPLAY or STOP literal statements or by normal file operations on files whose filename identifies the appropriate special device name (see the earlier section COBOL Special Device-names).
The UNIX operating system supports standard input, output and error as special devices or files and the COBOL streams are directly mapped to them. The operating system then allows these special files to be redirected in various ways but directs them to the terminal by default.
All components of this COBOL system, including the Compiler and run-time system, make use of the standard input, output and error streams where appropriate. Note in particular that normal output and error output are logically distinguished and where the operating system allows, they can be redirected individually.
The following program, demo.cbl, reads a line from standard input and writes a line to each of standard output and standard error. Typical command lines follow that run the program and redirect the standard input from demo.in, the standard output to demo.out, and the standard error to demo.err. The file demo.in is assumed to contain "Redirected input!". The operating system carries out the redirection and the results are not under the control of the COBOL system.
working-storage section. 01 tmp pic x(20). procedure division. accept tmp from sysin. display "Message stdout is: " tmp upon sysout display "This is a message to stderr" upon syserr.
If you run the command:
cobrun demo <demo.in >demo.out 2>demo.err
then demo.out contains "Message to stdout is: Redirected input!", and demo.err contains "This is a message to stderr".
A COBOL program can access a terminal device in one of two ways using the ACCEPT or DISPLAY statements:
The COBOL system takes no special action when treating the terminal as a CONSOLE device, relying on the standard operating system support to handle the terminal.
For formatted screen I-O, the COBOL system has to take action at two levels: the logical level and the physical level. The Adis module translates the high-level COBOL requirements into logical, low-level, terminal-independent operations. The run-time system translates these logical operations into the terminal-dependent instructions required to drive the terminal as well as translating any terminal-dependent response into a logical form before passing it back to the Adis module.
A UNIX system might have virtually any type of terminal connected. The run-time system task of translating between the Adis terminal-independent operations and the physical character strings and escape sequences used by the terminal device is performed by a separate screen handling module. This module is a part of the COBOL system but it uses the standard UNIX method for handling a terminal: the environment variable TERM contains the name of the terminal type and the details for that terminal type are held in the UNIX terminfo system database. The run-time system requires that terminfo holds a minimum set of details for the terminal otherwise it will give a run-time error. See the chapter Terminfo Database and Terminal Devices in your Server Express User's Guide for details on specifying and using your terminal's capabilities with your COBOL system.
The screen handling module drives the terminal via the standard UNIX input and output devices. Terminal I-O can be redirected but with the restriction that you must not redirect standard input from a file unless it represents a terminal device. So, for example, the following is legal:
cobrun prog < ` tty ` > ` tty `
whereas redirecting the input from an ordinary file or /etc/null is not legal and could result in a run-time error. If you try the above example, be sure to use the correct apostrophe (`) rather than the similar but incorrect one (').
The COBOL Compiler recognizes various function-names in the Special-Names paragraph (see your Language Reference) and allows you to reference them in the Procedure Division using the associated mnemonic-name. Different COBOL dialects recognize different sets of function-names. The following table lists all the function-names recognized by your Compiler for the various COBOL dialects, together with an indication of the meaning of the function-name and the COBOL statement in which it may be referenced. The letter Y indicates that the function-name is recognized for the given dialect, the letter U indicates that it is recognized by your compiler and the mainframe compiler but that it is not a documented mainframe function-name. A blank indicates that the function-name is not recognized for that COBOL dialect.
Function-name | Meaning | Statements in Which Function Can be Used | COBOL Dialect | ||||
---|---|---|---|---|---|---|---|
MF | XOPEN | OSVS | VSC2 | ||||
2 | 3 | ||||||
COMMAND- LINE | The line of system commands that invoked the main program. Text to substitute for the system command line | ACCEPT and DISPLAY | Y | ||||
PRINTER | System logical printer | DISPLAY | Y | ||||
TAB | Skip to vertical tabulation position | WRITE | Y | ||||
ARGUMENT-
NUMBER |
Number of component of COMMAND-LINE | ACCEPT and DISPLAY | Y | Y | |||
ARGUMENT-
VALUE |
Value of component of COMMAND-LINE | ACCEPT | Y | Y | |||
ENVIRONMENT-
NAME |
Name of environment variable | DISPLAY | Y | Y | |||
ENVIRONMENT-
VALUE |
Value associated with environment variable | ACCEPT and DISPLAY | Y | Y | |||
SYSERR | System logical error device | DISPLAY | Y | Y | |||
SYSIN | System logical input device | ACCEPT | Y | Y | Y | Y | Y |
SYSIPT | System logical input device | ACCEPT | Y | U | U | Y | |
SYSOUT | System logical output device | DISPLAY | Y | Y | Y | Y | Y |
SYSLIST | System logical output device | DISPLAY | Y | Y | |||
SYSLST | System logical output device | DISPLAY | Y | U | U | Y | |
SYSPCH | System logical output device | DISPLAY | Y | U | U | Y | |
SYSPUNCH | System logical output device | DISPLAY | Y | U | Y | Y | |
CONSOLE | System logical I-O device | ACCEPT and DISPLAY | Y | Y | Y | Y | |
C01 | Skip to printer channel 1 | WRITE | Y | Y | Y | Y | |
C02 through C12 | Skip to printer channel 2 through 12 respectively | WRITE | Y | Y | Y | Y | |
S01 through S02 | Select punch pocket | WRITE | Y | Y | Y | Y | |
S03 through S05 | Select punch pocket | WRITE | Y | U | Y | ||
CSP | Suppress spacing | WRITE | Y | Y | Y | Y | |
One-character non-numeric literal | Report writer code | CODE clause | Y | Y |
COMMAND-LINE provides the standard way of accessing a COBOL application command line. See your Language Reference for information on the ACCEPT statement and the DISPLAY statement for details.
ARGUMENT-NUMBER and ARGUMENT-VALUE provide access to the command line using the method specified by X/Open. See your Language Reference for information on the ACCEPT statement and the DISPLAY statement for details.
ENVIRONMENT-NAME and ENVIRONMENT-VALUE provide access to environment variables held by the operating system using the method specified by X/Open. See your Language Reference for information on the the ACCEPT statement and the DISPLAY statement for details.
FORMFEED and TAB provide vertical and horizontal positioning in a printer-destined LINE ADVANCING file using the WRITE statement with the ADVANCING phrase. See your File Handling book for details on the format of LINE ADVANCING files.
The PRINTER function-name provides source code compatibility for source code developed in mainframe environments. We recommend that you do not use it unless absolutely necessary. This function-name must not be confused with the PRINTER clause to the SELECT statement in the Input-Output Section.
The DISPLAY data-item UPON PRINTER statement writes the contents of data-item as a single record to a print spooler process via a pipe. Once the record has been written, the pipe is closed. By default, the spooler that is run is lp but any alternative process can be specified by using the COBPRINTER environment variable. See the appendix Micro Focus Environment Variables in your Server Express User's Guide for details of COBPRINTER.
The system logical input, output and error devices are mapped to the COBOL special devices :CI:, :CO: and :CE: respectively.
The CONSOLE function-name causes the ACCEPT or DISPLAY statement to map the I-O to the COBOL special devices :CI: and :CO: for input and output respectively. This option cannot be used with the FROM CRT phrase or with a Screen Section item.
Your system emulates printer channels C01 through C12 by line feeds and form feeds. If you want to write to these channels you should set the COBLPFORM environment variable to define the line numbers on the form. This must consist of a series of numbers separated by colons as in the following example:
COBLPFORM=1:::::::::::60 export COBLPFORM
This sets channel 1 to line 1 (the beginning of the page) and channel 12 to line 60. You can specify only a single line number for each channel. Those channels which have line number zero, function-names S01-S052, CSP, or are undefined, are set to line 1. See the appendix Micro Focus Environment Variables in your UNIX Server Express User's Guide for further details of COBLPFORM.
Any WRITE BEFORE/AFTER PAGE statements cause positioning to be at line 1. Each line that is advanced increases the line number by one. A request to skip to a line number less than or equal to the current line causes a new page to begin. The appropriate number of line feeds are then generated.
Any WRITE BEFORE/AFTER TAB statements generate a form feed and cause any subsequent skips to a channel number to start a new page.
The value of the literal has no effect at run time.
Copyright © 2000 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names
used herein are protected by international law.
Concurrency Support | Integrated Preprocessor Interface |