Top Cobol Interview Questions You Need to Know

Are you preparing for a COBOL developer interview? Our comprehensive guide on “COBOL interview questions and answers” is here to help! Whether you’re a fresher or an experienced candidate, this article covers a wide range of questions that are commonly asked during COBOL interviews. From basic concepts to advanced programming techniques, we’ve compiled the most important questions along with detailed answers to boost your confidence and readiness. Dive into our article to gain insights and enhance your understanding of COBOL, ensuring you ace your next interview. Read on and become well-equipped with the knowledge required to succeed as a COBOL developer.

COBOL (Common Business-Oriented Language) is one of the oldest programming languages, designed specifically for business, finance, and administrative systems for companies and governments. Developed in 1959, COBOL excels in handling large volumes of data and is known for its readability and simplicity, with a syntax resembling natural English language.

Cobol Key Features

  • Readability and Simplicity: COBOL’s syntax is designed to be easy to read and understand, making it accessible to non-programmers.
  • Business-Oriented: It is tailored for business applications, excelling in data processing tasks like payroll, inventory management, and financial transactions.
  • Data Processing: COBOL handles extensive file processing and database management efficiently.
  • Portability: Programs written in COBOL can run on various hardware platforms with minimal modifications, ensuring cross-platform compatibility.
  • Structured Programming: Supports structured programming techniques, which improves code clarity and maintainability.
  • Legacy System Integration: COBOL is widely used in legacy systems, particularly in the financial sector, and continues to run critical applications.
  • Self-Documenting Code: Encourages writing code that is self-explanatory, aiding in maintenance and updates.
  • Transaction Processing: Effective in handling both batch and online transaction processing, making it ideal for high-volume transaction environments.

Despite its age, COBOL remains relevant due to its robustness and reliability, with many organizations continuing to use and maintain COBOL-based systems for mission-critical applications.

cobol interview questions and answers

Top Cobol Interview Questions for Experienced

Q1. Why is LINKAGE SECTION needed?
Ans: The LINKAGE SECTION in COBOL is essential for defining data items passed between programs or between a program and a called subprogram. It enables the sharing of data without needing to reallocate memory. This section allows the called program to access the data items defined in the calling program, promoting modularity and reusability.

Example:

LINKAGE SECTION.
01 WS-VARIABLE PIC X(10).

Q2. What is the difference between CALL and LINK statements in COBOL?
Ans:

  • CALL Statement: The CALL statement is used to invoke a subprogram from a main program. The control returns to the main program after the subprogram execution. Example:
CALL 'SUBPROGRAM' USING WS-DATA.

LINK Statement: The LINK statement, often used in IBM’s CICS, is used to invoke a program but transfers control in a manner that allows the program to return control to the calling program at a later point.

Q3. What is the importance of INITIALIZE verb?
Ans: The INITIALIZE verb in COBOL is used to set all the data items of a specified storage area to their default values (e.g., numeric fields to zero and alphanumeric fields to spaces). This helps to avoid unexpected values in data items.

Example:

INITIALIZE WS-RECORD.

Q4. Explain the NEXT SENTENCE statement in COBOL?
Ans: The NEXT SENTENCE statement transfers control to the statement following the next period (.). It is different from the CONTINUE statement, which simply moves control to the next statement.

Example:

IF WS-CONDITION
   NEXT SENTENCE
ELSE
   DISPLAY 'Condition not met'.

Cobol Interview Questions for Freshers

Q5. How is PERFORM … WITH TEST AFTER different from PERFORM … WITH TEST BEFORE?
Ans:

  • PERFORM … WITH TEST AFTER: The loop body is executed at least once before the condition is tested.

    Example:
PERFORM UNTIL WS-EOF
    READ INPUT-FILE
    AT END
        SET WS-EOF TO TRUE
    END-READ
WITH TEST AFTER.

PERFORM … WITH TEST BEFORE: The condition is tested before the loop body is executed, which means the loop body may not execute if the condition is initially false.

Example:

PERFORM UNTIL WS-EOF
    WITH TEST BEFORE
    READ INPUT-FILE
    AT END
        SET WS-EOF TO TRUE
    END-READ.

