COBOL

COBOL

Top Interview Questions

About COBOL

 

COBOL: An In-Depth Overview

Introduction

COBOL, which stands for Common Business-Oriented Language, is one of the oldest high-level programming languages, specifically designed for business, finance, and administrative systems for companies and governments. It was developed in the late 1950s to early 1960s as a part of a drive to create a universal programming language that could be easily read and understood by both programmers and non-programmers alike. Despite being decades old, COBOL continues to run a significant portion of the world’s financial systems, from banking to insurance, and government operations, underscoring its reliability and robustness.


History of COBOL

COBOL’s history traces back to 1959, when the Conference on Data Systems Languages (CODASYL) was formed to create a standardized language for business data processing. Prior to COBOL, businesses relied on machine-specific assembly languages, which were difficult to understand, maintain, and port across different computers.

A committee led by Grace Hopper, often referred to as the “Grandmother of COBOL,” contributed significantly to the language's design. COBOL was officially standardized in 1960, and its adoption spread rapidly due to its readability, portability, and suitability for business applications. Over the decades, COBOL has undergone multiple standardizations, such as COBOL-68, COBOL-74, COBOL-85, and modern versions that integrate object-oriented features.


Purpose and Design Philosophy

COBOL was designed with business applications in mind, particularly those involving processing large volumes of data, such as payroll, accounting, billing, and inventory management. The language’s main objectives include:

  1. Readability: COBOL syntax is highly English-like, making it easier for non-technical personnel, such as business analysts, to understand the code.

  2. Portability: Programs written in COBOL can run on different computer systems with minimal modifications.

  3. Data Processing Efficiency: Optimized for handling large-scale batch and transactional processing.

  4. Maintainability: Designed to be easy to modify and extend, crucial for long-term business applications.

COBOL’s syntax prioritizes clarity over brevity. While modern programming languages often favor compact code, COBOL emphasizes self-documenting statements like ADD SALARY TO TOTAL-PAY.


COBOL Program Structure

A typical COBOL program is divided into four main divisions, each serving a specific purpose:

  1. IDENTIFICATION DIVISION
    This division provides the program's metadata, such as its name, author, and date of creation. Example:

    IDENTIFICATION DIVISION.
    PROGRAM-ID. PAYROLL.
    AUTHOR. YASH YADAV.
    
  2. ENVIRONMENT DIVISION
    Defines the hardware and software environment in which the program will run, including file handling and input/output configurations.

  3. DATA DIVISION
    Specifies all the variables, records, and data structures used in the program. It is divided into sections like WORKING-STORAGE SECTION, FILE SECTION, and LOCAL-STORAGE SECTION.

    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 EMPLOYEE-NAME    PIC A(20).
    01 SALARY           PIC 9(6)V99.
    
  4. PROCEDURE DIVISION
    Contains the executable statements of the program. This division implements the logic for processing data, performing calculations, and managing control flow.

    PROCEDURE DIVISION.
    ADD SALARY TO TOTAL-PAY.
    DISPLAY 'TOTAL PAY: ' TOTAL-PAY.
    STOP RUN.
    

The division-based structure, along with verbose English-like commands, makes COBOL programs highly readable and easier to maintain.


Key Features of COBOL

COBOL offers several distinctive features that set it apart from other programming languages:

  1. English-Like Syntax:
    Statements such as IF, THEN, PERFORM, DISPLAY, and ADD make the code readable and intuitive.

  2. Precision in Data Handling:
    COBOL allows fixed-point arithmetic and precise data definitions using the PICTURE clause, making it ideal for financial calculations.

  3. File Handling Capabilities:
    COBOL has robust support for sequential, indexed, and relative file operations, essential for business applications that manage massive datasets.

  4. Batch and Transaction Processing:
    COBOL is designed to handle large-scale batch processing (processing a batch of records at once) and online transaction processing (real-time data handling).

  5. Portability:
    Programs can be moved across different hardware and operating systems with minimal changes.

  6. Structured Programming Support:
    Modern COBOL supports structured programming constructs, reducing the reliance on GOTO statements and promoting modularity.

  7. Object-Oriented COBOL:
    Recent COBOL standards (like COBOL 2002) introduced object-oriented programming features, allowing developers to create classes, objects, and methods.


Applications of COBOL

Despite its age, COBOL remains vital in many industries due to its reliability and scalability. Key applications include:

  1. Banking and Financial Systems:
    COBOL is widely used for ATM systems, loan processing, transaction management, and core banking applications.

  2. Insurance Industry:
    COBOL handles policies, claims processing, and customer information in life insurance, health insurance, and property insurance companies.

  3. Government Systems:
    COBOL powers social security systems, tax computation, pension management, and other large-scale administrative applications.

  4. Retail and Inventory Management:
    COBOL is used to track inventory, manage sales, generate invoices, and forecast demand.

  5. Airline and Transportation Industry:
    Reservation systems, ticketing, and logistics tracking in airlines and railways rely heavily on COBOL.


Advantages of COBOL

  1. High Readability:
    English-like syntax makes it easier for developers and non-programmers to understand and maintain code.

  2. Scalability and Reliability:
    COBOL is designed to handle large-scale applications efficiently, with minimal system downtime.

  3. Legacy Integration:
    Many businesses still rely on COBOL programs, and the language integrates well with modern systems through APIs and middleware.

  4. Precision and Accuracy:
    COBOL is excellent for handling financial transactions requiring exact decimal computations.

  5. Longevity and Proven Track Record:
    COBOL has been running mission-critical systems for over six decades, proving its durability.


