Environment Division

This chapter explains the structure of the environment division.

1. Configuration Section

The Configuration section describes a program’s execution environment. It must be defined in the Environment division.

figure ed configuration section
CONFIGURATION Section

The configuration section consists of the following paragraphs.

  • SOURCE-COMPUTER paragraph

  • OBJECT-COMPUTER paragraph

  • SPECIAL-NAMES paragraph

1.1. SOURCE-COMPUTER Paragraph

The SOURCE-COMPUTER paragraph describes the computer on which the source program is compiled.

figure ed source computer
SOURCE-COMPUTER Paragraph
  • computer-name

    • Specifies the name of the computer on which the source program is compiled.

    • Only used as information written by a program developer.

The SOURCE-COMPUTER paragraph is syntax checked, but does not affect the program execution.

1.2. OBJECT-COMPUTER Paragraph

The OBJECT-COMPUTER paragraph describes the environment in which runtime modules created by a compiler are executed.

figure ed object computer
OBJECT-COMPUTER Paragraph
  • computer-name

    • Specifies the system name on which a compiled module is executed.

    • Only used as information written by a program developer.

  • PROGRAMMING COLLATING SEQUENCE IS

    • Specifies the collating sequence to be used by the program and programs that include the program.

    • PROGRAM COLLATING SEQUENCE is used to compare the following alphanumeric characters.

      • Those explicitly specified in relation conditions.

      • Those explicitly specified in condition name conditions.

    • If the PROGRAM COLLATING SEQUENCE clause is omitted, the EBCDIC collating sequence is applied first.

The OBJECT-COMPUTER paragraph is syntax checked, but only the PROGRAM COLLATING SEQUENCE clause affects the execution of the program.

1.3. SPECIAL-NAMES Paragraph

The SPECIAL-NAMES paragraph has the following features.

  • Relates alphabet names to character sets or collating sequences.

The SPECIAL-NAMES paragraph clauses can be specified in any order.

figure ed special names
SPECIAL-NAMES Paragraph
figure ed special names entry1
SPECIAL-NAMES Entry
figure ed special names phrase1
SPECIAL-NAMES Phrase

If a clause is not specified, the separator, a period (.), can be omitted. If it is specified, a period must follow the last clause.

  • environment-name-1

    • Specifies a name that represents a system device using the following.

      environment-name-1 Meaning Allowed in

      SYSIN, SYSIPT

      System input

      ACCEPT

      SYSOUT, SYSLIST, SYSLST

      System output

      DISPLAY

      SYSPUNCH, SYSPCH

      Punching system

      DISPLAY

      CONSOLE

      Console

      ACCEPT, DISPLAY

      SYSPUNCH and SYSPCH are syntax checked, but they do not affect the execution of the program.

  • environment-name-2

    • Specifies a 1 byte user programmable status indicator (UPSI) switch with a value between USPI-0 and USPI-7.

    • environment-name-2 is syntax checked, but it does not affect the execution of the program.

  • mnemonic-name-1, mnemonic-name-2

    • Follows the rules for user-defined names.

    • mnemonic-name-1 can be used in the ACCEPT, DISPLAY, and WRITE statements.

    • mnemonic-name-2 can be referenced only in the SET statement.

  • ON STATUS IS, OFF STATUS IS

    • Defines whether the status of the user programmable status indicator (UPSI) switch is ON or OFF.

  • condition-1, condition-2

    • Can only use condition-name conditions.

    • Follows the rules for user-defined names. At least one alphanumeric character must be included.

    • A condition name specified in the SPECIAL-NAMES paragraph can be referenced by all programs included in the program.

environment-name and mnemonic-name do not need to be unique. If mnemonic-name is the same as environment-name, mnemonic-name takes priority over environment-name.

1.3.1. ALPHABET Clause

The ALPHABET clause relates a specified character set or collating sequence to alphabet-name.

alphabet-name specifies a collating sequence when used in the following cases.

  • The PROGRAM COLLATING SEQUENCE clause of the OBJECT-COMPUTER paragraph.

  • The COLLATING SEQUENCE phrase of a SORT or MERGE statement.

The following alphabet-names can be specified.

  • STANDARD-1

    Specifies the ASCII character set.

  • NATIVE, EBCDIC

    Specifies the EBCDIC character set.

  • literal-1, literal-2, literal-3

    Specifies a collating sequence for alphanumeric data according to the following rules.

    • The order in which literals are defined is the order of a collating sequence.

    • Characters that are not explicitly specified are assumed to have values in the collating sequence that are greater than the explicitly specified characters. The order of unspecified characters is determined by the order of the relevant character set.

    • All literals must be alphanumeric or numeric. Each character in an alphanumeric literal represents an actual character in a character set.

      A numeric literal must be an unsigned integer. Each numeric literal value must be valid in a collating sequence.

    • A character cannot be specified more than once in the ALPHABET clause.

    • An alphanumeric literal associated with THROUGH or ALSO must be at least one byte.

      If THROUGH is specified, the consecutive characters in the character set beginning with the character specified in literal-1 and ending with the character specified in literal-2 become the collating sequence.

      For example, if "Z" THROUGH "A" is specified, the order for uppercase alphabetic characters is as follows.

      ZYXWVUTSRQPONMLKJIHGFEDCBA
    • If ALSO is specified, the characters specified in literal-1 and literal-3 are the same position in a collating sequence.

      For example, if "D" ALSO "N" ALSO "%" is specified, the characters D, N, and % are in the same position in a collating sequence.

    • A figurative constant cannot be specified.

The character that has the highest position in a collating sequence specified by the ALPHABET clause affects the value for a figurative constant HIGH-VALUE. If multiple characters have the highest position due to the specification of the ALSO phrase, the last character becomes the HIGH-VALUE character.

Likewise, the character that has the lowest position in a collating sequence becomes the LOW-VALUE character. If multiple characters exist in the same position due to the specification of the ALSO phrase, the first character becomes the LOW-VALUE character.

1.3.2. CLASS Clause

The CLASS clause relates the specified character set to class-name.

  • CLASS class-name-1 IS

    Defines the character set specified in the clause through class-name-1. Class-name-1 can only be referenced from a class-condition.

  • literal-4, literal-5

    • Only numeric and alphanumeric literal can be used.

    • A floating-point literal cannot be used.

    • If the THROUGH clause is used, literal-4 and literal-5 must be a character with a length of 1.

1.3.3. DECIMAL-POINT IS COMMA Clause

The DECIMAL-POINT IS COMMA clause exchanges the functions of the period and the comma in PICTURE character strings and numeric literals.

  • DECIMAL-POINT IS COMMA

2. Input-Output Section

The Input-Output section determines the file organization and access methods. For more details, refer to ORGANIZATION Clause and ACCESS MODE Clause.

The Input-Output section must be defined in the Environment division and includes the following two paragraphs:

figure ed input output section
Input-Output Section Format
  • FILE-CONTROL

    • The FILE-CONTROL keyword identifies the FILE-CONTROL paragraph. This keyword can be specified only once, at the beginning of the FILE-CONTROL paragraph.

    • The FILE-CONTROL paragraph can be omitted if no file exists in a program, even if FILE-CONTROL is specified.

    • The FILE-CONTROL paragraph specifies physical files.

  • I-O-CONTROL

    • The I-O-CONTROL keyword identifies the I-O-CONTROL paragraph.

    • The I-O-CONTROL paragraph specifies information that is necessary for effective data transfer between COBOL programs and external data sets.

2.1. FILE-CONTROL Paragraph

The FILE-CONTROL paragraph associates each file in a COBOL program with an external data set, and specifies information such as file organization and access methods.

The following table lists available file organizations and access methods.

File Organization Access Method

Sequential

Non-VSAM, VSAM

Relative

VSAM

Indexed

VSAM

Line sequential

Text stream I-O

The FILE-CONTROL paragraph starts with the FILE CONTROL keyword followed by a period (.).

