Top COBOL Interview Questions to Master in 2023 - IQCode

Introduction to COBOL

COBOL, short for Common Business Oriented Language, is one of the oldest high-level programming languages. It was specifically developed to ensure the readability and portability of the code across different mainframe systems. Despite its age, COBOL still holds great significance in today's software industry, due to its capacity to perform advanced computations towards accomplishing business objectives. As a result, there has been a surge in demand for mainframe developers who have knowledge of COBOL. In this article, we will look at the most frequently asked interview questions for both freshers and experienced professionals that will help them succeed in COBOL interviews.

Take a free mock interview to receive instant feedback and recommendations:

Take Free Mock Interview

COBOL Interview Questions for Freshers

1. What is COBOL?

Available Data Types in COBOL Language

In COBOL, there are several available data types that can be used for declaring variables. These include: - Alphanumeric (PIC X) - Numeric (PIC 9) - Alphabetic (PIC A) - Decimal (PIC S) - Date (PIC 9(8)) - Time (PIC 9(6)) Using the appropriate data type is crucial in ensuring that the variable can store the desired type of data and that it can be processed correctly.

Differences between "next" and "continue" statements in programming

In programming, "next" and "continue" are two distinct statements that serve different purposes.

The "continue" statement is used within loops to skip the current iteration and move to the next iteration of the loop. It is useful when you want to avoid executing some code for a certain iteration of the loop.

On the other hand, the "next" statement is used in nested loops to skip the current iteration of the inner loop and move to the next iteration of the outer loop. It is used when you want to bypass the remaining iterations of the inner loop for the current value of the outer loop.

In summary, the main difference between "continue" and "next" statement is that "continue" skips the remaining code within the current iteration of a loop, while "next" skips the remaining iterations of a nested loop for the current iteration of the outer loop.

What is a Numeric Clause?

A Numeric Clause is a condition that evaluates if a given value is a numeric or not. It is commonly used in programming languages to check if an input provided by a user is a number or not.

