The ENVIRONMENT Division

3.2 The ENVIRONMENT DIVISION

This division tells the computer what the program will be interacting with (i.e. its environment) such as printers, disk drives, other files etc... As such, there are two important sections: the CONFIGURATION SECTION (which defines the source and object computer) and the INPUT-OUTPUT SECTION (which defines printers, files that may by used and assigns identifier names to these external features).



     000260 ENVIRONMENT DIVISION.
     000270 CONFIGURATION SECTION.
     000280 SOURCE-COMPUTER.   IBM PC.
     000290 OBJECT-COMPUTER.   IBM PC.
     000300 INPUT-OUTPUT SECTION.
     000310 FILE-CONTROL.
     000320    SELECT INPUT-FILE ASSIGN TO 'input.dat'
     000330      ORGANIZATION IS LINE SEQUENTIAL.
     000340    SELECT PRINT-FILE ASSIGN TO PRINTER.

Notes:

  • You probably wouldn't need to bother with the configuration section (I think this is an oldie thing)
  • The DIVISION and SECTION words are written into area A but the SELECT clause should be in area B.
  • The full stop doesn't appear in the SELECT clause until after the ORGANIZATION has been specified.
  • INPUT-FILE and PRINT-FILE are user-defined names that are used in the program to refer to 'input.dat' and the printer, respectively. If the input.dat file was on a different disk drive, within a directory structure, then you could write: ...ASSIGN TO 'D:datafiles/data/input.dat'.
  • Line 000330 describes the structure or form of the data written in 'input.dat' file. In this case, each record is on a new line in the file (see File Handling section for details).
  • The printer also is assigned but the organization doesn't have to be secified.
  • For the SELECT clause, if no organization is defined the computer defaults to SEQUENTIAL organization (i.e. each record appears in a long string with no line breaks.


Things look clearer when you see a full program (see Sample Code section).