Q6. How can you perform dynamic memory allocation in COBOL?
Ans: COBOL does not directly support dynamic memory allocation like modern languages. However, dynamic allocation can be achieved using tables or working-storage with OCCURS DEPENDING ON clause for variable-length data structures.

Example:

01 WS-TABLE.
   05 WS-ENTRY OCCURS 1 TO 100 TIMES DEPENDING ON WS-SIZE.
      10 WS-DATA PIC X(10).

Q7. How can COBOL be used in business?
Ans: COBOL is widely used in business for its ability to handle large volumes of data and complex transactions. It is particularly prevalent in banking, finance, and insurance industries for applications like payroll processing, transaction processing, and management of accounts.

Q8. Define the INPUT PROCEDURE and OUTPUT PROCEDURE?
Ans:

  • INPUT PROCEDURE: Used in the SORT statement to manipulate records before sorting. It is executed before the sorting process begins.

    Example:
SORT SORT-FILE
    ON ASCENDING KEY WS-KEY
    USING WS-UNSORTED
    INPUT PROCEDURE IS INPUT-PROCEDURE.

OUTPUT PROCEDURE: Used in the SORT statement to process records after sorting. It is executed after the sorting process is complete.

Example:

SORT SORT-FILE
    ON ASCENDING KEY WS-KEY
    GIVING WS-SORTED
    OUTPUT PROCEDURE IS OUTPUT-PROCEDURE.

Q9. Explain the use of EVALUATE statement?
Ans: The EVALUATE statement is similar to a CASE or SWITCH statement in other languages. It allows for multiple conditional checks in a clear and structured manner.

Example:

EVALUATE TRUE
   WHEN WS-VALUE = 1
      DISPLAY 'Value is 1'
   WHEN WS-VALUE = 2
      DISPLAY 'Value is 2'
   WHEN OTHER
      DISPLAY 'Other Value'
END-EVALUATE.

Q10. How do you load a table dynamically in COBOL?
Ans: A table can be loaded dynamically by reading data from an external source and populating the table during program execution using the OCCURS clause.

Example:

01 WS-TABLE.
   05 WS-ENTRY OCCURS 100 TIMES INDEXED BY WS-IDX.
      10 WS-DATA PIC X(10).

PERFORM VARYING WS-IDX FROM 1 BY 1 UNTIL WS-IDX > 100
   READ INPUT-FILE INTO WS-ENTRY (WS-IDX)
   AT END
      EXIT PERFORM
END-PERFORM.

Q11. Why does ABEND happen?
Ans: ABEND (Abnormal End) occurs when a program terminates unexpectedly due to errors such as data mismatches, out-of-bounds array accesses, division by zero, or file access issues. It signals that the program encountered an issue it couldn’t recover from.

Q12. How would you declare variables in COBOL?
Ans: Variables in COBOL are declared in the DATA DIVISION under the WORKING-STORAGE SECTION or LINKAGE SECTION. Each variable is defined with a level number, data type, and picture clause.

Example:

WORKING-STORAGE SECTION.
01 WS-NUMBER PIC 9(5).
01 WS-NAME   PIC X(20).

Q13. Differentiate between OS/VS COBOL and VS COBOL II?
Ans:

  • OS/VS COBOL: An older version of COBOL designed for the OS/VS operating system. It lacks many modern features and performance optimizations.
  • VS COBOL II: An updated version with enhancements such as structured programming, improved performance, and support for new data types and functions.

Q14. How is SSRANGE different from NOSSRANGE?
Ans:

  • SSRANGE: Enables subscript range checking, ensuring array indexes are within defined limits, which helps in debugging. Example:
PROGRAM-ID. MYPROG SSRANGE.

NOSSRANGE: Disables subscript range checking, which can improve performance but risks potential errors due to out-of-bounds access. Example:

PROGRAM-ID. MYPROG NOSSRANGE.

Q15. How is the NEXT SENTENCE statement different from CONTINUE statement?
Ans:

  • NEXT SENTENCE: Transfers control to the statement following the next period (.). It skips all code in between.
  • CONTINUE: Acts as a placeholder, transferring control to the next executable statement without skipping any code.

