Top COBOL Interview Questions (2021) - InterviewBit

### Before you go!

Take this "COBOL Interview Questions" interview guide with you

## Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

College/University *
Enter the name of your college
Branch *
Year of completion *

College/University *
Enter the name of your college
Branch *
Year of completion *

Current Company *
Enter company name
Experience *

## Begin your success journey!

Full name *
Email *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Email *

# COBOL Interview Questions

## Begin your success journey!

Full name *
Email *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

## Welcome back!

Email *

### Introduction to COBOL

COBOL stands for Common Business Oriented Language which is one of the oldest high-level programming languages that was developed mainly for readability and portability of the code across different mainframe systems. Despite being the oldest programming language, it has gained huge importance in the software industry due to its ability to perform advanced computations for achieving different business objectives. Due to this, the need for mainframe developers having COBOL knowledge has grown rapidly. In this article, we will see the most commonly asked interview questions for both freshers and experienced professionals that will help them ace the COBOL interviews.

Crack your next tech interview with confidence!
Take a free mock interview, get instant⚡️ feedback and recommendation💡

## Cobol Interview Questions for Freshers

### 1. What is COBOL?

COBOL stands for Common Business Oriented Language and is one of the oldest high-level programming languages used for solving complex business problems in different domains like business verticals, finance, security and administrative purposes. Following are the features of this programming language:

• Simplicity: It is an easy-to-learn language with a simple and wide vocabulary for syntax and has an uncluttered style of coding.
• Business-oriented capabilities: COBOL has advanced capabilities for file handling that let it operate on huge data and can be used for simple to complex processing operations thereby being it the most popular technology for handling business transactions.
• Universality: COBOL is one of the oldest programming languages and has survived for more than 6 decades across growing business needs and has adapted across almost every platform, product and compiler.
• Scalability: COBOL is highly scalable, reliable and is also portable across different platforms. They provide variables control structures that make it easy to read, debug and modify.

### 2. What are the available data types in the COBOL language?

There are mainly three data types supported by COBOL, they are:

• Numeric data type – Used for representing numerical values between 0-9.
• Alphabetic data type – Used for representing alphabetic values ranging from A-Z.
• Alphanumeric data type – Used for representing both numeric and alphabetic types.

### 3. How is the NEXT SENTENCE statement different from CONTINUE statement?

The CONTINUE statement is like a null statement that indicates no operation and the control needs to be passed to the next executable instruction after explicit scope terminator. It can be used anywhere in conditional statements or imperative statements are used. Example syntax for CONTINUE in case of IF construct is:

IF condition-1 THEN
{statement-1 ...    | CONTINUE}
[ELSE {statement-2 ... | CONTINUE}]
[END-IF]

The NEXT SENTENCE statement does the task of simply transferring the control to an implicit CONTINUE statement that is present immediately after the next separator period. If the statement is specified along with the END-IF statement then the control passes to the statement after the closest following period. It is mainly used to transfer control to the next sentence.

IF condition-1 THEN
{statement-1 ... | NEXT SENTENCE}

### 4. What is IS NUMERIC clause?

This clause is used for checking if an item is a numeric value or not. If it is numeric - positive or negative, TRUE will be returned. For example:

CHECK-NUMBER SECTION.
DISPLAY 'Check if input is numeric ' INPUT-NUM
IF INPUT-NUM IS NUMERIC
DISPLAY 'input is numeric'
ELSE
DISPLAY 'input is non numeric'

### 5. What is the importance of using REPLACING option in a COPY statement?

REPLACING option is used for allowing the same copy to be used multiple times by changing the replace value in the same code.
Syntax COPY <VariableName> REPLACING BY

### 6. How is SSRANGE different from NOSSRANGE?

Both are options used by the compiler for finding subscript outside of range.
SSRANGE is used for handling the overflow of an array systematically. It needs to be specified explicitly which helps in finding exact subscript outside of range. Whereas the NOSSRANGE is used in cases of very sensitive applications that are driven by performance. It is the default option that gets applied and need not be specified explicitly and it does not support runtime errors whenever the index goes out of range.

