Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 3: COBOL Program structure


COBOL- program structure

COBOL Program Structure is represented using diagram as shown below:-

Explanation for above given Structure is as follows:-

Program

  • Every COBOL Source program is made up of 4 divisions. No code can be written outside these divisions.

Division

  • A division may contain one or more sections or paragraphs.
  • The names of these divisions are predefined by language and cannot be changed
  • All these divisions must begin in Margin A and can be continued to Margin B of Coding Sheet
  • Each division can be started by specifying division name and it ends at the beginning of the next division or end of program
  • There are 4 divisions in COBOL
    1. IDENTIFICATION DIVISION :- This division is used to identify program to operating system and also provides documentation details about the program
    2. ENVIRONMENT DIVISION :- This division is used to define input/output file names and to describe devices used to store them
    3. DATA DIVISION :- This division is used to describe input and output format of data in files. Also, this can be used to define any constants and work areas
    4. PROCEDURE DIVISION :- This is the division, where programmer writes program logic
  • Note:- Each of these divisions will be explained in detail in later modules

Section

  • A section may contain one or more paragraphs
  • Few section are pre-defined by language. We can also code user-defined section in Procedure Division.
  • All section must begin in Margin A and can be continued to Margin B of Coding Sheet
  • Section begin with the section name and ends at the beginning of another section, division; If section is specified in PROCEDURE DIVISION it can end at the end of PROCEDURE DIVISION or at the key words END DECLARATIVES in the declaration portion of the PROCESURE DIVISION
  • Example:-
    FILE SECTION. <-- Pre-defined section <file-entries> EMPLOYEE SECTION. <-- user-defined section <user-defined statement>

Paragraph

  • A paragraph may contain one or more statements terminated by period (.)
  • Few paragraphs are pre-defined by language. We can also code user-defined paragraphs in PROCEDURE DIVISION
  • All paragraphs must begin in Margin A and cane be continued to Margin B of coding Sheet
  • Paragraphs begin with paragraph name and ends at the beginning of another paragraph, section, division; It also ends at the end of program. There are few other statements also available to end paragraphs which will be explained in later modules
  • Example:-
    PROGRAM-ID. <-- Example of Pre-defined paragraph 1000-EMP-PARA. <-- Example of User-defined paragraph

Sentence

  • A sentence may contain one or more statements terminated by period (.)
  • All sentences must be coded within Margin B of Coding Sheet
  • Example of Sentence:-
    MOVE DATA-A TO DATA-B MOVE DATA-B TO DATA-C MOVE DATA-C TO DATA-A.
  • In above example, we coded three statements and terminated last statement with period sign (.). Thus this three lines of code can be considered as single sentence

Statement

  • A statement may consists of one or more valid words and verbs
  • Generally, statement has a COBOL Verb followed by operand or operands. Statement can be considered as stand-alone instruction
  • All statements must be coded within Margin B of codding sheet
  • There are 4 types of statements in COBOL language:-
    1. Imperative statements :- Imperative statements are those which indicate the specific unconditional action to be taken by the object program i.e. these statements are not having any conditions to execute.
      For example: - ‘MOVE A TO B’
    2. Compiler directive statements :- As the name suggests, the Compiler Directive statements direct the COBOL compiler and no corresponding statements are generated for this in the load module. ‘COPY’ and ‘USE’ statements are examples of Compiler directive statement
    3. Conditional statements :- A conditional statement specifies that the true or false value of the condition is to be determined. If the condition is true, the statement following condition are executed. If the condition is false, the subsequent statements dependent on true value of condition will be skipped. ‘IF’ and ‘EVALUATE’ statements are examples of conditional statements
    4. Delimited scope statements :- When a conditional statement(for example, IF statement) is ended with an explicit end verb scope terminator (for example, END-IF), the statement is called as Delimited scope statement

COBOL words, verbs

  • A COBOL word or verb comprise of one or more characters. They can be user-defined or pre-defined by language. For example ‘MOVE’, ‘ACCEPT’ are verb

Characters

  • Characters are lowest element in the COBOL program structure and cannot be divided further.
  • It may be Digits (0-9), Alphabets (A-Z), Space (b), Special characters (+  -  *  /  (  )  =  $  ;  “  >  < , .) etc. Complete list of character described in ‘Character Set’ article





© copyright mainframebug.com
Privacy Policy