Q16. Mention any three Divisions of COBOL?
Ans: The three main divisions of a COBOL program are:

  • IDENTIFICATION DIVISION: Contains the program’s name and author information.
  • ENVIRONMENT DIVISION: Specifies the hardware and software environment.
  • DATA DIVISION: Defines the variables and data structures used.

Q17. How do we find the current date from the system within a century?
Ans: The current date can be retrieved using the intrinsic function CURRENT-DATE.

Example:

MOVE FUNCTION CURRENT-DATE TO WS-DATE.

Q18. What are the best practices to avoid ABEND?
Ans:

  • Proper Error Handling: Use error-handling routines to manage unexpected conditions.
  • Data Validation: Validate all input data before processing.
  • Boundary Checks: Ensure array indexes and other boundaries are checked.
  • Resource Management: Properly manage file and memory resources.

Q19. How can you implement multi-threading in COBOL programs?
Ans: Multi-threading in COBOL is achieved using the compiler directives and runtime options provided by the COBOL compiler and operating system. It typically involves managing multiple instances of COBOL programs running concurrently.

Q20. What is the importance of using REPLACING option in a COPY statement?
Ans: The REPLACING option in a COPY statement allows for the modification of specific text in the copied code, enabling reuse of code with minor adjustments without altering the original copybook.

Example:

COPY COPYBOOK REPLACING ==OLD-TEXT== BY ==NEW-TEXT==.

Q21. What is a COBOL paragraph?
Ans: A COBOL paragraph is a section of code within a division, specifically in the PROCEDURE DIVISION, that consists of one or more sentences or statements grouped together. It is used to organize and structure the code logically.

Example:

PARAGRAPH-NAME.
   DISPLAY 'This is a paragraph'.

Q22. What is the purpose of the INITIALIZE verb in COBOL, and when would you use it?
Ans: The purpose of the INITIALIZE verb is to set variables to their default values (numeric fields to zeros and alphanumeric fields to spaces). It is used to avoid unexpected values in variables before they are used.

Example:

INITIALIZE WS-RECORD.

Q23. How do you read and write sequential files in COBOL?
Ans: Sequential files are read using the READ statement and written using the WRITE statement. OPEN and CLOSE statements are used to manage file access.

Example:

OPEN INPUT INPUT-FILE.
READ INPUT-FILE INTO WS-RECORD
   AT END
      SET WS-EOF TO TRUE.
CLOSE INPUT-FILE.

OPEN OUTPUT OUTPUT-FILE.
WRITE WS-RECORD.
CLOSE OUTPUT-FILE.

Q24. How do you handle errors in COBOL programs?
Ans: Errors in COBOL programs can be handled using ON ERROR, INVALID KEY, and AT END clauses, along with user-defined error-handling routines.

Example:

READ INPUT-FILE INTO WS-RECORD
   AT END
      PERFORM HANDLE-END-OF-FILE
   INVALID KEY
      PERFORM HANDLE-ERROR.

Cobol Interview Questions for Experienced

Q25. Explain the usage of FILE STATUS in COBOL?
Ans: FILE STATUS is a mechanism in COBOL that allows for monitoring the success or failure of file operations. A FILE STATUS variable is defined and associated with a file, storing a status code after each file operation.

Example:

FILE STATUS IS WS-FILE-STATUS.
IF WS-FILE-STATUS NOT = '00'
   DISPLAY 'File error: ' WS-FILE-STATUS.

Q26. Why is S9(4) COMP needed despite knowing that Comp-3 would utilize less space?
Ans: S9(4) COMP is needed in COBOL for specific use cases where binary representation is more efficient for arithmetic operations. COMP (computational) format stores data in binary, which is faster for the system to process compared to COMP-3, which uses packed decimal format.

For example, S9(4) COMP uses 2 bytes of storage, while S9(4) COMP-3 uses 3 bytes. In scenarios where the system performs a lot of arithmetic calculations, using COMP can improve performance due to its direct binary processing capability.