Disadvantages of COBOL

  1. Verbose Code:
    Programs can be lengthy and time-consuming to write compared to modern concise languages like Python or Java.

  2. Declining Workforce:
    Fewer young programmers are learning COBOL, leading to a shortage of skilled developers for maintaining legacy systems.

  3. Limited Modern Features:
    Although object-oriented COBOL exists, it lacks many modern language features available in contemporary programming languages.

  4. Difficult Modernization:
    Updating or integrating COBOL systems with modern cloud-based architectures can be challenging and expensive.


Modern Relevance of COBOL

Despite predictions of its decline, COBOL remains highly relevant due to several factors:

  1. Legacy Systems Dependency:
    Many banks, insurance companies, and government agencies still run core systems on COBOL. Rewriting these systems in a new language is risky and expensive.

  2. Integration with Modern Technology:
    COBOL programs can now interface with Java, .NET, and web services, allowing organizations to modernize applications gradually.

  3. Support from Modern Platforms:
    Platforms like IBM Z mainframes and Micro Focus COBOL provide enhanced performance, security, and connectivity features, ensuring COBOL’s continued relevance.

  4. High Demand During Crises:
    During critical times, like the COVID-19 pandemic, COBOL programmers were in demand to update unemployment and social benefits systems.


COBOL in Education and Training

While COBOL is not as prominent in computer science curricula as languages like Python, Java, or C++, it remains essential in vocational training and enterprise IT programs. Learning COBOL provides insights into legacy system maintenance, business-oriented programming, and mainframe computing. For students or IT professionals looking to specialize in financial systems, insurance, or government applications, COBOL remains a valuable skill.

Fresher Interview Questions

 

1. What is COBOL?

Answer:
COBOL (Common Business Oriented Language) is a high-level programming language developed in 1959, primarily used for business, finance, and administrative systems. It is designed for processing large volumes of data and is widely used in mainframe environments.

Key features:

  • English-like syntax (easy to read and maintain)

  • Platform-independent

  • Supports structured and procedural programming

  • Mainly used in business applications such as banking, insurance, and payroll systems


2. What are the main divisions of a COBOL program?

Answer:
A COBOL program is divided into four main divisions:

  1. IDENTIFICATION DIVISION:

    • Provides the program name and author information.

    • Mandatory for all COBOL programs.

    IDENTIFICATION DIVISION.
    PROGRAM-ID. SampleProgram.
    AUTHOR. Yash Yadav.
    
  2. ENVIRONMENT DIVISION:

    • Describes the computer environment where the program will run.

    • Specifies input/output devices and files.

    ENVIRONMENT DIVISION.
    INPUT-OUTPUT SECTION.
    FILE-CONTROL.
       SELECT EmployeeFile ASSIGN TO 'EMP.DAT'.
    
  3. DATA DIVISION:

    • Declares all variables and data structures used in the program.

    • Subdivisions include WORKING-STORAGE SECTION, FILE SECTION, and LINKAGE SECTION.

  4. PROCEDURE DIVISION:

    • Contains the logic and instructions of the program.

    • Executable statements are written here.

    PROCEDURE DIVISION.
    DISPLAY 'Hello COBOL'.
    STOP RUN.
    

3. What are the different data types in COBOL?

Answer:
COBOL supports the following main data types:

  1. Numeric: Holds numeric values.

    • PIC 9(5) → 5-digit number

    • PIC S9(4)V99 → Signed number with 2 decimal places

  2. Alphabetic: Holds only letters.

    • PIC A(10) → 10 letters

  3. Alphanumeric: Holds letters, digits, and special characters.

    • PIC X(20) → 20 characters

  4. Alphanumeric Edited: Stores formatted strings for display.

    • PIC Z(5).99 → Displays numbers with formatting


4. What is a paragraph and a section in COBOL?

Answer:

  • Section: A logical division in the PROCEDURE DIVISION. It groups related paragraphs.

  • Paragraph: A set of COBOL statements within a section. It ends with a period (.).

Example:

PROCESS-EMPLOYEE SECTION.
    ADD-SALARY.
        ADD BONUS TO SALARY.
        DISPLAY SALARY.

5. Explain PIC clause in COBOL.

Answer:
The PIC (Picture) clause defines the type, size, and format of a variable. It is used in the DATA DIVISION.

  • 9 → Numeric

  • A → Alphabetic

  • X → Alphanumeric

  • S → Signed number

  • V → Implied decimal point

Example:

01 EMPLOYEE-NAME   PIC A(20).
01 EMPLOYEE-AGE    PIC 99.
01 SALARY          PIC S9(5)V99.

6. What are the different types of COBOL statements?

Answer:

  1. Data Movement Statements: MOVE, ACCEPT, DISPLAY

  2. Arithmetic Statements: ADD, SUBTRACT, MULTIPLY, DIVIDE

  3. Conditional Statements: IF, EVALUATE

  4. Looping Statements: PERFORM

  5. File Handling Statements: OPEN, CLOSE, READ, WRITE, REWRITE


7. Explain the PERFORM statement.

Answer:
The PERFORM statement is used to execute a paragraph, section, or range of statements repeatedly or conditionally.

Types:

  1. Simple PERFORM: Executes a paragraph or section once

  2. PERFORM UNTIL: Repeats until a condition is met

  3. PERFORM VARYING: Loop with increment/decrement

Example:

PERFORM PROCESS-EMPLOYEE UNTIL EMPLOYEE-END = 'Y'.

8. What is the difference between DISPLAY and WRITE in COBOL?