### 7. How is PERFORM … WITH TEST AFTER different from PERFORM … WITH TEST BEFORE?

PERFORM ... WITH TEST BEFORE indicates that the condition must be tested at the beginning of every execution of the specified PERFORM range. Whereas TEST AFTER is used for testing the condition after every execution.

### 8. What happens during INPUT PROCEDURE and OUTPUT PROCEDURE?

In INPUT PROCEDURE, the input file will be opened, the records from the file are read and can also be edited. The records will then be released to sorting operation and then the file will be closed. Whereas in OUTPUT PROCEDURE, the output file will be opened, the records post sorting will be written in the output file and then the file will be closed.

### 9. Why is LINKAGE SECTION needed?

It is used for passing data from one program to another. It can also be used for passing data from a procedure to another program. It maps data in the calling program’s working storage.

### 10. Why should we not define OCCURS clause at 01 level?

01 level is the level of record. We can repeat the fields within a record but we cannot repeat the record itself. The OCCURS clause indicates the repetition of the definition of data names. This is why we cannot use the OCCURS clause at the 01 level.

### 11. How do we find current date from the system within a century?

We can find it out by using the Intrinsic function called FUNCTION CURRENT-DATE. We can also make use of the DATE function for accepting the current date. It has to be noted that the current date cannot be accepted if we are using CICS COBOL programs.

### 12. How is CALL command different from LINK?

CALL command is an actual command that initiates an external program and returns. The LINK command is also similar to CALL but it does not belong to COBOL verb vocabulary. The LINK command runs like a separate run unit whereas CALL is executed as a single run unit.

### 13. What is the importance of INITIALIZE verb?

INITIALIZE verb is used for initializing values in data items to their default value. Numeric items will be set to 0, alphabetic and alphanumeric items will be set to spaces. Items like FILLERS, OCCURS DEPENDING ON are to be left untouched during the initialization.

### 15. What do you understand by static and dynamic linking?

Static and dynamic linking are two types of linking available in COBOL. Static linking refers to the linking of subroutine into calling program and not existing as a separate module. In dynamic linking, the subroutine exists as a separate program and does not link to the main program. The static linking can be done by using the NODYNAM link option and the dynamic linking can be done by using the DYNAM option.

### 16. What are the object oriented features provided in COBOL?

Object-Oriented COBOL provides the following features:

• Define classes and let programs define and create objects of those classes.
• Data encapsulation is due to the ability to create objects. The data properties will be encapsulated in the objects.
• Behaviour of objects can be defined for the class by means of methods.
• Inheritance is supported in COBOL.
• Provides maximum flexibility by means of polymorphism and defining interfaces.
• Also compatible with procedural programming.

## Cobol Questions for Experienced

### 17. What are some of the guidelines that can be followed while developing a structured COBOL program?

Certain guidelines need to be followed while writing a structured COBOL program.

• When developing the CASE construct, we can use EQUIVALENT statements.
• We can use Scope Terminators while using nested constructs.
• We can also try using IN-LINE PERFORM statements whenever possible when we want a program to perform something.
• To perform a proper conditional check, we can also try using TEST BEFORE and TEST AFTER statements while using loop constructs to ensure desired results.

### 18. What are the different divisions in COBOL programs?

There are mainly 4 divisions in a COBOL program, they are:

• IDENTIFICATION DIVISION: This is the most important division that is used for identifying the program. This division is needed for any COBOL program to run. If this division is not included in your program, then the program cannot be compiled.
• ENVIRONMENT DIVISION: This division is subdivided into 2 types - Configuration and Input-Output section. They define the written program’s environment.
• DATA DIVISION: This division is used for identifying the data items, allocating proper memory and defining the names within the program. It also has a file, linkage section and working storage.
• PROCEDURE DIVISION: This division supports the main logic of the program. It should consist of at least one statement for using user-defined variables.

### 19. How is sorting achieved in the COBOL program?

It is done by using the SORT command whose syntax goes as follows:

SORT file_1 ON ASCENDING/DESCENDING KEY key…
USING file_2
GIVING file_3.

where

