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?

FeatureStructured COBOL ProgrammingObject-Oriented COBOL Programming
ModelFollows procedural and structured programmingUses object-oriented programming (OOP) concepts
Program StructureOrganized using divisions, sections, and paragraphs with a top-down flowUses classes, objects, and methods for modular and reusable code
Code ReusabilityLimited; code is reused through paragraph, COPYBOOKs or subprogramsHigh; code is encapsulated within classes and objects
Data EncapsulationGlobal data is used across the programSupports data hiding and encapsulation with PRIVATE and PUBLIC attributes
InheritanceNot supportedSupports inheritance, allowing derived classes to reuse base class features
PolymorphismNot supportedAllows polymorphism through method overriding
FlexibilityBest suited for traditional batch processing and transaction systemsSuitable 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 -
    01 WS-VAR      PIC 9(05) VALUE 55.
    ...
    MOVE -25.75 TO WS-AMOUNT. 
    55 and -25.75 are the numeric literals.
  • Non-Numeric Literals - Represent text or character values enclosed in quotes (' or "). For example -
    01 WS-VAR      PIC X(05) VALUE "HELLO".
    ...
    MOVE 'A1' TO WS-CHAR. 
    HELLO and A1 are the non-numeric literals.

4. What is the difference between performing a SECTION and a PARAGRAPH?

FeatureSECTIONPARAGRAPH
DefinitionA SECTION consists of one or more PARAGRAPHS.A PARAGRAPH is a named block of code within a SECTION.
Execution ScopeWhen a SECTION is performed, all paragraphs inside it are executed sequentially.When a PARAGRAPH is performed, only that specific paragraph is executed.
End PointSECTION ends when another SECTION coding starts or the program endsPARAGRAPH ends when another PARAGRAPH or SECTION coding starts or the program ends
UsageUsed 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 -

ComponentPurpose
IDENTIFICATION DIVISIONStarting point of the program
PROGRAM-ID (Paragraph in IDENTIFICATION DIVISION)Defines the program name
PROCEDURE DIVISIONContains the program logic
STOP RUN or GOBACKSpecifies 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).