Answer:

DISPLAY WRITE
Outputs data to the screen Outputs data to a file or report
Used for debugging or user interaction Used for file handling
Example: DISPLAY 'Hello' Example: WRITE EMPLOYEE-RECORD

9. Explain the difference between COMPUTE and ADD statements.

Answer:

  • ADD: Used for simple addition of numeric values.

    ADD 100 TO SALARY.
    
  • COMPUTE: Can perform arithmetic operations (+, -, *, /) in a single statement.

    COMPUTE NET-SALARY = SALARY + BONUS - TAX.
    

10. What is an intrinsic function in COBOL?

Answer:
Intrinsic functions are built-in functions to perform operations on data. Some common functions:

Function Description
NUMVAL Converts string to numeric value
LENGTH Returns the length of a string
FUNCTION UPPER-CASE Converts string to uppercase
FUNCTION TRIM Removes leading/trailing spaces

Example:

MOVE FUNCTION LENGTH(EMPLOYEE-NAME) TO NAME-LENGTH.

11. What are the different types of files in COBOL?

Answer:
COBOL supports several file types:

  1. Sequential File: Records stored one after another

  2. Indexed File: Records accessed using a key field

  3. Relative File: Records stored with relative record numbers

Example of file handling statements:

OPEN INPUT EmployeeFile
READ EmployeeFile
WRITE EmployeeOutput
CLOSE EmployeeFile

12. Explain the difference between STOP RUN and GOBACK.

Answer:

STOP RUN GOBACK
Terminates the program completely Returns control to the calling program
Used in main programs Used in subprograms
Ends execution Does not end the main program

13. What is the difference between PROCEDURE DIVISION USING and CALL statement?

Answer:

  • PROCEDURE DIVISION USING: Defines parameters for subprograms

  • CALL: Invokes a subprogram and passes data

Example:

CALL 'SUBPROG' USING EMPLOYEE-NAME, SALARY.

14. What is the difference between sequential and random file access?

Answer:

  • Sequential Access: Records are read in order from first to last.

  • Random/Direct Access: Records are accessed directly using keys or record numbers.


15. What are the different divisions used in COBOL subprograms?

Answer:
Subprograms also have the following divisions:

  1. IDENTIFICATION DIVISION – Program name

  2. ENVIRONMENT DIVISION – Optional

  3. DATA DIVISION – Variables and linkage section

  4. PROCEDURE DIVISION USING – Receives parameters


16. What is the difference between REDEFINES and RENAMES?

Answer:

  • REDEFINES: Allows one memory area to be used by multiple data items with different data types.

  • RENAMES: Groups several contiguous data items under a new name.

Example:

01 EMPLOYEE-INFO.
   05 EMP-NAME    PIC X(20).
   05 EMP-AGE     PIC 99.
01 PERSON REDEFINES EMPLOYEE-INFO.
   05 FULL-INFO   PIC X(22).

17. What is an EVALUATE statement?

Answer:
EVALUATE is similar to a switch-case statement in other languages. It simplifies multiple IF conditions.

Example:

EVALUATE GRADE
    WHEN 'A' DISPLAY 'Excellent'
    WHEN 'B' DISPLAY 'Good'
    WHEN OTHER DISPLAY 'Average'
END-EVALUATE.

18. What are the advantages of COBOL?

Answer:

  • Easy to read and maintain due to English-like syntax

  • Efficient for processing large datasets

  • Platform-independent

  • Strong file-handling capabilities

  • Long-standing support in mainframes and banking systems


19. What are the limitations of COBOL?

Answer:

  • Verbose and long code

  • Not ideal for modern GUIs or web applications

  • Limited support for object-oriented programming (before COBOL 2002)

  • Performance may lag compared to modern languages for complex computations


20. How is error handling done in COBOL?

Answer:

  • COBOL handles runtime errors using the FILE STATUS clause for file operations

  • Use ON SIZE ERROR, INVALID KEY, or AT END to detect errors in arithmetic or file handling

Example:

OPEN INPUT EmployeeFile
IF FILE-STATUS NOT = '00'
   DISPLAY 'File Error'
END-IF

21. What is the difference between WORKING-STORAGE SECTION and LOCAL-STORAGE SECTION?

Answer:

  • WORKING-STORAGE SECTION:

    • Variables retain their values throughout the program execution.

    • Declared at the program level.

  • LOCAL-STORAGE SECTION:

    • Variables are reinitialized every time a program or subprogram is called.

    • Useful for temporary storage in subprograms.

Example:

WORKING-STORAGE SECTION.
01 TOTAL-SALES PIC 9(5) VALUE 0.

LOCAL-STORAGE SECTION.
01 TEMP-TOTAL PIC 9(5) VALUE 0.

22. What is the difference between FILE SECTION and WORKING-STORAGE SECTION?

Answer:

FILE SECTION WORKING-STORAGE SECTION
Used to define file structures and records Used to define temporary or permanent variables
Required when working with files Optional
Used with OPEN, READ, WRITE statements Used for calculations, intermediate storage

23. What is a level number in COBOL?

Answer:
Level numbers define the hierarchy of data items in DATA DIVISION.

  • 01: Top-level structure

  • 02-49: Subordinate fields

  • 66: RENAMES

  • 77: Independent elementary item (no subfields)

  • 88: Condition names

Example:

01 EMPLOYEE-RECORD.
   05 EMP-NAME   PIC X(20).
   05 EMP-AGE    PIC 99.
   05 EMP-SALARY PIC 9(6).

