Tags

, , , , , , ,

COBOL program format

IDENTIFICATION DIVISION, which identifies the program with a name and, if you want, gives other identifying information.

IDENTIFICATION DIVISION.

Program-ID. Helloprog.

Author. A. Programmer.

Installation. Computing Laboratories.

Date-Written. 08/21/2002.

ENVIRONMENT DIVISION, where you describe the aspects of your program that depend on the computing environment.

The configuration section is an optional section for programs and classes, and can describe the computer environment on which the program or class is compiled and executed.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

 SOURCE-COMPUTER. computer-name.

 OBJECT-COMPUTER. computer-name.

 SPECIAL-NAMES.   special-names-entries.

INPUT-OUTPUT SECTION.

FILE-CONTROL.

SELECT [OPTIONAL] file-name-1   ASSIGN TO system-name [FOR MULTIPLE {REEL | UNIT}]   […. .  I-O-CONTROL.   SAME [RECORD] AREA FOR file-name-1 … file-name-n.

DATA DIVISION, where the characteristics of your data are defined in one of the following sections in the DATA DIVISION:

    • FILE SECTION, to define data used in input-output operations
    • LINKAGE SECTION, to describe data from another program.

When defining data developed for internal processing:

    • WORKING-STORAGE SECTION, to have storage statically allocated and remain for the life of the run unit.
    • LOCAL-STORAGE SECTION, to have storage allocated each time a program is called and de-allocated when the program ends.
    • LINKAGE SECTION, to describe data from another program.

DATA DIVISION.

FILE SECTION.

FD filename  01 recordname   nn . . . fieldlength & type   nn . . . fieldlength & type  . . .

WORKING-STORAGE SECTION

01 file-status PICTURE 99.  . . .

PROCEDURE DIVISION, where the instructions related to the manipulation of data and interfaces with other procedures are specified.

The PROCEDURE DIVISION of a program is divided into sections and paragraphs, which contain sentences and statements, as described here:

    • Section – a logical subdivision of your processing logic. A section has a section header and is optionally followed by one or more paragraphs. A section can be the subject of a PERFORM statement. One type of section is for declaratives.

Declaratives are a set of one or more special purpose sections, written at the beginning of the PROCEDURE DIVISION, the first of which is preceded by the key word. DECLARATIVES and the last of which is followed by the key word END DECLARATIVES.

    • Paragraph – a subdivision of a section, procedure, or program. A paragraph can be the subject of a statement.
    • Sentence – a series of one or more COBOL statements ending with a period.
    • Statement – a defined step of COBOL processing, such as adding two numbers.
    • Phrase – a subdivision of a statement.

PROCEDURE DIVISION.

. . .

OPEN iomode filename

. . .

READ filename

. . .

WRITE recordname

. . .

CLOSE filename

. . .

STOP RUN.

————————————————————————————————————

If you would like to Earn Free Stocks, Credit card Points and Bank account Bonuses, Please visit My Finance Blog