The FILE-CONTROL paragraph must include one entry for each file described with an FD or SD in the data division. In each entry, the SELECT clause must appear first. The other clauses can appear in any order.

The following figure shows the formats for the FILE-CONTROL paragraph.

  • Sequential file entries

    figure ed file control format1
    FILE-CONTROL Format 1
  • Indexed file entries

    figure ed file control format2
    FILE-CONTROL Format 2
    figure ed file control format2 entry1
    FILE-CONTROL Format 2 - entry
  • Relative file entries

    figure ed file control format3
    FILE-CONTROL Format 3
  • Line-sequential file entries

    figure ed file control format4
    FILE-CONTROL Format 4

2.1.1. SELECT Clause

The SELECT clause defines a file identifier for a COBOL program.

Item Description

SELECT OPTIONAL

Syntax checked. SELECT has the same function.

file-name-1

Must be identified with an FD or SD in the data division.

Must follow the rules for COBOL user-defined names.

Must include at least one alphabetical character, and cannot use names that are duplicated in the current program.

2.1.2. ASSIGN Clause

The ASSIGN clause associates a file name with an actual external data set.

Item Description

assignment-name-1

Specifies an external data set name.

Specifies a name or file path described in a JCL DD statement.

If the file is a sort or merge file, it is treated as comments.

2.1.3. ORGANIZATION Clause

The ORGANIZATION clause identifies the logical structure for a file. The logical structure is determined when a file is created, and cannot be changed.

  • ORGANIZATION IS SEQUENTIAL (format 1)

  • ORGANIZATION IS INDEXED (format 2)

  • ORGANIZATION IS RELATIVE (format 3)

  • ORGANIZATION IS LINE SEQUENTIAL (format 4)

If the ORGANIZATION clause is omitted, the compiler assumes ORGANIZATION IS SEQUENTIAL.

The data organization must be established when a file is created. After the file has been created, it can be extended, but the organization cannot be changed.

  • Sequential organization

    • The physical order of records is the actual order of records. The relationship between records is not changed even if the file is extended.

    • Records can be fixed length or variable length.

    • There are no keys.

  • Indexed organization

    • Each record in a file has one or more internal keys (key data items). Each key has an index with which a specific record can be searched according to the contents in an internal key data item.

    • Records can be fixed length or variable length.

    • Each record must include a prime key data item.

      When a record is inserted, updated, or deleted, it can be searched using a prime key. Therefore, the prime key data item must be unique and cannot be changed even if the record is updated. A prime key data item can be used by being described in the RECORD KEY clause of the FILE-CONTROL paragraph.

    • Each record can have one or more alternate key data items.

      A record to be read can be identified with an alternate key. An alternate key data item can be used by describing it in the ALTERNATE RECORD KEY clause of the FILE-CONTROL paragraph.

  • Relative organization

    • Each record is identified by a relative record number. Relative record numbers are not included in records.

    • An access method saves and gets records based on relative record numbers.

    • The physical order of records in a file is not related to each record’s relative record number.

    • Records can be fixed length or variable length.

  • Line-sequential organization

    • Each record ends with a record delimiter. The delimiter is not counted in the length of the record.

    • When a record is written in a file, trailing blanks are removed and a record delimiter is added.

    • When a record is read, the record delimiter is removed and the remaining part of the record (after EOF) is filled with blanks.

    • The new line character is a delimiter.

The compiler does not directly provide indexed organization or relative organization. However, the organizations are supported if the compiler is integrated with the OpenFrame file system.

2.1.4. ACCESS MODE Clause