Q27. What are the problems associated with using ordered sequential files?
Ans: Ordered sequential files have several limitations:

  • Access Time: They require linear search for accessing records, leading to slower access times compared to indexed files.
  • Maintenance: Adding or deleting records requires re-sequencing the entire file, which can be time-consuming.
  • Concurrency Issues: They are not well-suited for concurrent access, leading to potential data integrity issues.


For instance, if a file contains 10,000 records and you need to find the 9999th record, the system must sequentially read through 9998 records first, leading to inefficiency.

Q28. What are the object-oriented features provided in COBOL?
Ans: COBOL provides several object-oriented features including:

  • Classes and Objects: Define reusable code structures.
  • Inheritance: Enables new classes to inherit properties and methods of existing classes.
  • Encapsulation: Bundles data and methods that operate on the data within one unit.
  • Polymorphism: Allows methods to do different things based on the object it is acting upon.

For example, you can define a class Person with properties like Name and Age, and methods like DisplayDetails. A subclass Employee can inherit from Person and add additional properties like EmployeeID.

Q29. Under what circumstances are scope terminators mandatorily needed?
Ans: Scope terminators are mandatorily needed in the following circumstances:

  • Nested IF Statements: To clearly define the end of each IF statement.
  • PERFORM…END-PERFORM: To mark the end of a perform block.
  • EVALUATE…END-EVALUATE: To mark the end of an evaluate block.
  • READ…END-READ and WRITE…END-WRITE: To define the scope of read and write operations.

For example:

IF condition-1 THEN
   IF condition-2 THEN
      PERFORM action-1
   END-IF
END-IF

Q30. What is a COBOL copybook? What are the benefits of using these?
Ans: A COBOL copybook is a reusable set of COBOL code that can be included in multiple programs. It typically contains data definitions or file layouts.

Benefits:

  • Reusability: Promotes code reuse and consistency.
  • Maintainability: Easier to update since changes in the copybook reflect in all programs using it.
  • Standardization: Ensures standard data formats and structures across programs.

For example:

COPY CUSTOMER-RECORD.

Where CUSTOMER-RECORD contains standard definitions for customer data fields.

Q31. What are the causes of S0C7, S0C5, and S0C1?
Ans:

  • S0C7: Data exception error, typically caused by invalid data in a numeric field. Example: Moving alphanumeric data to a numeric field.
  • S0C5: Addressing error, usually due to invalid memory references. Example: Accessing storage not allocated to the program.
  • S0C1: Operation exception, often caused by an invalid machine instruction. Example: Trying to execute data as instructions.

Q32. What are the different divisions in COBOL programs?
Ans: COBOL programs are divided into four main divisions:

  • IDENTIFICATION DIVISION: Contains metadata about the program.
  • ENVIRONMENT DIVISION: Describes the system environment and file usage.
  • DATA DIVISION: Defines variables and data structures.
  • PROCEDURE DIVISION: Contains the actual code and logic.

For example:

IDENTIFICATION DIVISION.
PROGRAM-ID. SampleProgram.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

DATA DIVISION.
FILE SECTION.

PROCEDURE DIVISION.

Q33. How do we remove the spaces at the end of every record in an output file that is of variable length?
Ans: To remove spaces at the end of every record in a variable-length output file, you can use the STRING and UNSTRING operations.

Example:

STRING input-field DELIMITED BY SPACE INTO trimmed-field.

This removes trailing spaces from input-field and stores the result in trimmed-field.

Q34. How is INCLUDE different from COPY?
Ans:

  • INCLUDE: Typically used in JCL to include another JCL member within a JCL stream.
  • COPY: Used in COBOL to include copybook content within a COBOL program.

Example for COPY in COBOL:

COPY MY-COPYBOOK.

Example for INCLUDE in JCL:

//INCLUDE MEMBER=MY-JCL-MEMBER

Q35. Explain sequential and index files?
Ans:

  • Sequential Files: Records are stored one after another in sequence. Access is linear and typically slow for large files.
  • Indexed Files: Contains an index for faster access to records. Allows direct access using key values, making it more efficient for large datasets.

Example for Sequential File:

SELECT SEQFILE ASSIGN TO 'SEQFILE.DAT'.