• file_1 - sort workfile that needs to be described by using SD entry in FILE SECTION.
• file_2 - input file for SORT that needs to be described using FD entry in FILE SECTION and using a SELECT clause in FILE CONTROL.
• file_3 - output file from SORT and again needs to be described using FD entry in FILE SECTION and SELECT clause in FILE CONTROL section.

All three files are not supposed to be opened explicitly.

Note:

• USING clause can be replaced by INPUT PROCEDURE IS para_1 THRU para_2. While using INPUT PROCEDURE, we need to remember that the section will be executed before sort and the records need to be released to the work file from the result of the input procedure.
• GIVING clause can be replaced by OUTPUT PROCEDURE IS para_1 THRU para_2. While using OUTPUT PROCEDURE, we need to note that the procedure will be executed once all records were sorted and the records from the sort work file should be populated one record at a time to the output procedure.

### 20. Why should the file be opened in I-O mode when it is being used for REWRITE purposes?

When the file REWRITE of the record needs to be performed, the file should first be opened and then the record must be read from the file. This is why the file should always be opened in I-O mode.

### 21. How do we remove the spaces at end of every record in an output file that is of variable length?

Spaces that are present at the end of the record are called trailing spaces. COBOL does not provide the functionality to remove such trailing spaces. But it can be achieved by using the RECORD-LENGTH field as follows:
Consider a scenario where we have a file of variable length and the maximum possible record length is 4000. To remove trailing space from every record, then we can alter the record length value to RECORD-LENGTH. This ensures that the records are trimmed which are beyond actual record length. Assuming that a variable-length file has a maximum record length of 4000.

• Move the original record length value to RECORD-LENGTH. This process enables the trimming of the entire record that is beyond the length.
• In case the data is populated only up to 3000 bytes - meaning there are 1000 trailing spaces. Then move the record length value to RECORD-LENGTH.
• By doing this, the records would be trimmed off and 1000 bytes would be freed.

### 22. How can we process two files by comparing key fields?

There are 2 possible approaches for this:

• Approach 1:
• We can read records from both files, if the key fields match, then they can be ignored.
• If upon key comparison, the results are unequal, then we identify which file has missing or new records and update the file with missing records accordingly.
• Approach 2:
• If both files have the same records, then the work will be reduced.
• If file 1 comes to the AT END state, then we have to move HIGH VALUES into the key field. The same goes to file 2.
• This process needs to be repeated until both key fields are equal to HIGH VALUES.
• For this process to work, the key fields should be in PIC(X) format and not numeric.

To make the process easier, we can avoid a lot of I-O operations by reading data to the local array table and then processing the records from there.

### 23. How can we reference or make COBOL program realise that about the following file formats?

1. Fixed Block File
2. Fixed Unblock File
3. Variable Block File
4. Variable Unblock File
5. Printer File

Following are the explanation to the points one by one:

1. Fixed Block File: We can identify that a file is a fixed block file if the following 3 conditions are met:
• ORGANIZATION IS SEQUENTIAL
• RECORDING MODE IS F
• BLOCK CONTAINS 0
2. Fixed Unblock File: We can identify that a file is a fixed unblock file if the following 2 conditions are met:
• ORGANIZATION IS SEQUENTIAL
• RECORDING MODE IS F
3. Variable Block File: We can identify that a file is a variable block file if the following 4 conditions are met:
• ORGANIZATION IS SEQUENTIAL
• RECORDING MODE IS V
• BLOCK CONTAINS 0
• Record length is never coded as 4 bytes in FD as JCL will consider the record length as the max length of record plus 4.
4. Variable Unblock File: We can identify that a file is a variable unblock file if the following 3 conditions are met:
• ORGANIZATION IS SEQUENTIAL
• RECORDING MODE IS V
• Record length is never coded as 4 bytes in FD as JCL will consider the record length as the max length of record plus 4.
5. Printer File: We can reference that a file is a printer file if the following 3 conditions are met:
• ORGANIZATION IS SEQUENTIAL
• RECORDING MODE IS F
• BLOCK CONTAIN 0

### 25. What are the causes of S0C7, S0C5 and S0C1?

S0C7 is caused mainly due to the following reasons:

• Whenever numeric operations are performed on data of non-numeric type.
• When we are working on the uninitialized storage.
• When we try to code excessively that surpasses the maximum permitted dub script.

S0C5 is caused mainly due to the following reasons:

• Damaged index or subscript.
• Exit occurred incorrectly from a perform.
• Before the read operation, I/O is accessed.
• When we try to close an unopened dataset.

S0C1 is caused mainly due to the following reasons:

• Incorrectly spelt DD name.
• When we perform a read or write operation on an unopened dataset.
• When the subprograms that are called are not found.

### 26. Under what circumstances are scope terminators mandatorily needed?

When we are using in-line PERFORMS or EVALUATE statements, we need to use scope terminators. It is recommended because it helps to read the code better and is deemed as a good coding practice.

### 27. What are the problems associated with using ordered sequential files?

The main nature of ordered sequential files is that the records are arranged based on some key field(s). When a user wants to perform operations like insert or deletion, then the order based on the field(s) should be maintained at all times. This is attained only by creating a new file where we insert or update or delete the records within the new file and then maintain the ordered nature. All these take place on the disk directly and the time required to access data on disk is the main bottleneck while processing any functionality. This reduces the speed of computation and slows down the system unnecessarily if we try to use ordered sequential files whenever not needed.

### 28. How is INCLUDE different from COPY?

The main similarity between INCLUDE and COPY is that both help in expanding the program variables or codes. The important difference between them is that INCLUDE is used for expanding the code at the time of pre-compilation. Whereas the COPY expands the code at compilation time. DB2 pre-compilers won’t be able to process COPY statements which is why the statements involving the validation of table attributes and DCL statements are embedded using INCLUDE.

### 29. What do you understand by the following terminologies?

1. AMODE(31)
2. AMODE(24)
3. RMODE(24)
4. RMODE(ANY)

All 4 are the options that are available in compile or link editing. AMODE expands to Addressing Mode. AMODE(31) and AMODE(24) represents that the addressing mode used is 31-bit and 24-bit respectively. When we use AMODE(ANY), it indicates that either 31-bit mode or 24-bit addressing mode can be used and it is dependent on the value of RMODE.

RMODE represents Resident Mode within the virtual storage. RMODE(24) represents that the mode can reside within virtual storage below the 16 Meg line. RMODE(ANY) represents that the mode can reside below or above 16 Meg line and the address bit can be either 24-bit or 31-bit depending on the RMODE.

### 30. Why is S9(4) COMP needed despite knowing that Comp-3 would utilise less space?

S9(4) COMP represents that the item is a small integer which means two words of 1 byte each can occupy a total of 2 bytes. In S9(4) COMP-3, one word is equal to half a byte which means 4 words can occupy 2 bytes and additionally, the sign occupies another half byte which results in a maximum of 3 bytes usage. More can be accommodated in S9(4) COMP when compares to COMP-3.

### 31. Consider a scenario where we have a program having an array of 20 items. When the program tries to access the 21st item, the program fails to abend. What is the reason for this?

The default compiler option NOSSRANGE must have been used which does not allow the program to abend. If we want the program to abend whenever accessing an array element that is out of bounds, we need to use the compiler option of SSRANGE. Using this option, the program abends with SOC4 error which indicates that it tried to access an invalid address by using the wrong index.

## Cobol Sample Programs

### 32. Write a COBOL program that allows users to enter the names of students of a class and then displays it. Try to use OCCURS clause for achieving this.

• OCCURS clause is used for specifying the table where the contents can be accessed using indexing. It is advantageous when we do not require different data entries for data of a similar kind.
• COBOL Program:
IDENTIFICATION DIVISION
PROGRAM-ID
ENVIRONMENT DIVISION
DATA DIVISION
WORKING-STORAGE SECTION
01 N PIC 9(2) VALUE 0
01 I PIC 9(2) VALUE 0
01 NAME-IN
02 NAME PIC X(10) OCCURS 10 times
01 KEY-IN PIC X VALUE SPACE
PROCEDURE DIVISION
P-1
DISPLAY(1 1) ERASE
DISPLAY(3 5) "HOW MANY STUDENTS?"
ACCEPT N
DISPLAY(1 1) ERASE
PERFORM GET-DATA-PROC N TIMES
DISPLAY(1 1) ERASE
MOVE 0 to I
PERFORM DISPLAY-DATA-PROC N TIMES
STOP RUN
GET-DATA-PROC
ACCEPT NAME(I)
ADD 1 TO I
DISPLAY-DATA-PROC
DISPLAY NAME(I)
ACCEPT KEY-IN
ADD 1 TO I

