The ENVIRONMENT DIVISION contains:
CONFIGURATION SECTION
INPUT-OUTPUT SECTION
In the CONFIGURATION SECTION, for describing the aspects of the program that depend on the computing environment:
computer for compiling the program (SOURCE-COMPUTER paragraph)
computer for running the program (OBJECT-COMPUTER paragraph)
special items such as the currency sign and symbolic characters (SPECIAL-NAMES paragraph)
user-defined classes (REPOSITORY paragraph)
The INPUT-OUTPUT SECTION is for:
declaration of files, connect them to external data sets (FILE-CONTROL paragraph)
controlling buffering, checkpointing, common areas (I-O-CONTROL paragraph)
Originally, it defined for which platform the code was compiled (IBM, Honeywell, Univac, Burroughs etc.). Today the compiler does not create separate code versions therefore the computer-name is not used during the process but the paragraph is syntax-checked.
The existence of the optional part is important:
normal mode (the marked debugging lines are treated as comments)
debugging mode (the marked debugging lines are compiled)
Debugging line:
marked with a D letter in the 7th column
the mark can be used everywhere after the SOURCE COMPUTER paragraph but not in the IDENTIFICATION DIVISION
if contains only spaces in Area A and Area B, will be treated as a blank line
always must be correct so changing the mode does not cause compilation error
The presence of debugging mode is determined after all COPY and REPLACE statements are processed.
The SOURCE-COMPUTER paragraph cannot be specified in a function prototype definition.
EXAMPLE FOR SYNTAX OF SOURCE-COMPUTER PARAGRAPH:
The computer-name - similarly to the SOURCE COMPUTER - is old and unnecessary but for syntax only it is checked.
The memory size specifies the amount of main storage needed to run the object program, unit of words, characters or modules. If exists, also syntax-checked only.
The collating sequence is the only part having effect on the program; can be found in older and special codes only, determines what character-sorting rule must be used (e.g. A smaller than B, upcase vs. downcase, what is the order of SPACE and 0-9 and A-Z). It has effect in:
alphanumeric comparisons (A < B, NAME > "K")
in level-88 conditions based on alphanumeric values
SORT and MERGE key (if those are defined with the DISPLAY word, unless COLLATING SEQUENCE phrase is specified in the MERGE or SORT statement)
Default is EBCDIC (if not defined specifically), alternative is ASCII.
Does not apply to DBCS or NATIONAL data items.
The segment limit is again syntax-checked only. The priority number is in [1, 49]; all sections with priority-numbers 0 through 49 are fixed permanent segments. Segmentation is not supported for programs compiled with the THREAD option.
The SOURCE-COMPUTER paragraph cannot be specified in a function prototype definition.
EXAMPLE FOR SYNTAX OF OBJECT-COMPUTER PARAGRAPH:
Its task is to
create a more verbal wording within the program
hide the original system components from the program (in case the system changes, only the SPECIAL NAMES must be reviewed)
EXAMPLE FOR SYNTAX OF SPECIAL-NAMES PARAGRAPH:
Mnemonic-name-1: connects a freely defined word by the developer to a pre-defined word (environment-name-1) in the system; can be more defined (here the syntax shows one line only).
Will be used in ACCEPT, DISPLAY and WRITE ADVANCING statements.
Its task is to
create a more verbal wording within the program
hide the original system components from the program (in case the system changes, only the SPECIAL NAMES must be reviewed)
EXAMPLE FOR DEFINITION OF MNEMONIC NAMES 1:
Mnemonic-name-2: another mapping to developer-defined word but this is for UPSI-0, ..., UPSI-9 switches; can be more defined (here the syntax shows one line only).
This can be later used in SET and IF statements.
UPSI switches were used in older mainframe systems for configuration marks.
EXAMPLE FOR DEFINITION OF MNEMONIC NAMES OF SWITCHES:
The ALPHABET defines a character set or collating sequence, mapped to a developer-defined name. Not used in modern COBOL development.
Options:
STANDARD‑1 (ASCII)
STANDARD‑2 (International Reference Version of ISO/IEC 646, 7-bit coded character set)
NATIVE (specifies the native character code set, if the ALPHABET clause is omitted, EBCDIC is assumed)
EBCDIC (itself)
literal, phrase (own sorting rule; rare)
Can be used in
PROGRAM COLLATING SEQUENCE
SORT, MERGE
alphanumeric comparisons
SYMBOLIC CHARACTERS: maps a character from a character set to a developer-defined name; can be more defined (here the syntax shows one line only). Rarely used nowadays.
This character can be used in IF, MOVE, STRING etc. statements.
Cannot be specified in a function prototype definition.
EXAMPLE FOR DEFINITION OF SYMBOLIC CHARACTERS:
CURRENCY SIGN: defines which character will be a currency sign, optionally giving a symbol to it as well.
If used, the CURRENCY and NOCURRENCY compiler options are ignored. If not used, the NOCURRENCY compiler option results the $ as default currency sign.
Rules without PICTURE SYMBOL:
must be a single character
must not be a figurative constant or a null-terminated literal
must not contain a DBCS character
must not contain 0..9, A, B, C, D, E, G, N, P, R, S, U, V, X, Z, their lowercase equivalents, SPACE, +-,.*/;()"='
can be f, h, i, j, k, l, m, o, q, t, w, y
Rules with PICTURE SYMBOL:
can consist of one or more characters
must not contain 0..9, +-.,
Rules for PICTURE SYMBOL:
must be an alphanumeric literal consisting of one single-byte character
must not contain a figurative constant, 0..9, A, B, C, D, E, G, N, P, R, S, U, V, X, Z, their lowercase counterparts, SPACE, +-,.*/;()"='
Used in
monetary systems
when in the PICTURE format a currency sign must be displayed
rarely in modern COBOL because the currency mark is written with DISPLAY
EXAMPLE FOR DEFINITION OF CURRENCY SIGN:
The DECIMAL-POINT definition is standard and sets the number description to European which means:
numbers in memory stays in original (US) format (of course without the thousand-sign)
literals will be understood in EU format
displayed numbers will be shown in EU format
E.g. in PICTURE clause PIC 9(3)V99 input-output format will be European
Formats:
US (1,234.56)
EU (1.234,56)
Examples:
COMPUTE X = 1,5 + 2,5 results 4,0 (literals)
in PICTURE clause PIC 9(3)V99 input-output format will be EU
in DISPLAY/WRITE statements the format will be EU
Used in European systems.
With the CLASS clause it is possible to create character classes.
Used in IF, EVALUATE, STRING/UNSTRING, VALIDATION statements.
Used rarely because it is better to use explicit IFs, but very useful in data validation.
The THROUGH and THRU are equivalent; the order of the edge values can be either ascending and descending.
EXAMPLE FOR CLASS DEFINITION:
XML‑SCHEMA: helps to process XMLs (XML PARSE, XML GENERATE):
which XML schema file (XSD) should be used
where is this schema file (DDNAME or environment variable)
EXAMPLE FOR DEFINITION OF XML SCHEMA:
EXAMPLE FOR SYNTAX OF REPOSITORY PARAGRAPH:
A CLASS maps an external (Java) class which will be available in the program. This can be a reference to
a Java class as type of an object
a Java class as element type of an array
In case the object type is not specified along with the array name, the element type will be Object.
In COBOL, all Java methods of the mapped class will be available:
the contructor will be invoked as "new"
a method will be invoked as "methodName"
the order of the arguments corresponds to the original Java method argument order
The COBOL array corresponds to a Java array (therefore it is not part of the Java Collection Framework):
the fix length and the element type must be defined
elements can be accessed by their index, starting with zero
the invoked "set" will set a value to the accessed element
the invoked "get" will get the value of the accessed element
In the background the COBOL uses a Java wrapper which maps data types, method names to the corresponding Java types.
EXAMPLE FOR AN INMUTABLE JAVA CLASS:
EXAMPLE FOR REPOSITORY CLASS MAPPING TO JAVA CLASS:
It is possible to leave the FUNCTION keyword of specific functions, or leave all together. This possibility is available for COBOL built-in functions as well as own functions.
The ALL option refers to the built-in functions only, for the own names they must be defined one-by-one.
When leaving FUNCTION keyword for own function names, they can not be LENGTH, RANDOM, SIGN, SUM, or WHEN-COMPILED.
EXAMPLE FOR LEAVING SPECIFIC FUNCTION NAMES:
EXAMPLE FOR LEAVING ALL BUILT-IN FUNCTION NAMES ONLY:
EXAMPLE FOR LEAVING OWN FUNCTION NAMES ONLY:
Defines the program which external files will access and by what I/O rules.
EXAMPLE FOR A FULL INPUT-OUTPUT SECTION:
The FILE-CONTROL paragraph defines that the COBOL program which external files and how it uses, and where will it write the operation status codes.
EXAMPLE FOR SYNTAX OF FILE CONTROL PARAGRAPH:
The SELECT defines the inner (logical) name the program will use inside. The FILE-CONTROL paragraph contains one or more SELECT sentences. Every SELECT describes a file.
The ASSIGN connects the logical file name to the real external file. This is platform-dependent:
z/OS alatt DDNAME
mainframe batch alatt JCL DD
Windows/Unix alatt fájlnév
EXAMPLE FOR ASSIGN CLAUSES ABOVE DIFFERENT PLATFORMS:
The RESERVE reserves buffer for the file; only for SEQUENTIAL files. The integer defines that how many bufferblocks will be reserved for the file.
The ORGANIZATION organizes the file on physical level:
SEQUENTIAL (readable-writeable in sequential order)
RELATIVE (relative recordfile; based on number of records)
INDEXED (indexed file; with record key)
LINE SEQUENTIAL (text lines; LF/CRLF)
PADDING: if a record is shorter, extends the rest of the space with the character defined with it. Only for LINE SEQUENTIAL files.
EXAMPLE FOR PADDING CLAUSE:
The RECORD DELIMITER defines practically the line-end marker:
STANDARD-1 (LF; Unix)
STANDARD-2 (CRLF; Windows)
The ACCESS MODE defines the variant of file access:
SEQUENTIAL (sequentially)
RANDOM (by key/index)
DYNAMIC (hybrid; read/write in any order)
The RECORD KEY defines the main index when the file is INDEXED. The LENGHT is rarerly used.
EXAMPLE FOR RECORD CLAUSE:
The ALTERNATE RECORD KEY defines the secondary key in case of an INDEXED file. The optional DUPLICATES shows that the key con contain duplicates.
EXAMPLE FOR ALTERNATE RECORD KEY CLAUSE:
The RELATIVE KEY defines the field containing the number of record in case of a RELATIVE file.
EXAMPLE FOR RELATIVE KEY CLAUSE:
The PASSWORD is an old clause, for a protected file.
EXAMPLE FOR PASSPORT CLAUSE:
The FILE STATUS defines the data target into which COBOL will write the result code of file operations.
EXAMPLE FOR FILE STATUS CLAUSE:
The I-O CONTROL paragraph defines the file management rules of the COBOL program e.g. buffering, common record areas, restarting (rerun) during running.
EXAMPLE FOR SYNTAX OF I-O CONTROL PARAGRAPH:
The RERUN clause activates the COBOL checkpoint/rerun mechanism: writes checkpoint with a frequency (in case the program has a break, continues from the last checkpoint, useful at big batch processes).
EXAMPLE FOR RERUN CLAUSE:
The SAME AREA clause exists by syntax but does nothing. In old COBOLs handled memory sharing.
The SAME RECORD AREA clause defines that the given files will use the same record buffer area for their operations:
needs less memory
can be dangerous as one operation can overwrite data for an operation of the other file
The SAME SORT AREA clause exists by syntax but does nothing. In old COBOLs optimalized sort/merge.
The SAME SORT-MERGE AREA clause has no effect either.
The MULTIPLE FILE TAPE clause was for mainframe tape systems; more logical COBOL files physically on the same tape so COBOL knows the tape should not be mounted to reach the other file.
The APPLY WRITE-ONLY clause optimizes buffer and device space allocation for variable-length, blocked, sequential files. Use it when the file is
SEQUENTIAL
variable-length
blocked
for writing only
The operations will
use less buffer
have faster writing speed
have less I/O overhead
EXAMPLE FOR APPLY WRITE-ONLY CLAUSE: