COBOL Interview Questions (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 a SSRANGE and NOSSRANGE?
SSRANGE (Subscript Range Checking Enabled):
- Enables runtime checking for array (table) out-of-bounds errors.
- If a subscript or index exceeds the defined range, an error occurs.
- Used for debugging and preventing memory corruption.
NOSSRANGE (Subscript Range Checking Disabled - Default):
- Does not check array bounds at runtime.
- Improves performance but may cause memory corruption if subscripts go out of range.
3. Describe the purpose of the FD and SD entries?
FD (File Description) Entry:
- Used in the FILE SECTION to define input or output files.
- Specifies file structure, record layout, and organization.
- Used for sequential, indexed, or relative files.
SD (Sort Description) Entry:
- Used in the FILE SECTION to define a temporary sort work file.
- Required when using the SORT statement.
- Stores records during sorting operations but does not require explicit OPEN and CLOSE.
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 specify 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 divisionsare used to 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. For example -
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 is important in defining how files are assigned, accessed, and organized. Its key features are -
- Maps COBOL logical file names to 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).