Friday, November 18, 2011

Divisions in cobol


There are four divisions in a COBOL program and Data division is optional.
1.Identification Division.
2.Environment Division.
3.Data Division.
4.Procedure Division.

Identification Division.
This is the first division and the program is identified here. Paragraph PROGRAM-ID followed by user-defined name is mandatory. All other paragraphs are optional and used for documentation. The length of user-defined name for IBM COBOL is EIGHT.

IDENTIFICATION DIVISION.
PROGRAM-ID.          PROGRAM NAME.
AUTHOR.                 COMMENT ENTRY.
DATE-WRITTEN.       COMMENT ENTRY.
DATE-COMPILED.      COMMENT ENTRY.
SECURITY.               COMMENT ENTRY.

Security does not pertain to the operating system security, but the information that is passed to the user of the program about the security features of the program.

Environment Division.
Only machine dependant division of COBOL program. It supplies information about the hardware or computer equipment to be used on the program. When your program moves from one computer to another computer, the only section that may need to be changed is ENVIRONMENT division. 

Configuration Section.
It supplies information concerning the computer on which the program will be compiled (SOURCE-COMPUTER) and executed (OBJECT-COMPUTER). It consists of three paragraphs – SOURCE COMPUTER, OBJECT-COMPUTER and SPECIAL-NAMES.
This is OPTIONAL section from COBOL 85.

SOURCE-COMPUTER. IBM-4381 (Computer and model # supplied by manufacturer)
                           WITH DEBUGGING MODE clause specifies that the debugging lines in the program (statements coded with ‘D’ in column 7) are compiled.

OBJECT-COMPUTER. IBM-4381          (Usually same as source computer)


Input-Output Section.
It contains information regarding the files to be used in the program and
it consists of two paragraphs FILE-CONTROL & I-O CONTROL.
 FILE CONTROL. Files used in the program are identified in this paragraph.
I-O CONTROL.  It specifies when check points to be taken and storage areas that are shared by different files.

Data Division.
Data division is used to define the data that need to be accessed by the program. It has three sections.
FILE SECTION                              describes the record structure of the files.
WORKING-STORAGE SECTION        is used to for define intermediate variables.
LINKAGE SECTION                        is used to access the external data.
Ex: Data passed from other programs or from PARM of JCL

LINKAGE SECTION


It is used to access the data that are external to the program. JCL can send maximum 100 characters to a program thru PARM. Linkage section MUST be coded with a half word binary field, prior to actual field. If length field is not coded, the first two bytes of the field coded in the linkage section will be filled with length and so there are chances of 2 bytes data truncation in the actual field.
01 LK-DATA.
          05 LK-LENGTH           PIC S9(04) COMP.
          05 LK-VARIABLE        PIC X(08).
LINKAGE section of sub-programs will be explained later
Procedure Division.
This is the last division and business logic is coded here. It has user-defined sections and paragraphs. Section name should be unique within the program and paragraph name should be unique within the section.



No comments:

Post a Comment