77 STATUS-CODE PIC 9.
88 ACTIVE VALUE 1.
88 INACTIVE VALUE 0.

24. Explain 88-level items in COBOL.

Answer:

  • 88-level items define condition names for a variable.

  • Used for readability and conditional checks.

Example:

01 EMP-STATUS PIC 9.
   88 ACTIVE VALUE 1.
   88 INACTIVE VALUE 0.

IF ACTIVE
   DISPLAY 'Employee is active'.

25. What are the types of loops in COBOL?

Answer:

  1. PERFORM THRU: Executes a range of paragraphs

  2. PERFORM UNTIL: Executes until a condition is true

  3. PERFORM VARYING: Loop with increment/decrement variable

  4. PERFORM TIMES: Loop executes a fixed number of times

Example:

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5
   DISPLAY I
END-PERFORM.

26. Explain the difference between sequential, indexed, and relative files.

Answer:

File Type Access Method Key Feature
Sequential Read in order Simple, fast for reading all records
Indexed Access by key Allows direct record access
Relative Access by record number Fixed-size records

27. What are the common file status codes?

Answer:

  • 00 → Successful operation

  • 10 → End of file

  • 90 → Duplicate key (for indexed files)

  • 91 → Not found (for indexed files)

  • 35 → Invalid key

Example:

READ EMP-FILE
   AT END DISPLAY 'End of File'
   NOT AT END DISPLAY EMP-NAME
END-READ.

28. What is the difference between REDEFINES and RENAMES?

Answer:

  • REDEFINES: Allows one memory area to be used by multiple data items. Only one is active at a time.

  • RENAMES: Groups contiguous fields under a new name for convenience.

Example (RENAMES):

01 EMPLOYEE-INFO.
   05 EMP-NAME   PIC X(10).
   05 EMP-AGE    PIC 99.
   05 EMP-SALARY PIC 9(5).

01 EMP-DETAILS RENAMES EMPLOYEE-INFO FOR 1 THRU 3.

29. What is the difference between COMPUTE and MOVE?

Answer:

  • MOVE: Copies a value from one variable to another.

  • COMPUTE: Performs arithmetic or calculations and stores the result.

Example:

MOVE 100 TO SALARY.
COMPUTE NET-SALARY = SALARY + BONUS - TAX.

30. Explain the difference between EVALUATE and IF statements.

Answer:

  • IF: Checks a single condition at a time.

  • EVALUATE: Similar to switch-case; checks multiple conditions and executes matching branch.

Example:

EVALUATE GRADE
    WHEN 'A' DISPLAY 'Excellent'
    WHEN 'B' DISPLAY 'Good'
    WHEN OTHER DISPLAY 'Average'
END-EVALUATE.

31. What is the difference between ACCEPT and DISPLAY?

Answer:

ACCEPT DISPLAY
Accepts input from user or system Shows output on screen or report
Example: ACCEPT EMP-NAME Example: DISPLAY EMP-NAME

32. Explain the difference between INDEXED and RELATIVE file organization.

Answer:

  • Indexed: Access records using key values. Keys are unique or non-unique.

  • Relative: Access records using relative record numbers.


33. What is the difference between procedural and object-oriented COBOL?

Answer:

  • Procedural COBOL: Traditional COBOL using divisions, paragraphs, and procedural logic.

  • Object-Oriented COBOL (OO-COBOL): Introduced in COBOL 2002; supports classes, objects, inheritance, and methods.


34. How do you handle exceptions in COBOL?

Answer:

  • File errors: Use FILE STATUS clause and check the code after each operation.

  • Arithmetic errors: Use ON SIZE ERROR clause.

  • Example:

ADD 100 TO SALARY ON SIZE ERROR
   DISPLAY 'Overflow Error'
END-ADD.

35. What is the difference between an elementary and group item in COBOL?

Answer:

  • Elementary item: Cannot be subdivided (e.g., PIC X(10), PIC 9(5)).

  • Group item: Contains subfields (e.g., 01 EMPLOYEE with EMP-NAME, EMP-AGE).


36. Explain the difference between CALL and LINKAGE SECTION.

Answer:

  • CALL: Invokes a subprogram.

  • LINKAGE SECTION: Declares variables passed from calling program to subprogram.

Example:

CALL 'SUBPROG' USING EMPLOYEE-NAME, SALARY.

37. What is the difference between STOP RUN and GOBACK?

Answer:

  • STOP RUN: Terminates the entire program.

  • GOBACK: Returns control to the calling program (used in subprograms).


38. What is the difference between LEVEL 77 and LEVEL 88?

Answer:

  • 77: Independent elementary item (not part of any group).

  • 88: Condition names for 77 or other data items.


39. What is the difference between INSPECT and UNSTRING statements?

Answer:

  • INSPECT: Counts, replaces, or removes characters in a string.

  • UNSTRING: Breaks a string into multiple parts based on delimiters.

Example (UNSTRING):

UNSTRING FULL-NAME DELIMITED BY SPACE
   INTO FIRST-NAME, LAST-NAME
END-UNSTRING.

40. What is the difference between INITIALIZE and MOVE statements?

Answer:

  • INITIALIZE: Sets numeric fields to zero and alphanumeric fields to spaces.

  • MOVE: Copies a specific value to a variable.


41. What is the difference between SELECT and ASSIGN in COBOL?

Answer:

  • SELECT: Links a logical file name with the physical file.

  • ASSIGN: Specifies the physical file location (like path or DD name).

Example:

SELECT EMP-FILE ASSIGN TO 'EMP.DAT'.