Example for Indexed File:

SELECT IDXFILE ASSIGN TO 'IDXFILE.DAT'
       ORGANIZATION IS INDEXED
       ACCESS MODE IS DYNAMIC
       RECORD KEY IS idx-key.

Q36. What do you understand by the following terminologies?
Ans: Here are explanations for some common COBOL terminologies:

WORKING-STORAGE SECTION: This is a part of the DATA DIVISION in a COBOL program where variables are defined and initialized. These variables are available throughout the program’s execution. Example:

WORKING-STORAGE SECTION.
01 WS-VARIABLE PIC 9(5) VALUE 0.

FILE SECTION: This section within the DATA DIVISION is used to define the structure and layout of the files that the program will access. Example:

FILE SECTION.
FD INPUT-FILE.
01 INPUT-RECORD PIC X(80).

LINKAGE SECTION: This section is used to define data that is passed between programs or between the main program and subprograms. Example:

LINKAGE SECTION.
01 LK-VARIABLE PIC 9(5).

ENVIRONMENT DIVISION: This division specifies the environment in which the program will run, including the configuration and external files. Example:

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.

PROCEDURE DIVISION: This division contains the executable statements of the program. It includes the logic and procedures that manipulate the data defined in the DATA DIVISION. Example:

PROCEDURE DIVISION.
DISPLAY 'Hello, World'.

SECTION and PARAGRAPH: A SECTION is a logical grouping of paragraphs within the PROCEDURE DIVISION, and a PARAGRAPH is a logical unit of code within a SECTION.
Example:

SECTION-A.
PARAGRAPH-1.
    DISPLAY 'This is a paragraph within SECTION-A'.

PIC (Picture) Clause: The PIC clause defines the type and size of a data item. Example:

01 CUSTOMER-NAME PIC X(25).

REDEFINES Clause: Allows a data item to share the same storage area as another data item, providing different views of the same memory location. Example:

01 DATE-FIELD.
    05 DATE-YY PIC 9(4).
    05 DATE-MM PIC 9(2).
    05 DATE-DD PIC 9(2).
01 DATE-REDEFINED REDEFINES DATE-FIELD PIC X(8).

VALUE Clause: Specifies an initial value for a data item.
Example:

01 WS-NUMBER PIC 9(3) VALUE 100.

SIGN Clause: Specifies the position and presence of a sign in a numeric field.
Example:

01 AMOUNT PIC S9(5)V99.

These are some of the fundamental terminologies in COBOL, each playing a crucial role in the structure and functionality of COBOL programs.

Q37. How can we reference or make COBOL program realize that about the following file formats?
Ans:In COBOL, you can define and reference different file formats using the FILE CONTROL section and the FILE SECTION. Here’s how you can handle various file formats:

Sequential Files

Definition: Sequential files are files where records are stored one after another in a sequential manner. Access to the records is done sequentially.

Example:

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT SEQ-FILE ASSIGN TO 'SEQFILE.DAT'
    ORGANIZATION IS SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD  SEQ-FILE.
01  SEQ-RECORD PIC X(80).

Indexed Files:

Definition: Indexed files use an index to allow both sequential and random access to records. They are organized by keys.

Example:

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT IDX-FILE ASSIGN TO 'IDXFILE.DAT'
    ORGANIZATION IS INDEXED
    ACCESS MODE IS DYNAMIC
    RECORD KEY IS IDX-KEY.

DATA DIVISION.
FILE SECTION.
FD  IDX-FILE.
01  IDX-RECORD.
    05 IDX-KEY    PIC X(10).
    05 IDX-DATA   PIC X(70).

Relative Files

Definition: Relative files store records based on their relative position within the file, allowing random access using the relative record number.

Example:

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT REL-FILE ASSIGN TO 'RELFILE.DAT'
    ORGANIZATION IS RELATIVE
    ACCESS MODE IS RANDOM
    RELATIVE KEY IS REL-KEY.

DATA DIVISION.
FILE SECTION.
FD  REL-FILE.
01  REL-RECORD.
    05 REL-KEY    PIC 9(4).
    05 REL-DATA   PIC X(76).

