COBOL Programing Structures

COBOL Programing Structures: The structure of COBOL programming is designed in an organized form using the hierarchical flow of control. The advantage of using a hierarchical control of flow is that all components of the hierarchical relationship don't need to present altogether; they can work as stand-alone components.

Hierarchy stands for a parent to child relationship amongst objects giving the ability to share data amongst elements.

COBOL programming structure is divided amongst these few divisions in the form of hierarchy.

1) DIVISION

2) SECTION

3) PARAGRAPH

4) SENTENCES

5) STATEMENT

6) CHARACTERS

 

COBOL Programing Structures

DIVISIONS

COBOL works on data encapsulation property, such that division is a set of codes that restrain one or more than one section.

Here the data is encapsulated(wrapped in lower sets)amongst different divisions. You can identify a division once you encounter the division name, and it ends before the beginning of the new division.

There are 4 types of data divisions in Cobol

1 ) Identification division

2 ) Environment division

3 ) Data division

4 ) Procedure division

1 ) Identification division – All the unique figures to identify a particular COBOL program, i.e., program name , author , installation , Date – written , date – compiled can be added here in this section.

But most importantly PROGRAM – ID is a keyword that must be coded immediately after IDENTIFICATION DIVISION tag and every COBOL program consist of one PROGRAM – ID.

2 ) Environment division – This is an optional division, and it holds the record about all the compiler, devices  and computers, that are going to work while executing the program. This division also holds the record about the environment in which the program is running, and it also contains information regarding all the input and output source required in the program. This division divide amongst two section INPUT _ OUTPUT SECTION and CONFIGURATION SECTION.

3 ) Data division – One of the main division where all the data items of the program are stated  along with their  name, decimal point storage format, and length.

Data division is further sub – divided amongst 3 sections:

  • FILE SECTION – describes and store information related data input or output gained from an outside source
  • WORKING STORAGE SECTION – This section consists of information about variable used in program for data manipulation.
  • LINKAGE SECTION – It describes interconnection between two programs.

4) Procedure division – It contains the body of the program and it holds all the statements programmed m by programmer that will be executed

SECTIONS

Similarly, like divisions, sections are further subdivided into a smaller collection of a paragraph, which is nothing but a logical subdivision of program logic.

Section starts with a section name and ends with the name of next section to be started.

EXAMPLE =>

EMP_DTL SECTION.

PARAGRAPHS

As inherited, these smaller paragraphs are nothing but a smaller junction with zero or many sentences. These paragraphs are a user-defined or predefined portion of the section, followed by a period.

The user mostly constructs the data according to his needs.

Paragraph section starts with a paragraph name and ends with the name of next paragraph to be started.

EXAMPLE =>

PARAGRAPH – EMPL_ID

SENTENCES

Sentences are nothing but a combination of single or multiple statements that must end with a period and have a standard set of divisions.

EXAMPLE =>

MOVE Z TO TEMP
MOVE Q TO Z
MOVE TEMP TO Q.

STATEMENTS

Finally, after combining characters, these meaningful COBOL statements are solely responsible for the task and work to be processed provided by the user.

COBOL statement comprises of one or more variable, an operand, and an ending period.

EXAMPLE => ADD A  TO B GIVING D

CHARACTERS

These are the lowest set of words and keywords, which can’t be further divided. These are the basic building blocks of a complete program

just like alphabets in the ENGLISH language, combining these character turns to a meaningful sentence.

To run and compile the COBOL program, one must start from the same base level combining character to form statements. Further collecting statements to form sentences going up towards paragraph gaining more meaning throughout the process, and later forming sections and divisions if the programs exceed the limit.

SAMPLE PROGRAM -

This is a demo program to learn and understand the concept of different programming structures in COBOL and how to assign values and by displaying the result separately.

IDENTIFICATION DIVISION.
PROGRAM-ID. SAMP1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
PROCEDURE DIVISION.
DISPLAY ' SAMPLE PROGRAM EXECUTION STARTS HERE .  . . '.
PERFORM NEW-SEC-DISP.
STOP RUN.
NEW-SEC-DISP SECTION.
DISPLAY ' ENTERING INTO NEW SECTION . . . '.
PARAGRAPH.
DISPLAY ' ENTERING INTO PARAGRAPH . . . '.
STOP RUN.

THE OUTPUT WILL BE:

 SAMPLE PROGRAM EXECUTION STARTS HERE .  . . 
 ENTERING INTO NEW SECTION . . .
 ENTERING INTO PARAGRAPH . . .

Here in this program, we have assigned few variables with different values and later manipulating the output using different programing structures to make you clear about the different concepts related STRUCTURES.

 With this program and output, you will be able to understand how convenient and easy the COBOL is.

COBOL Programing Structures