42. What is the difference between PERFORM TIMES and PERFORM UNTIL?

Answer:

  • PERFORM TIMES: Repeats a set of statements a fixed number of times.

  • PERFORM UNTIL: Repeats until a condition becomes true.


43. What is the difference between numeric edited and numeric data?

Answer:

  • Numeric data: Stores numbers without formatting (e.g., 9(5)).

  • Numeric edited: Stores numbers with formatting (e.g., commas, decimal points).


44. What are intrinsic functions in COBOL?

Answer:
Functions like LENGTH, NUMVAL, UPPER-CASE, TRIM, etc., are built-in and used for operations on variables.

Example:

MOVE FUNCTION NUMVAL('12345') TO NUM-VALUE.

45. How can you handle multiple file input/output in COBOL?

Answer:

  • Open multiple files using OPEN INPUT/OUTPUT/EXTEND

  • Read, write, or rewrite each file separately

  • Close all files at the end

Example:

OPEN INPUT EMP-FILE
OPEN OUTPUT REPORT-FILE
READ EMP-FILE
WRITE REPORT-FILE
CLOSE EMP-FILE REPORT-FILE

46. What is the difference between SORT and MERGE in COBOL?

Answer:

  • SORT: Arranges records in ascending or descending order.

  • MERGE: Combines two or more sorted files into one sorted file.


47. What is the difference between level 01 and level 77?

Answer:

  • 01: Top-level group item that can have subfields.

  • 77: Elementary item, independent, cannot have subfields.


48. What are the different divisions in a COBOL program?

Answer:

  1. IDENTIFICATION DIVISION

  2. ENVIRONMENT DIVISION

  3. DATA DIVISION

  4. PROCEDURE DIVISION


49. How do you declare constants in COBOL?

Answer:

  • Use VALUE clause in WORKING-STORAGE section.
    Example:

01 PI-VALUE PIC 9(1)V99 VALUE 3.14.

50. What are condition names in COBOL?

Answer:

  • Declared with 88-level items.

  • Makes code readable by replacing numeric values with meaningful names.

Experienced Interview Questions

 

1. What are the key features of COBOL used in enterprise applications?

Answer:

  • Readable syntax: English-like, easy to maintain for business logic.

  • File handling: Supports sequential, indexed, and relative files.

  • Structured programming: Supports PERFORM, EVALUATE, and modularization.

  • Report generation: Built-in capabilities for formatted reports.

  • Mainframe compatibility: Works efficiently with CICS, DB2, VSAM.

  • Long-standing use: Widely used in banking, insurance, and payroll systems.


2. Explain the difference between LEVEL-77, LEVEL-88, and LEVEL-01 items.

Answer:

  • 01: Top-level group item, may have subfields.

  • 77: Elementary item, standalone, cannot have subfields.

  • 88: Condition names for meaningful conditional checks.

Example:

01 EMP-RECORD.
   05 EMP-NAME  PIC X(20).
   05 EMP-AGE   PIC 99.

77 STATUS-CODE PIC 9.
88 ACTIVE VALUE 1.
88 INACTIVE VALUE 0.

3. What are the advanced file handling techniques in COBOL?

Answer:

  • Sequential Files: Simple read/write operations.

  • Indexed Files (VSAM): Direct access using keys, supports duplicates.

  • Relative Files: Access via record numbers.

  • Dynamic File Handling: Using SELECT … ASSIGN TO at runtime.

  • Error Handling: Using FILE STATUS codes to catch errors during OPEN, READ, WRITE.

Example:

OPEN INPUT EMP-FILE
IF FILE-STATUS NOT = '00'
   DISPLAY 'File error occurred'
END-IF.

4. What is COBOL subprogram and how do you call it?

Answer:

  • Subprogram: A modular program invoked by a main program to perform specific tasks.

  • Calling Methods:

    • CALL 'SUBPROG' USING var1, var2

    • Parameters are passed via LINKAGE SECTION in the subprogram.

Example (Subprogram):

LINKAGE SECTION.
01 EMP-NAME PIC X(20).
PROCEDURE DIVISION USING EMP-NAME.
DISPLAY 'Employee Name: ' EMP-NAME.
GOBACK.

Main Program:

CALL 'SUBPROG' USING EMP-NAME.

5. What are dynamic and static calls in COBOL?

Answer:

  • Static CALL: Subprogram is linked at compile time.

  • Dynamic CALL: Subprogram is linked at runtime; allows flexibility for multiple programs without recompilation.


6. How do you handle multiple files in a COBOL program?

Answer:

  • Open files sequentially or simultaneously.

  • Perform read/write operations separately for each file.

  • Close all files after processing.

Example:

OPEN INPUT EMP-FILE
OPEN OUTPUT REPORT-FILE
PERFORM UNTIL EOF = 'Y'
    READ EMP-FILE AT END MOVE 'Y' TO EOF
        NOT AT END
            WRITE REPORT-FILE
    END-READ
END-PERFORM
CLOSE EMP-FILE REPORT-FILE.

7. Explain intrinsic functions and their advanced usage.

Answer:

  • NUMVAL: Converts numeric strings to numbers.

  • LENGTH: Returns length of a string.

  • UPPER-CASE / LOWER-CASE: Case conversion.

  • DATE / DAY-OF-WEEK: Used in financial/reporting programs.

  • TRIM: Removes spaces for data normalization.

Example:

MOVE FUNCTION NUMVAL(EMP-ID-STR) TO EMP-ID.
DISPLAY 'Length of Name: ' FUNCTION LENGTH(EMP-NAME).

