Application programming on z/OS
Previous topic | Next topic | Contents | Glossary | Contact z/OS | PDF


COBOL program format

Application programming on z/OS

With the exception of the COPY and REPLACE statements and the end program marker, the statements, entries, paragraphs, and sections of a COBOL source program are grouped into four divisions.

  • IDENTIFICATION DIVISION, which identifies the program with a name and, if you want, gives other identifying information.
  • ENVIRONMENT DIVISION, where you describe the aspects of your program that depend on the computing environment.
  • 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.
  • 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.

Example of COBOL divisions

Figure 1. IDENTIFICATION DIVISION
 IDENTIFICATION DIVISION.
Program-ID. Helloprog.
Author. A. Programmer.
Installation.  Computing Laboratories.
Date-Written.  08/21/2002.

Example of input-output coding

Figure 2. ENVIRONMENT DIVISION
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.
Explanations of the user-supplied information follow Figure 3.
Figure 3. Input and output files in FILE-CONTROL
 IDENTIFICATION DIVISION.
. . .
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT filename ASSIGN TO assignment-name 
    ORGANIZATION IS org ACCESS MODE IS access 
    FILE STATUS IS file-status 
. . .
DATA DIVISION.
FILE SECTION.
FD  filename
01  recordname 
    nn . . . fieldlength & type 
    nn . . . fieldlength & type
. . .
WORKING-STORAGE SECTION
01 file-status PICTURE 99.
. . .
PROCEDURE DIVISION.
    . . .
    OPEN iomode filename 
    . . .
    READ filename
    . . .
    WRITE recordname
    . . .
    CLOSE filename
    . . .
    STOP RUN.
  • org indicates the organization, which can be SEQUENTIAL, LINE SEQUENTIAL, INDEXED, or RELATIVE.
  • access indicates the access mode, which can be SEQUENTIAL, RANDOM, or DYNAMIC.
  • iomode is for INPUT or OUTPUT mode. If you are only reading from a file, code INPUT. If you are only writing to it, code OUTPUT or EXTEND. If you are both reading and writing, code I-O, except for organization LINE SEQUENTIAL.
  • Other values like filename, recordname, fieldname (nn in the example), fieldlength and type are also specified.




Copyright IBM Corporation 1990, 2010