if (is_numeric($inputValue)) {
   // Do something if input is a number
} else {
   // Do something else if input is not a number

In the above example, the


function checks whether the value of the


variable is a numeric value or not. If the input value is numeric, the code block inside the


statement is executed, otherwise the code block inside the


statement is executed.

Importance of Using the REPLACE Option in a COPY Statement

When performing a COPY statement to transfer data from one table to another, the REPLACE option can be useful. It allows for the existing data in the receiving table to be replaced with the new data being copied over. This is advantageous in situations where the data being copied is intended to replace any existing data in the receiving table, rather than simply being appended to it.

Without using the REPLACE option, if the receiving table already contains data, the COPY statement will result in duplicate data being added rather than replacing the existing data. This can lead to errors in the data and an undesired increase in the table size.

Therefore, using the REPLACE option can ensure that the receiving table contains only the most up-to-date and accurate data.

SSRange vs NoSSRange: What's the difference?

In the context of this question, I assume that SSRange and NoSSRange refer to two different APIs or programming libraries. However, without further information, it's impossible to provide a detailed comparison of the two.

In general, "SS" and "NoSS" might stand for "server-side" and "non-server-side," respectively. If that's the case, then SSRange likely refers to an API or library that can be run on the server-side, while NoSSRange cannot be run on a server.

Ultimately, more information is needed to provide a thorough explanation of the differences between the two.

How is "perform...with test after" different from "perform...with test before"?

"Perform...with test after" means executing a code block first and then testing its output or results. On the other hand, "perform...with test before" means testing the code block before executing it to ensure that it meets the desired specifications. Essentially, "perform...with test after" is a way to test and verify the results of an already written code, while "perform...with test before" is a way to ensure that a code will meet the desired specifications before it is written and executed.

// Example of perform...with test after
function calculateSum(x, y) {
  return x + y;
console.log(calculateSum(2, 3)); // Output: 5

// Example of perform...with test before
describe('calculateSum function', () => {
  it('should return the sum of two numbers', () => {
    expect(calculateSum(2, 3)).toBe(5);

Input and Output Procedures

During the input procedure, data is entered into the system through various devices such as a keyboard, mouse, scanner, etc. The data is then processed by the system and stored in the appropriate location.

On the other hand, during the output procedure, data is retrieved from the system and presented to the user through various output devices such as a monitor, printer, speakers, etc. The data is presented in a readable format that the user can understand and make use of.

It is worth noting that the input and output procedures are integral parts of the overall data processing cycle. Both procedures work together to ensure that the system processes and presents data accurately and efficiently.

Why do we need the Linkage Section?

The Linkage Section is necessary in COBOL programming language. It is used to link data between the calling program and the called program. When a program is called, data is moved between the calling program and the called program. This data must be defined in the Linkage Section of the called program. It is also used to define external data items used by the program but are not defined within it.

Reasons for not defining occurs clause at 01 level

It is generally not recommended to define the "occurs" clause at the 01 level in COBOL programming due to the following reasons:

  • This can lead to memory wastage as COBOL allocates memory for all the occurrences of the data item, even if they are not needed.
  • It can also result in performance issues since the program needs to allocate memory for all the occurrences at once.
  • It can be difficult to read and maintain the code if the "occurs" clause is defined at the top-level since it may not be clear how many times the data item will occur within the record.


   02 NAME PIC X(20).
   02 CUSTOMER-ID PIC X(10).
   02 ADDRESS.
      03 LINE-1 PIC X(40).
      03 LINE-2 PIC X(40).
      03 ORDER-NUMBER PIC 9(5).
      03 ORDER-AMOUNT PIC 9(5)V99.
      03 ORDER-DATE PIC 9(8).

In the above example, the "occurs" clause is defined within the "CUSTOMER-INFO" record instead of at the 01 level. This allows for more efficient memory allocation and promotes better code readability and maintenance.

How to Retrieve Current Date within a Century from System?

To get the current date within a century from the system, you can use the built-in functions of your programming language. Below is an example in Python:

import datetime

current_year =
century_start_year = (current_year // 100) * 100
current_date_within_century ="%Y-%m-%d")

print("Current date within century: ", current_date_within_century)

This code will retrieve the current year from the system and calculate the start year of the century. Then, it will format the current date with the year within the century and print the result.

Difference between CALL command and LINK

The CALL command is used to run a batch file within another batch file, allowing the calling batch file to continue executing once the other batch file has finished running.

On the other hand, the LINK command is used to create an executable file from one or more object files. It is commonly used in C or C++ programming.

Importance of the Initialize Verb

The initialize verb is important in programming as it is used to set initial values to variables, arrays, and other data structures. Initializing variables helps to avoid unexpected behavior, errors, or crashes that could arise from the use of uninitialized data. It also helps in the readability and maintenance of code, making it easier for other developers to understand the purpose and functionality of the program. Therefore, it is crucial to use the initialize verb at the beginning of a program or at the declaration of a variable to ensure proper functionality of the program.

Differences between OS/VS COBOL and VS COBOL II

OS/VS COBOL and VS COBOL II are two versions of COBOL programming language used in IBM mainframe systems. The main differences between them are:

1. Performance:

VS COBOL II is faster than OS/VS COBOL as it has improved handling of tables and indexes, and optimized instructions for string manipulation.

2. Compatibility:

VS COBOL II is more compatible with newer IBM mainframe systems compared to OS/VS COBOL, which may require modifications when migrating to newer systems.

3. Language features:

VS COBOL II has additional language features such as sign trailing, improved handling of indexes, and improved debugging capabilities.

4. Error handling:

VS COBOL II has improved error handling capabilities and provides more descriptive error messages compared to OS/VS COBOL.

Overall, VS COBOL II is a more advanced and optimized version of COBOL compared to OS/VS COBOL, with improved performance, compatibility, and language features.

Understanding Static and Dynamic Linking

Static and dynamic linking are two methods used in programming to combine and execute software with external libraries.

Static Linking: In static linking, the external libraries are compiled into the binary file of the program during the build process. This means that the code from the libraries is included in the final executable file, making it self-contained and independent. The advantages of static linking are faster loading times and no dependencies on external libraries, but the drawback is a larger executable file size.

Dynamic Linking: In dynamic linking, the external libraries are loaded into the program during runtime. This means that the code from the libraries is not included in the executable file, making it smaller in size. The advantages of dynamic linking are smaller file sizes and the ability to make changes to libraries without recompiling the entire program. However, the drawback is a longer loading time due to the need to locate and load the external libraries at runtime.

Ultimately, the choice between static and dynamic linking depends on the requirements of the program and the preferences of the developer.

Object Oriented Features in COBOL

COBOL provides the following Object Oriented features:

- Encapsulation: COBOL supports encapsulation of data using the "private" and "public" keywords. Private data is only accessible within the same class, while public data is accessible outside the class.

- Inheritance: COBOL supports inheritance where a new class can be created from an existing class. The new class will have access to all the data and methods of the existing class.

- Polymorphism: COBOL supports polymorphism where a method can be defined with multiple implementations. The implementation used is determined at runtime based on the actual object being operated on.

- Abstraction: COBOL supports abstraction where complex data types can be defined without exposing their internal details. This simplifies the code and makes it easier to use.

- Class and Object: COBOL supports the creation of classes and objects, allowing code to be organized into reusable modules. Classes define the properties and methods of an object, while objects are instances of a class that can be created and manipulated at runtime.

Guidelines for Developing a Structured COBOL Program

There are several guidelines that can be followed while developing a structured COBOL program to ensure its readability, maintainability, and efficiency.

1. Use a standard program structure that includes proper indentation and consistent naming conventions for variables and procedures.

2. Implement modular programming by breaking down the program into smaller, more manageable modules.

3. Use meaningful comments to make the code more readable and explain the purpose of each section of code.

4. Use the COPY statement to reduce redundant code and improve readability.

5. Use structured programming constructs such as IF-THEN-ELSE, PERFORM, and EVALUATE to write concise and efficient code.

6. Use subroutines and functions to perform common operations that are used in multiple parts of the program.

7. Avoid using too many GO TO statements and instead use structured loops and conditional statements.

8. Use the COBOL compiler options to check the program for common errors and warnings.

By following these guidelines, a structured COBOL program can be developed that is easy to read, maintain, and enhance over time.

Divisions in COBOL Programs

In COBOL programming, there are four divisions that organize the program structure and flow:

- Identification Division: Contains the program's name and other information about it. - Environment Division: Describes the environment in which the program runs, such as the computer, files, and devices used. - Data Division: Defines the data used in the program, including variables, constants, and data structures. - Procedure Division: Contains the logic or instructions for the program's processing.

Each division serves a specific purpose and helps to make the program easier to understand and modify. By organizing the program into these divisions, it is easier to maintain and update the code over time.

Sorting in COBOL Programs

In COBOL programs, sorting can be achieved using the SORT verb. It allows the data to be sorted in ascending or descending order based on the key fields. The SORT verb requires an input procedure division and an output procedure division to be specified. The input procedure is responsible for providing the data to be sorted, while the output procedure handles the sorted data. Additionally, the key structure must be defined in the data division of the program. Overall, the SORT verb provides a simple and straightforward solution for sorting data in COBOL programs.

Reasons for opening a file in I-O mode for rewrite purposes

When we open a file in I-O mode (Input-Output) in a programming language, it means that the file can be both read and written. This is particularly useful when we want to perform operations like changing the records within the file, and rewriting the file. Here are some reasons why the file should be opened in I-O mode for rewrite purposes:

  • It allows for both reading and writing operations on the file
  • It enables us to modify the existing records within the file
  • It makes it easy to delete records that are no longer needed
  • It helps us save time and resources, as we can modify the file without having to create a new one, and without having to read it entirely into memory first

is the section of a file handling program that specifies the files to be used in the program, and how they should be handled. In this section, the programmer specifies the names of the files to be used, as well as the access mode in which they should be opened. When a file is opened in I-O mode, it means that the file exists already and can be both read from and written to. Therefore, before opening a file in I-O mode, it's important to make sure that the file you want to open exists, and that it can be modified as intended.

How to remove trailing spaces from variable length output file records?

One way to remove trailing spaces from variable length records in an output file is to use a programming language that supports string manipulation. For example, in Python, we can use the strip() method to remove whitespace from the end of each record.

Here's some sample code to demonstrate how to read from a file, strip trailing whitespace from each line, and write the result to a new file:

with open("input.txt", "r") as input_file, open("output.txt", "w") as output_file:
    for line in input_file:
        stripped_line = line.rstrip() # Removes trailing whitespace from each line
        output_file.write(stripped_line + "\n")

In this example, we use the built-in `open()` function to open both the input and output files. We then loop through each line in the input file, use the `rstrip()` method to remove trailing whitespace, and write the result to the output file.

This code will generate a new file called "output.txt" with the same records as the input file, but with trailing spaces removed.

Processing Two Files by Comparing Key Fields

To process two files by comparing key fields, you can use the following algorithm:

1. Read the first file and store the key field values in a list or dictionary. 2. Read the second file and for each record, check if the key field value is in the list or dictionary. 3. If the key field value is found, process the record accordingly (e.g., update the corresponding record in the first file). 4. If the key field value is not found, add the record to the first file.

Here's an example implementation in Python:

# Open the first file and store the key field values in a dictionary
with open('file1.txt') as f1:
    f1_dict = {}
    for line in f1:
        key = line.split(',')[0]  # assuming the key field is the first column
        f1_dict[key] = line

# Open the second file and process each record
with open('file2.txt') as f2:
    for line in f2:
        key = line.split(',')[0]  # assuming the key field is the first column
        if key in f1_dict:
            # Do something with the matching record in file1
            # Add the record to file1
            with open('file1.txt', 'a') as f1:
                f1_dict[key] = line

Note that this is a simple example and may need to be modified depending on the specific requirements of your use case.

How to Inform COBOL Program about Different File Formats?

To inform a COBOL program about different file formats, we can use the SELECT and ASSIGN statements to specify the file and its attributes such as organization, access mode, and record format. The file format can be sequential, indexed, or relative. The SELECT statement is used to identify the file and its organization, while the ASSIGN statement is used to specify the file name and its attributes. It is important to ensure that the file formats referenced in the program match with the actual file formats used.

Differences between Structured COBOL and Object-Oriented COBOL Programming

Structured COBOL follows a traditional procedural programming approach, where the program is composed of a series of modules, each of which performs a specific function. It mainly focuses on the structure of the program and uses structured programming constructs such as loops, conditionals, and functions to achieve program tasks.

On the other hand, Object-Oriented COBOL follows an object-oriented programming (OOP) approach, where the program is composed of a collection of objects that interact with each other to perform tasks. It primarily focuses on the real-world entities and uses classes, objects, inheritance, and encapsulation to achieve program tasks.

In summary, structured COBOL is best suited for developing simple applications, while object-oriented COBOL is ideal for developing complex applications because of its ability to handle large codebases that can be easily managed and maintained.

Causes of S0C7, S0C5, and S0C1 Errors

S0C7, S0C5, and S0C1 are errors that can occur in mainframe systems. The causes of these errors are as follows:

- S0C7: This error occurs when a program attempts to perform an operation on a data item that is outside of its defined boundaries or when it encounters an un-initialized numeric field. To resolve this error, you should check the program logic and correct any coding errors.

- S0C5: This error occurs when a program attempts to access a storage area that is not available or has been released. To resolve this error, you should check for missing parameters or parameters that are not initialized properly.

- S0C1: This error is caused by an invalid instruction or an illegal address. It typically occurs when there is a problem with the program code or an attempt is made to execute data as code. To resolve this error, you should verify the program code and correct any coding errors.

When are Scope Terminators Mandatory?

Scope terminators are mandatorily needed in the following circumstances:

- When defining nested control statements
- When declaring multiple variables in a single statement
- When defining functions or methods with more than one statement

In these situations, scope terminators are required to clearly indicate where a block of code ends so that the program can be executed correctly. Failure to use scope terminators can lead to syntax errors and program crashes.

Problems with using Ordered Sequential Files

There are several problems that come with using ordered sequential files:

  1. Inserting or deleting records can be difficult and inefficient, as it may require shifting large portions of the file.
  2. Accessing data within the file can be slow, especially if searching for a specific record requires scanning through a large portion of the file.
  3. If the file becomes corrupted, it may be difficult to recover the data.
  4. Concurrency and sharing the data across multiple users or applications can be tricky, as updating the file requires exclusive access.
// example code using ordered sequential file

Difference Between "Include" and "Copy"

In programming, the terms "include" and "copy" might seem similar, but they serve different purposes. "Include" is used to bring code from another file to the current file, where it can be compiled, executed, and modified. This is often done to avoid writing the same code multiple times or to modularize code.

On the other hand, "copy" refers to making a duplicate of a file or piece of code in a new location. This is often done to maintain a backup or to have multiple versions of the same code.

In summary, both "include" and "copy" have their own purposes in programming, and understanding the difference between the two is important for writing efficient and organized code.I'm sorry, I cannot answer this question without more context. Can you provide me with more information or clarify what terminologies you are referring to?

Why do we need S9(4) COMP when COMP-3 uses less space?

In COBOL, both S9(4) COMP and COMP-3 are used for storing numeric data. While it is true that COMP-3 uses less space compared to S9(4) COMP, there are certain scenarios where S9(4) COMP is preferred.

One reason is compatibility with other programming languages. S9(4) COMP uses binary storage format which is used by many other languages. This makes it easier to exchange data between different systems. On the other hand, COMP-3 uses a packed decimal format which may not be compatible with other languages.

Another reason is performance. S9(4) COMP is faster to process compared to COMP-3 because it uses binary arithmetic which is simpler and faster for computers to execute. This is important in applications where speed is critical.

In conclusion, while COMP-3 may be more space-efficient, S9(4) COMP has advantages in terms of compatibility and performance that make it a useful option in certain situations.

Program accessing 21st item in an array doesn't abend

In some programming languages, when a program tries to access an element outside the boundaries of an array, it can result in a runtime error called an "array out of bounds" exception. However, in some languages like C, C++, and others, the program may not abend or terminate unexpectedly when it tries to access an invalid element address outside the bounds of an array. Instead, it may give unpredictable results and cause memory corruption or overwrite other program variables. Therefore, it is essential to employ proper boundary checks and safeguards in the program to avoid such errors.

COBOL Sample Program: Displaying Names of Students in a Class

PROGRAM-ID. Display-Student-Names.

01 Student-Names.
   05 Student-Name-Input PIC X(20) OCCURS 30 TIMES.
01 Num-Students PIC 9(2).
01 I PIC 9(2).

DISPLAY "Enter the number of students in the class".
ACCEPT Num-Students.

DISPLAY "Enter the names of the students:".
   DISPLAY "Student " I ":".
   ACCEPT Student-Name-Input(I)

DISPLAY "The names of the students are:".
   DISPLAY Student-Name-Input(I)


This COBOL program allows users to enter the names of students in a class and then displays them using the OCCURS clause. The program prompts the user to enter the number of students in the class and then prompts them to enter each student's name. Finally, the program displays the names of all the students entered by the user.

COBOL program for addition and multiplication of two numbers


01 NUM1 PIC 9(3).
01 NUM2 PIC 9(3).
01 SUM PIC 9(4).
01 PRODUCT PIC 9(6).

DISPLAY "Enter first number: ".

DISPLAY "Enter second number: ".


DISPLAY "The sum is: ", SUM.
DISPLAY "The product is: ", PRODUCT.


Delete Matching Records from a File using COBOL


     05 INPUT-NAME         PIC X(20).
     05 INPUT-AGE          PIC 9(3).
     05 INPUT-GRADE        PIC X(2).
     05 OUTPUT-NAME        PIC X(20).
     05 OUTPUT-AGE         PIC 9(3).
     05 OUTPUT-GRADE       PIC X(2).
 01 MATCH-FOUND           PIC X(3) VALUE 'NO '.
 01 WS-EOF-FLAG           PIC X(3) VALUE 'NO '.
 01 WS-ERR-FLAG           PIC X(3) VALUE 'NO '.

     STOP RUN.

This is an example program to demonstrate the process of deleting matching records from a file using COBOL. In this program, the file to be checked for matching records is named 'INPUT-FILE.DAT' and the output file is named 'OUTPUT-FILE.DAT'. The program will match a record with name 'JOHN' and age '25'. If a record matches, the program will skip it and write all other records to the output file. The final output file will not have any records that match the given criteria.

Technical Interview Guides

Here are guides for technical interviews, categorized from introductory to advanced levels.

View All

Best MCQ

As part of their written examination, numerous tech companies necessitate candidates to complete multiple-choice questions (MCQs) assessing their technical aptitude.

View MCQ's
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.