8. What is the difference between PERFORM, PERFORM THRU, and PERFORM UNTIL?

Answer:

PERFORM Type Description
PERFORM Executes a paragraph or section once
PERFORM THRU Executes a range of paragraphs sequentially
PERFORM UNTIL Executes repeatedly until a condition is satisfied
PERFORM VARYING Loop with increment/decrement variable

Example:

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
   DISPLAY I
END-PERFORM.

9. Explain EVALUATE statement with WHEN OTHER clause.

Answer:

  • EVALUATE is similar to switch-case in other languages.

  • WHEN OTHER handles all unmatched conditions.

Example:

EVALUATE GRADE
   WHEN 'A' DISPLAY 'Excellent'
   WHEN 'B' DISPLAY 'Good'
   WHEN OTHER DISPLAY 'Average'
END-EVALUATE.

10. Explain advanced data types like COMP, COMP-3, and BINARY.

Answer:

  • COMP / BINARY: Efficient numeric storage for arithmetic; takes less memory.

  • COMP-3 / Packed Decimal: Stores two digits per byte; used for financial data.

  • Usage: Improves performance for calculations in mainframe systems.

Example:

01 SALARY PIC S9(7) COMP-3.

11. How do you optimize COBOL programs for performance?

Answer:

  • Use indexed files for large datasets.

  • Minimize nested PERFORM loops.

  • Use COMP / COMP-3 for numeric processing.

  • Avoid unnecessary DISPLAY statements in production.

  • Properly manage memory and working-storage variables.


12. What are the different ways to handle errors in COBOL?

Answer:

  • FILE STATUS for file operations

  • ON SIZE ERROR for arithmetic overflow

  • INVALID KEY for indexed files

  • AT END for end-of-file detection

Example:

READ EMP-FILE
   AT END DISPLAY 'End of file reached'
   INVALID KEY DISPLAY 'Key not found'
END-READ.

13. What are nested subprograms and how do you handle them?

Answer:

  • COBOL allows calling subprograms from another subprogram.

  • Linkage Section passes variables correctly.

  • Avoid deep nesting to maintain performance and readability.


14. Explain COPYBOOKs in COBOL.

Answer:

  • Reusable data or procedure segments included in programs using COPY statement.

  • Helps maintain consistency and reduces coding effort.

Example:

COPY EMPLOYEE-RECORDS.

15. What is DB2 integration with COBOL?

Answer:

  • COBOL programs can access DB2 databases using embedded SQL.

  • EXEC SQL statements are used to perform SELECT, INSERT, UPDATE, DELETE.

Example:

EXEC SQL
   SELECT NAME, SALARY INTO :EMP-NAME, :EMP-SALARY
   FROM EMPLOYEE
   WHERE EMP-ID = :EMP-ID
END-EXEC.

16. What are the common debugging techniques in COBOL?

Answer:

  • Use DISPLAY statements to check variable values.

  • Use DEBUGGING TOOLS like Xpediter or IBM Debug Tool.

  • Check FILE STATUS and RETURN-CODES.

  • Comment out sections to isolate issues.


17. How do you handle multiple condition checks efficiently in COBOL?

Answer:

  • Use EVALUATE instead of multiple nested IFs.

  • Use 88-level condition names for better readability.

Example:

IF ACTIVE OR TEMPORARY DISPLAY 'Employee can access system'.

18. How do you handle date and time in COBOL?

Answer:

  • Use ACCEPT DATE or FUNCTION CURRENT-DATE to get system date.

  • Perform date arithmetic using numeric fields.

Example:

ACCEPT TODAY FROM DATE.
MOVE FUNCTION CURRENT-DATE TO SYS-DATE.

19. Explain SORT and MERGE in advanced scenarios.

Answer:

  • SORT: Sorts large datasets efficiently.

  • MERGE: Combines multiple sorted files into a single sorted file.

  • Advanced: Using USING / GIVING clauses for optimized memory and file handling.

Example:

SORT EMP-FILE ON ASCENDING KEY EMP-NAME
   USING UNSORTED-FILE
   GIVING SORTED-FILE.

20. How do you implement modular programming in COBOL?

Answer:

  • Use CALL / LINKAGE SECTION for subprograms.

  • Use COPYBOOKS for reusable code.

  • Group related logic in sections and paragraphs for maintainability.


21. Explain VSAM files and their usage in COBOL.

Answer:

  • VSAM (Virtual Storage Access Method) is used for indexed and direct access files.

  • Supports KSDS, RRDS, and ESDS file structures.

  • Efficient for large datasets in mainframes.

Example:

SELECT VSAM-EMP-FILE ASSIGN TO EMP-VSAM
   ORGANIZATION IS INDEXED
   RECORD KEY IS EMP-ID
   FILE STATUS IS WS-FILE-STATUS.

22. How do you handle large datasets efficiently?

Answer:

  • Use indexed or relative files for direct access.

  • Minimize nested loops.

  • Use SORT / MERGE utilities for large-scale sorting.

  • Use COMP-3 for numeric calculations to reduce memory usage.


23. Explain object-oriented COBOL concepts.

Answer:

  • Introduced in COBOL 2002.

  • Supports classes, objects, methods, inheritance, polymorphism.

  • Useful for modernizing legacy COBOL applications.

Example:

CLASS-ID. Employee.
METHOD-ID. DisplayInfo.
DISPLAY 'Employee Details'.
END METHOD DisplayInfo.
END CLASS Employee.

24. What are the best practices for maintaining COBOL code in production?

