Sie sind auf Seite 1von 8

COBOL PROGRAMMING STRUCTURE AND PROCEDURE

DIVISION

A COBOL program structure consists of divisions as shown in the


given below:

Program

Divisions

Sections

Paragraphs

Sentences

Statements

Characters
acter
CHARACTERS

Characters are the lowest in the hierarchy and cannot be


divisible. The alphabet of cobol is called the character set.
STATEMENTS

A Statements consists of a COBOL verb and an operand or


operands describes about COBOL verb process on the operands
either it may be a condition or unconditional

There are four categories of statements in COBOL

Imperative
Conditional
Delimited scope
Compiler directing

Example:

ADD A TO B GIVING C

SENTENCES

Sentences are the combination of one or more statements.


Sentences appear only in the procedure division. A sentence must
end with a period.

Example:

MOVE A TO TEMP

MOVE B TO A

MOVE TEMP TO B.
PARAGRAPHS

Paragraphs are the subdivision of a section or division. It is


either user-defined or a predefined name followed by a period, and
consists of zero or more sentences or entries.

Syntax:

Paragraph-name.

SECTIONS

Sections are the logical subdivision of program logic. A section


is a collection of paragraphs.

Syntax:

{section-name} SECTION.

DIVISIONS

A division is a block of code, which contains one or more


sections or set of sections or set of sentences or a block of
statements.

COBOL program consists of four divisions

IDENTIFICATION DIVISION
ENVIRONMENT DIVISION
DATA DIVISION
PROCEDURE DIVISION

IDENTIFICATION DIVISION

The IDENTIFICATION DIVISION consists of a standard


paragraphs showing the name of the program,name of its author
,date on which the program is compiled and similar information.It is
the first division of every COBOL source program. In this
division,PROGRAM-ID is the only mandatory paragraph.
PROGRAM ID specifies the program name that can consist 1 to 30
characters.

EXAMPLE

IDENTIFICATION DIVISION.

PROGRAM ID. HELLO.

PROCEDURE DIVISION.

DISPLAY welcome to Tutorialspoint.

STOP RUN.

ENVIRONMENT DIVISION

Environment division is used to specify input and output files to the


program. It consists of two sections

i. CONFIGURATION SECTION
ii. INPUT AND OUTPUT SECTION
i. CONFIGURATION SECTION
It provides information about the system on which the
program is written and executed. It consists of two
paragraphs
Source computer is used to compile the program.
Object computer is used to execute the program.
ii. INPUT AND OUTPUT SECTION
It provides information about the files to be used in the
program. It consists of two paragraphs
File control : Provides information of external data sets used
in the program.
I-O control : Provides information of files used in the program.

DATA DIVISION

Data division is used to define the variables used in the program. It


consists of four sections:

i. File section is used to define the record structure of the


file.
ii. Working-Storage section is used to declare temporary
variables and file structures which are used in the
program.
iii. Local-Storage section is similar to Working-Storage
section. The only difference is that the variables will be
allocated and initialized every time program a starts
execution.
iv. Linkage section is used to describe the data names that
are received from an external program.
PROCEDURE DIVISION

Procedure division is used to include the logic of the program. It


consists of executable statements using variables defined in the data
division. In this division, paragraph and section names are user-
defined.

The last statement to end the execution in this division is


either STOP RUN which is used in the calling programs or EXIT
PROGRAM which is used in the called programs.

PROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTCOBL.
AUTHOR. TESTTEST.
DATE-WRITTEN. 19-NOV-2010.
DATE-COMPILED.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT WS-INFILE ASSIGN TO INPIWS01
FILE STATUS IS WS-INFILE-SW.
DATA DIVISION.
FILE SECTION.
FD WS-INFILE.
01 INP-EMP-REC.
05 INP-EMPID PIC X(08).
05 INP-EMPID PIC X(08).
05 INP-EMP-NAME PIC X(15).
05 INP-EMP-LOB PIC X(10).
05 FILLER PIC X(47).
WORKING-STORAGE SECTION.
01 WS-INFILE-SW PIC X(02) VALUE SPACES.
88 WS-INFILE-SUCESS VALUE '00'.
88 WS-INFILE-EOF VALUE '10'.
01 WS-INP-EMP-REC.
05 WS-INP-EMPID PIC X(08).
05 WS-INP-EMP-NAME PIC X(15).
05 WS-INP-EMP-LOB PIC X(10).
05 FILLER PIC X(47).
01 WS-EOF-SW PIC X(01) VALUE 'N'.
88 WS-EOF-NO VALUE 'N'.
88 WS-EOF-YES VALUE 'Y'.
PROCEDURE DIVISION.
A1000-MAIN-PARA.
PERFORM A2000-OPEN-PARA THRU A200-EXIT.
PERFORM A3000-INPUT-PARA THRU A300-EXIT.
PERFORM A4000-INSERT-PARA THRU A400-EXIT.
PERFORM A5000-CLOSE-PARA THRU A500-EXIT.
STOP RUN.
A100-EXIT.
EXIT.
A2000-OPEN-PARA.
INITIALIZE WS-INFILE-SW WS-INP-EMP-REC WS-EOF-SW.
OPEN OUTPUT WS-INFILE
IF WS-INFILE-SUCESS
DISPLAY "FILE OPEN SUCCESSFUL"
ELSE
DISPLAY "FILE OPENING ERROR"
GO TO A100-EXIT
END-IF.
A200-EXIT.
EXIT.
A3000-INPUT-PARA.
ACCEPT WS-INP-EMPID.
ACCEPT WS-INP-EMP-NAME.
ACCEPT WS-INP-EMP-LOB.
DISPLAY WS-INP-EMPID WS-INP-EMP-NAME WS-INP-EMP-LOB.
A300-EXIT.
EXIT.
A4000-INSERT-PARA.
WRITE INP-EMP-REC FROM WS-INP-EMP-REC.
A400-EXIT.
EXIT.
A5000-CLOSE-PARA.
CLOSE WS-INFILE.
A500-EXIT.
EXIT.

Das könnte Ihnen auch gefallen