The ENVIRONMENT DIVISION in COBOL specifies the program's operating environment, including the computer system, configuration, and external files or devices used by the program. It is essential for file handling and for programs that interact with the outside world.
The ENVIRONMENT DIVISION is divided into sections and paragraphs. Here is the typical structure:
123456789ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. computer-name. OBJECT-COMPUTER. computer-name. SPECIAL-NAMES. ... INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO external-name ... I-O-CONTROL. ...
Not all paragraphs are required; include only those needed for your program.
12345678ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-370. OBJECT-COMPUTER. IBM-370. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INFILE ASSIGN TO 'INPUT.DAT'. SELECT OUTFILE ASSIGN TO 'OUTPUT.DAT'.
1234567ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. DECIMAL-POINT IS COMMA CURRENCY SIGN IS "$". CLASS ALPHA IS "A" THRU "Z". SYMBOLIC CHARACTERS ARE CR=13, LF=10.
Here are some practical uses of the ENVIRONMENT DIVISION in COBOL programs:
1234ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPFILE ASSIGN TO 'EMPLOYEE.DAT'.
Maps the logical file EMPFILE to the physical file EMPLOYEE.DAT.
12345ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PRINTER ASSIGN TO PRINTER. SELECT TAPEFILE ASSIGN TO TAPE.
Assigns logical files to a printer and a tape device.
12345ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. DECIMAL-POINT IS COMMA CURRENCY SIGN IS "€".
Sets the decimal point to a comma and the currency sign to the Euro symbol.
1. What is the primary purpose of the ENVIRONMENT DIVISION in COBOL?
2. Which section is NOT part of the ENVIRONMENT DIVISION?
3. What is the purpose of the SELECT statement in the ENVIRONMENT DIVISION?
4. Where do you specify the ASSIGN TO clause in COBOL?
5. What is the SPECIAL-NAMES paragraph used for?