Answer:

  • Use copybooks for standardization.

  • Use commenting and meaningful variable names.

  • Avoid hard-coded values; use constants or configuration files.

  • Implement error handling using FILE STATUS and RETURN-CODES.

  • Optimize loops and arithmetic operations.


25. How do you integrate COBOL with other technologies?

Answer:

  • CICS: For online transaction processing.

  • DB2: For relational database access.

  • JCL: For batch processing and job scheduling.

  • Web services / REST APIs: Modern integration using wrappers or middleware.


26. What are VSAM files and their types in detail?

Answer:
VSAM (Virtual Storage Access Method) is a file storage system used in mainframes for large datasets.
Types of VSAM files:

  1. KSDS (Key-Sequenced Data Set): Records are accessed using a unique key. Supports sequential and random access.

  2. RRDS (Relative Record Data Set): Records accessed via relative record numbers.

  3. ESDS (Entry Sequenced Data Set): Records stored in the order they are entered.

Example of KSDS File Handling:

SELECT EMP-VSAM ASSIGN TO EMPFILE
   ORGANIZATION IS INDEXED
   RECORD KEY IS EMP-ID
   FILE STATUS IS WS-FILE-STATUS.
OPEN INPUT EMP-VSAM
READ EMP-VSAM
   AT END DISPLAY 'End of File'
   NOT AT END DISPLAY EMP-NAME
END-READ
CLOSE EMP-VSAM.

27. Explain the difference between OCCURS and OCCURS DEPENDING ON (ODO).

Answer:

  • OCCURS: Defines a fixed array with a fixed number of elements.

  • OCCURS DEPENDING ON (ODO): Array size is dynamic; the number of occurrences is determined by a variable at runtime.

Example:

01 EMP-DETAILS.
   05 EMP-NAME  PIC X(20) OCCURS 10 TIMES.
   05 EMP-AGE   PIC 99   OCCURS 1 TO 10 TIMES DEPENDING ON EMP-COUNT.

28. How do you handle multiple condition checks efficiently in COBOL?

Answer:

  • Use 88-level condition names for readability.

  • Use EVALUATE instead of nested IFs.

  • Example with 88-level:

01 EMP-STATUS PIC 9.
   88 ACTIVE VALUE 1.
   88 INACTIVE VALUE 0.

IF ACTIVE DISPLAY 'Employee Active'
ELSE DISPLAY 'Employee Inactive'.

29. What are intrinsic functions for string manipulation in COBOL?

Answer:
Common intrinsic functions include:

  • FUNCTION LENGTH: Returns the length of a string.

  • FUNCTION TRIM: Removes leading/trailing spaces.

  • FUNCTION UPPER-CASE / LOWER-CASE: Converts case.

  • FUNCTION NUMVAL: Converts numeric string to number.

Example:

MOVE FUNCTION NUMVAL(EMP-ID-STR) TO EMP-ID.
DISPLAY 'Length: ' FUNCTION LENGTH(EMP-NAME).

30. Explain debugging techniques in COBOL.

Answer:

  • Use DISPLAY statements for variable tracing.

  • Use mainframe debugging tools: IBM Debug Tool, Xpediter, Abend-AID.

  • Check FILE STATUS and RETURN-CODES after operations.

  • Use paragraph isolation to find logical errors.

  • Comment out sections to narrow down issues.


31. What is an indexed VSAM file and how do you access a record?

Answer:

  • Indexed VSAM (KSDS): Records have unique key values; supports sequential and random access.

  • Access Methods:

    • Sequential Read: First-to-last record.

    • Random Read: Using the key.

  • COBOL Example:

READ EMP-VSAM KEY IS EMP-ID
   INVALID KEY DISPLAY 'Record Not Found'
   NOT INVALID KEY DISPLAY EMP-NAME.

32. What is CICS and how do you integrate COBOL with it?

Answer:

  • CICS (Customer Information Control System): A transaction processing system for mainframes.

  • Integration:

    • COBOL programs are invoked as CICS transactions.

    • Use EXEC CICS commands for data input/output, file access, and communication.

Example:

EXEC CICS READ FILE('EMPFILE') INTO(EMP-RECORD) RIDFLD(EMP-ID)
   RESP(RESP-CODE)
END-EXEC.

33. What is the difference between static and dynamic calls in COBOL?

Answer:

Type Description Example
Static Call Subprogram linked at compile time CALL 'SUBPROG' USING VAR1
Dynamic Call Subprogram linked at runtime CALL VAR-PROG-NAME USING VAR1

34. How do you handle date calculations in COBOL?

Answer:

  • Use FUNCTION CURRENT-DATE to get system date and time.

  • Use arithmetic operations to calculate age, difference between dates.

Example:

MOVE FUNCTION CURRENT-DATE TO WS-CUR-DATE.
COMPUTE AGE = (WS-CUR-DATE - DOB) / 10000.

35. Explain packed decimal (COMP-3) and its advantages.

Answer:

  • COMP-3: Stores two digits per byte; last nibble contains sign.

  • Advantages:

    • Saves memory.

    • Faster arithmetic operations.

    • Widely used in financial applications.

Example:

01 SALARY PIC S9(7)V99 COMP-3.

36. How do you handle multiple file I/O errors in COBOL?

Answer:

  • Use FILE STATUS after every OPEN, READ, WRITE, or REWRITE.

  • Example:

READ EMP-FILE
   AT END MOVE 'Y' TO EOF-FLAG
   INVALID KEY DISPLAY 'Record Not Found'
   NOT INVALID KEY DISPLAY EMP-NAME
END-READ.

