The Environment Division

The environment division describes the environment for which the program is written. It has two sections the CONFIGURATION SECTION and the INPUT-OUTPUT SECTION. The first of these is optional, but you should always include one.

CONFIGURATION SECTION

The configuration section describes the hardware on which the program is to run and on which it is to be compiled. The source computer is the computer on which the program is to be compiled. The object computer is the one on which the program is to run.

Additional features of the CONFIGURATION SECTION are:

  1. SPECIAL-NAMES. which is used to define mnemonics for printer control.
  2. items to determine ALPHABET, CURRENCY SIGN and DECIMAL-POINT, since the default values of these are what you would expect you can ignore them.

Here is what you need for the configuration section.

ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. i486. OBJECT-COMPUTER. i486.

INPUT-OUTPUT SECTION

COBOL programs historically get their input from files and write their output to files. Files are thus part of the environment in which a COBOL program runs. In addition most operating systems have naming conventions for files that lead to names that are unacceptable to COBOL. The FILE-CONTROL part of the INPUT-OUTPUT section serves to identify external files by names that are acceptable to the COBOL compiler. COBOL allows many kinds of files we only need sequential files and sort files so that is all that is illustrated.

Note that input files must be declared line sequential if they are created with an editor. This is because of the carriage return at the end of each line.

INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT NAME-ADDRESS-FILE ASSIGN TO "C:\TMP\SAMPIN.TXT" ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO "C:\TMP\SAMPOUT.TXT". * This next is only needed if the program is to sort a file. SELECT SORT-FILE-NAME ASSIGN TO "C:\TMP\SORT.TMP".
Return to the cobol home page
Jonathan Hodgson Last Change: 9 January 1998