### 33. Write a COBOL program that takes 2 numbers as inputs and performs addition and multiplication on them and displays the result.

IDENTIFICATION DIVISION.
PROGRAM-ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  NUMBER1           PIC 9  VALUE ZEROS.
01  NUMBER2           PIC 9  VALUE ZEROS.
01  RESULTANT         PIC 99 VALUE ZEROS.
01  OPERATOR          PIC X  VALUE SPACE.

PROCEDURE DIVISION.
DISPLAY "FIRST INPUT: " WITH NO ADVANCING
ACCEPT NUMBER1
DISPLAY "SECOND INPUT: " WITH NO ADVANCING
ACCEPT NUMBER2
DISPLAY "ENTER + FOR ADD AND * FROM MULTIPLY: " WITH NO ADVANCING
ACCEPT OPERATOR

IF OPERATOR = "+" THEN
ADD NUMBER1, NUMBER2 GIVING RESULTANT
END-IF

IF OPERATOR = "*" THEN
MULTIPLY NUMBER1 BY NUMBER2 GIVING RESULTANT
END-IF

DISPLAY "RESULT OF OPERATION = ", RESULTANT
STOP RUN.

### 34. Write a COBOL program example for demonstrating the DELETE concept from a file based on a matching record.

IDENTIFICATION DIVISION.
PROGRAM-ID.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT RECORD-FILE ASSIGN TO DISK1.
ORGANIZATION IS INDEXED.
ACCESS MODE IS RANDOM.
RECORD KEY  IS STD-ID.
FILE STATUS IS WS-FS.
DATA DIVISION.
FILE SECTION.
FD  RECORD-FILE.
01 STD-RECORD.
02 STD-ID          PIC 9(03).
02 STD-NAME        PIC X(20).

WORKING-STORAGE SECTION.
77 WS-FS               PIC 9(02).
01 WS-EOF-SW           PIC X(01) VALUE 'N'.
88 EOF-SW              VALUE 'Y'.

PROCEDURE DIVISION.
DISPLAY 'ENTER THE STUDENT ID TO BE MATCHED'
ACCEPT STD-ID.
DISPLAY 'OPENING FILE TO DELETE MATCHING RECORD..'.
OPEN INPUT RECORD-FILE.
PERFORM UNTIL EOF-SW
KEY IS STD-ID
AT END MOVE 'Y'  TO WS-EOF-SW
IF WS-FS = 00
DELETE STD-RECORD
MOVE 'Y'  TO WS-EOF-SW
ELSE
DISPLAY 'RECORD NOT AVAILABLE'
END-IF
END-PERFORM.
CLOSE RECORD-FILE.
DISPLAY STD-RECORD .
STOP RUN.  

### Conclusion

COBOL has been around for many decades and has found its use in various business purposes due to its strong computational capabilities. In this article, we have seen the most commonly asked COBOL interview questions for both freshers and experienced professionals.

## COBOL MCQ

1.

Where is the sign stored in the COMP-3 field?

It is stored in the last nibble.

2.

Which among the below errors does not get trapped in the ON SIZE ERROR option?

3.

What happens to a stand-alone program if we use GO BACK instead of using STOP RUN?

4.

Which among the following options results in the file status 39?

5.

When do we get file status 92?

6.

Can we use JUSTIFIED for all data types in COBOL?

7.

Which among the following options is true for OCCURS clause?

8.

Why do we use level 88?

9.

Which among the below represents COMP-1 and COMP-2?

10.

Which formula will you use to calculate how many bytes does S9(n) COMP-3 fields occupy, where n is any number?