37. Explain SORT and MERGE with USING and GIVING.

Answer:

  • SORT: Sorts input file into a new output file.

  • MERGE: Merges multiple sorted files into one sorted file.

Example (SORT):

SORT EMP-FILE ON ASCENDING KEY EMP-NAME
   USING UNSORTED-FILE
   GIVING SORTED-FILE.

Example (MERGE):

MERGE FINAL-FILE
   ON ASCENDING KEY EMP-ID
   USING FILE1 FILE2 FILE3.

38. What are COPYBOOKs and their advantages?

Answer:

  • Reusable blocks of code or data definitions included using COPY statement.

  • Advantages:

    • Reduces code duplication.

    • Simplifies maintenance.

    • Ensures consistency across multiple programs.

Example:

COPY EMPLOYEE-RECORDS.

39. How do you implement modular programming in COBOL?

Answer:

  • Use CALL / LINKAGE SECTION for subprograms.

  • Use COPYBOOKS for reusable data structures.

  • Group related paragraphs and sections for logical separation.

  • Example:

CALL 'CALC-SALARY' USING EMP-ID, EMP-SALARY.

40. What are the advanced debugging techniques for production COBOL?

Answer:

  • Use IBM Debug Tool or Xpediter to set breakpoints and watch variables.

  • Capture abend dumps to analyze errors.

  • Use FILE STATUS monitoring and logs.

  • Step through program execution with trace tables.


41. How do you optimize COBOL programs for performance?

Answer:

  • Use indexed/relative files instead of sequential files for large datasets.

  • Minimize nested PERFORM loops.

  • Use COMP / COMP-3 for numeric operations.

  • Avoid unnecessary DISPLAY statements in production.

  • Optimize SORT / MERGE operations with USING / GIVING clauses.


42. Explain EVALUATE with multiple conditions.

Answer:

  • Handles complex conditions efficiently.

  • Replaces multiple nested IF statements.

Example:

EVALUATE TRUE
   WHEN AGE < 18 AND EMP-STATUS = 'ACTIVE' DISPLAY 'Minor Active'
   WHEN AGE >= 18 AND EMP-STATUS = 'INACTIVE' DISPLAY 'Adult Inactive'
   WHEN OTHER DISPLAY 'Other Case'
END-EVALUATE.

43. How do you handle CICS transactions in COBOL?

Answer:

  • Use EXEC CICS commands:

    • READ and WRITE for files

    • SEND and RECEIVE for terminal I/O

    • HANDLE CONDITION for error handling

  • Example:

EXEC CICS READ FILE('EMPFILE') INTO(EMP-RECORD) RIDFLD(EMP-ID) RESP(RESP-CODE) END-EXEC.

44. What are real-time COBOL scenario-based questions?

Answer:
Scenario 1: Handling duplicate records in VSAM indexed file.

  • Use INVALID KEY to detect duplicates, REWRITE to update records.

Scenario 2: Processing large payroll files efficiently.

  • Use indexed files or SORT / MERGE utilities.

  • Use COMP-3 fields for numeric calculations.

Scenario 3: Calling multiple subprograms in batch job.

  • Modularize with CALL and LINKAGE SECTION.

  • Use COPYBOOKs for shared structures.


45. How do you handle large financial calculations in COBOL?

Answer:

  • Use COMP-3 / packed decimal for precision.

  • Avoid floating-point; use numeric edited fields for display.

  • Example:

COMPUTE NET-SALARY = BASIC + BONUS - TAX.

46. How do you integrate COBOL with DB2 in production systems?

Answer:

  • Use embedded SQL (EXEC SQL) inside COBOL.

  • Example:

EXEC SQL
   SELECT NAME, SALARY INTO :EMP-NAME, :EMP-SALARY
   FROM EMPLOYEE
   WHERE EMP-ID = :EMP-ID
END-EXEC.

47. Explain UNSTRING and STRING with delimiters in COBOL.

Answer:

  • UNSTRING: Breaks a string into multiple variables based on a delimiter.

  • STRING: Concatenates multiple strings with delimiters.

Example (UNSTRING):

UNSTRING FULL-NAME DELIMITED BY SPACE
   INTO FIRST-NAME LAST-NAME
END-UNSTRING.

Example (STRING):

STRING FIRST-NAME DELIMITED BY SPACE
       LAST-NAME DELIMITED BY SPACE
   INTO FULL-NAME
END-STRING.

48. How do you handle conditional updates in indexed VSAM files?

Answer:

  • Use READ … INVALID KEY to check record existence.

  • Use REWRITE to update existing records.

  • Use WRITE to insert new records.

Example:

READ EMP-VSAM KEY IS EMP-ID
   INVALID KEY WRITE EMP-RECORD
   NOT INVALID KEY REWRITE EMP-RECORD
END-READ.

49. Explain how to prevent abends in COBOL programs.

Answer:

  • Validate input using ACCEPT and IF conditions.

  • Check FILE STATUS for file operations.

  • Use ON SIZE ERROR for arithmetic overflows.

  • Handle NULL or unexpected data.

  • Example:

ADD SALARY BONUS ON SIZE ERROR DISPLAY 'Overflow Error'.

50. What are advanced performance tuning techniques in COBOL?

Answer:

  • Use indexed/relative files instead of sequential files.

  • Minimize nested loops.

  • Use COMP / COMP-3 fields for numeric operations.

  • Reduce disk I/O by batching writes.

  • Use SORT / MERGE efficiently with USING / GIVING clauses.

  • Modularize code for maintainability and reduced CPU time.