The ACCESS MODE clause defines which records in a file can be accessed.

  • ACCESS MODE IS SEQUENTIAL

    Can be specified in all formats.

    Format Description

    Format 1: Sequential

    Records in a file can be accessed with the sequence created when the file is created or extended.

    Format 1 only supports sequential access.

    Format 2: Indexed

    Records in a file can be accessed in the sequential order of ascending record keys.

    Format 3: Relative

    Records in a file can be accessed in the sequential order of relative record numbers.

    Format 4: Line-sequential

    Records in a file can be accessed with the sequence created when the file is created or extended.

    Format 4 only supports sequential access.

  • ACCESS MODE IS RANDOM

    Can be specified in format 2 and format 3.

    Format Description

    Format 2: Indexed

    Records can be accessed according the value of the record key data item.

    Format 3: Relative

    Records can be accessed according the value of the relative key data item.

  • ACCESS MODE IS DYNAMIC

    Can be specified in format 2 and format 3.

    Format Description

    Format 2: Indexed

    Records in a file can be sequentially or randomly accessed based on input-output statements.

    Format 3: Relative

    Records in a file can be sequentially or randomly accessed based on input-output statements.

2.1.5. RECORD KEY Clause

The RECORD KEY clause (format 2) specifies the data item that defines the prime RECORD KEY in an indexed file. The prime RECORD KEY data item must be unique.

  • data-name-2

    • The prime RECORD KEY data item.

    • Must be described in a record description entry of a file.

      The data categories are as follows:

      • Alphanumeric

      • Numeric

      • Numeric-edited

      • Alphanumeric-edited

      • Alphabetic

      • External floating-point

      • Internal floating-point

      • DBCS

    • data-name-2 cannot reference a group item that includes a variable-occurrence data item. data-name-2 can be qualified.

    • data-name-2’s data description and relative position in a record must be the same as when the file was defined.

2.1.6. ALTERNATE RECORD KEY Clause

The ALTERNATE RECORD KEY clause (format 2) specifies the data item that defines the alternative RECORD KEY in an indexed file.

  • data-name-3

    • The ALTERNATE RECORD KEY data item.

    • Must be described in a record description entry of a file.

      The data categories are as follows:

      • Alphanumeric

      • Numeric

      • Numeric-edited

      • Alphanumeric-edited

      • Alphabetic

      • External floating-point

      • Internal floating-point

      • DBCS

    • data-name-3 cannot reference a group item that includes a variable-occurrence data item. data-name-3 can be qualified.

    • data-name-2’s data description and relative position in a record must be the same as those at the time a file is defined.

If the DUPLICATES phrase is not specified, the contents referenced by the ALTERNATE RECORD KEY data item must be unique in a file.

2.1.7. RELATIVE KEY Clause

The RELATIVE KEY clause (format 3) identifies the data item that specifies the relative file’s relative record number.

Item Description

data-name-4

Must be an unsigned integer data item and must not include the symbol P in the PICTURE phrase.

data-name-4 cannot be described in a record description entry of a file. That is, RELATIVE KEY is not a part of a record.

data-name-4 can be qualified.

data-name-4 is only required for ACCESS IS SEQUENTIAL to use the START statement. It is always required for ACCESS IS RANDOM and ACCESS IS DYNAMIC.

2.1.8. FILE STATUS Clause

The FILE STATUS clause monitors the execution of input-output statements. If the FILE STATUS clause is specified, the result of an input-output operation for a corresponding file is saved in the file status key data item.

Item Description

data-name-1

The file status key data item can be defined with one of the following in the working-storage, local-storage, or linkage section.

  • A two-character alphanumeric data item.

  • A two-character numeric data item with usage DISPLAY.

data-name-1 must not include the PICTURE symbol 'P'.

data-name-1 can be qualified.

data-name-1 cannot be placed in a variable position. That is, it cannot follow a data item that includes an OCCURS DEPENDING ON clause.

data-name-8

Syntax checked, but not used.

2.2. I-O-CONTROL Paragraph

The I-O-CONTROL paragraph is used when different files share storage areas.

figure ed io control
I-O-CONTROL Paragraph

2.2.1. SAME AREA Clause

The SAME AREA clause allows two or more files to use the same record buffer space. The files do not need to have the same organization or access mode.

Item Description

filename-3, file-name-4

Must be specified in the file-control paragraph of the same program.

The EXTERNAL clause must not be specified.