Line Sequential Files

Definition: Line sequential files are a type of sequential file where each record is terminated by a newline character, typically used for text files.

Example:

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT LINE-SEQ-FILE ASSIGN TO 'LINESEQ.TXT'
    ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD  LINE-SEQ-FILE.
01  LINE-SEQ-RECORD PIC X(80).

Variable Length Files

Definition: Variable length files contain records of varying lengths. COBOL uses the RECORD VARYING clause to define such files.

Example:

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT VAR-FILE ASSIGN TO 'VARFILE.DAT'
    ORGANIZATION IS SEQUENTIAL
    RECORD IS VARYING FROM 10 TO 100 CHARACTERS
    DEPENDING ON WS-REC-LEN.

DATA DIVISION.
FILE SECTION.
FD  VAR-FILE.
01  VAR-RECORD.
    05 WS-REC-LEN  PIC 9(3).
    05 VAR-DATA    PIC X(97).

VSAM Files (Virtual Storage Access Method)

Definition: VSAM files are advanced file formats used in mainframe environments. There are different types of VSAM files, such as Key-Sequenced Data Sets (KSDS), Entry-Sequenced Data Sets (ESDS), and Relative Record Data Sets (RRDS).

Example for KSDS:

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT VSAM-FILE ASSIGN TO 'VSAMFILE'
    ORGANIZATION IS INDEXED
    ACCESS MODE IS DYNAMIC
    RECORD KEY IS VSAM-KEY.

DATA DIVISION.
FILE SECTION.
FD  VSAM-FILE.
01  VSAM-RECORD.
    05 VSAM-KEY    PIC X(10).
    05 VSAM-DATA   PIC X(90).

By defining these formats in the FILE CONTROL and FILE SECTION, you can make your COBOL program understand and handle different types of files effectively.

Q38. Which is the default, TEST BEFORE or TEST AFTER, for a PERFORM statement?
Ans: TEST BEFORE is the default for a PERFORM statement. This means the condition is tested before executing the loop.

Example:

PERFORM UNTIL condition
   statements
END-PERFORM.

Q39. What do you understand by static and dynamic linking?
Ans:

  • Static Linking: All subroutines are linked and compiled into the main program at compile time.
  • Dynamic Linking: Subroutines are linked at runtime, allowing updates without recompiling the main program.

Example of Dynamic Linking:

CALL 'SUBPROGRAM' USING parameters.

Q40. What is the PIC clause in COBOL?
Ans: The PIC (Picture) clause specifies the data type and size of a field.

Example:

77 VAR-NAME PIC 9(5).

This defines a numeric field VAR-NAME of length 5.

Q41. Mention three components of COBOL as a business language?
Ans:

  • File Handling: Extensive capabilities for handling various file types.
  • Data Division: Structured data definitions for complex business data.
  • Procedure Division: Clear and readable logic flow, ideal for business applications.

Q42. What are the differences between Structured COBOL and Object-Oriented COBOL programming?
Ans:

  • Structured COBOL: Emphasizes procedural programming with structured control statements.
  • Object-Oriented COBOL: Adds classes, objects, inheritance, and other OOP concepts to COBOL.

Example of Object-Oriented COBOL:

CLASS-ID. MyClass.
METHOD-ID. MyMethod.

Q43. Why should the file be opened in I-O mode when it is being used for REWRITE purposes?
Ans: A file should be opened in I-O mode for REWRITE purposes because it allows both reading and writing operations. REWRITE requires reading the record before updating it.

Example:

OPEN I-O MYFILE.
READ MYFILE INTO record-area.
REWRITE MYFILE FROM record-area.

Q44. What are Call By Reference and Call By Content in COBOL?
Ans:

  • Call By Reference: Passes the address of the variable, allowing the subprogram to modify the caller’s data. Example:
CALL 'SUBPROGRAM' USING BY REFERENCE var-name.

Call By Content: Passes a copy of the variable, preventing the subprogram from modifying the caller’s data. Example:

CALL 'SUBPROGRAM' USING BY CONTENT var-name.

Click here for more related topics.

Click here to know more about COBOL.

About the Author