COBOL Interview Questions and Answers (1 - 10)
1. What is COBOL, and why is it mainly used for?
COBOL (Common Business-Oriented Language) is a high-level programming language. It is a robust programming language designed primarily for business, financial, and administrative systems for companies.
2. What is the difference between Structured COBOL Programming and Object Oriented COBOL programming?
Feature | Structured COBOL Programming | Object-Oriented COBOL Programming |
---|---|---|
Model | Follows procedural and structured programming | Uses object-oriented programming (OOP) concepts |
Program Structure | Organized using divisions, sections, and paragraphs with a top-down flow | Uses classes, objects, and methods for modular and reusable code |
Code Reusability | Limited; code is reused through paragraph, COPYBOOKs or subprograms | High; code is encapsulated within classes and objects |
Data Encapsulation | Global data is used across the program | Supports data hiding and encapsulation with PRIVATE and PUBLIC attributes |
Inheritance | Not supported | Supports inheritance, allowing derived classes to reuse base class features |
Polymorphism | Not supported | Allows polymorphism through method overriding |
Flexibility | Best suited for traditional batch processing and transaction systems | Suitable for modern applications that require modular and scalable design |
3. What are literals?
Literals in COBOL are constant values that are explicitly written in the program and do not change during execution. They are directly assigned to variables or used in expressions and computations.
Type of Literals -
- Numeric Literals - Represent numeric values (integers or decimals) and can be positive or negative. For example -
55 and -25.75 are the numeric literals.01 WS-VAR PIC 9(05) VALUE 55. ... MOVE -25.75 TO WS-AMOUNT.
- Non-Numeric Literals - Represent text or character values enclosed in quotes (' or "). For example -
HELLO and A1 are the non-numeric literals.01 WS-VAR PIC X(05) VALUE "HELLO". ... MOVE 'A1' TO WS-CHAR.
4. What is the difference between performing a SECTION and a PARAGRAPH?
Feature | SECTION | PARAGRAPH |
---|---|---|
Definition | A SECTION consists of one or more PARAGRAPHS. | A PARAGRAPH is a named block of code within a SECTION. |
Execution Scope | When a SECTION is performed, all paragraphs inside it are executed sequentially. | When a PARAGRAPH is performed, only that specific paragraph is executed. |
End Point | SECTION ends when another SECTION coding starts or the program ends | PARAGRAPH ends when another PARAGRAPH or SECTION coding starts or the program ends |
Usage | Used when multiple paragraphs need to be executed together as a logical unit. | Used when a single paragraph needs to be executed independently. |
5. What does EXIT do?
The EXIT statement is used as a logical control statement, primarily for program flow control. It serves as a way to indicate the end of a loop, paragraph, or section without performing any specific operation. For example -
PROCESS-PARA.
IF WS-FLAG = 1
...
END-IF.
EXIT.
When EXIT is executed, the paragraph execution is completed and control returns to the statement following the PERFORM PRCOESS_PARA call.
6. What are all the divisions of a COBOL program?
A COBOL program is divided into four main divisions, each serving a specific purpose. These divisions help structure the program and improve readability and maintainability. They are -
- IDENTIFICATION DIVISION - Mandatory. Provides metadata about the program (name, author, date, version, etc.).
- ENVIRONMENT DIVISION - Optional. Contains system-specific configurations and file-handling information.
- DATA DIVISION - Optional. Defines all the variables, constants, and file structures used in the program.
- PROCEDURE DIVISION - Mandatory. Contains the executable logic of the program and defines the sequence of operations performed.
7. Which division and paragraphs are mandatory for a COBOL program?
Below is a breakdown of the required components for a minimal COBOL program -
Component | Purpose |
---|---|
IDENTIFICATION DIVISION | Starting point of the program |
PROGRAM-ID (Paragraph in IDENTIFICATION DIVISION) | Defines the program name |
PROCEDURE DIVISION | Contains the program logic |
STOP RUN or GOBACK | Specifies the end of the program |
8. Let us assume we have coded a program with all the mandatory divisions and paragraphs. Can we compile/execute a program without having single executable statement (except STOP RUN) in PROCEDURE DIVISION.
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTPROG.
PROCEDURE DIVISION.
STOP RUN.
Yes, we can compile and execute the program. However, its a do nothing program.
9. What is the significance of the FILE-CONTROL paragraph?
The FILE-CONTROL paragraph is part of the INPUT-OUTPUT SECTION in the ENVIRONMENT DIVISION of a COBOL program. It plays a crucial role in defining how files are assigned, accessed, and organized. Its key features are -
- Maps COBOL file names to physical storage locations or external datasets.
- Defines the File Organization - Determines how records are stored and accessed in the file.
- Specifies the Access Mode - Defines how the program will access records.
- Handles File Record Keys (for Indexed Files).
- Defines the file status field to capture the status of file operations.
10. How many Sections are there in Data Division?
The DATA DIVISION can contain up to four sections, depending on the program's requirements. Each section serves a different purpose in defining and managing data.
- FILE SECTION - Defines the structure of files used in the program.
- WORKING-STORAGE SECTION - Declares temporary variables, constants, and intermediate data used in the program.
- LOCAL-STORAGE SECTION - The variables declared in this section are generally used for short-term storage and are not retained between different program executions.
- LINKAGE SECTION - Defines variables that are passed between programs (used in CALLed programs).