COBOL Technical Interview Questions Answers



COBOL scenario-based interview questions and answers
COBOL scenario-based interview questions for experienced
COBOL scenario-based interview questions for 8 years of experience
COBOL tricky interview questions
COBOL interview questions and answers for 10 years of experience
COBOL interview questions for 6 years of experience
COBOL coding questions
COBOL abends interview questions

COBOL Technical Interview Questions Answers

What do you know about COBOL?

Answer :

COBOL is abbreviated as Common Business Oriented Language and it is one of the oldest programming languages. It primarily used for business, finance and administrative systems for companies. COBOL stands for Common Business Oriented Language. The US Department of Defense, in a conference, formed CODASYL (Conference on Data Systems Language) to develop a language for meeting business data processing needs which is now known as COBOL.

List some features of COBOL.

Answer :

COBOL is a standard language that can be compiled and executed on various machines. It is ideally suited for business-oriented applications as it can handle huge volumes of data. It provides numerous debugging and testing tools. COBOL is a structured language; it has different divisions, so it is easy to debug.


What is Static and Dynamic linking?

Answer :

In static linking, called subroutine links into the calling program, while in dynamic linking, the subroutine & the main program will exist as separate modules. Dynamic and Static linking can be achieved by choosing either the DYNAM or NODYNAM link edit option.


What kind of error is trapped by ON SIZE ERROR option?

Answer :

ON SIZE ERROR option is raised when there is fixed-point overflow Zero raised to the zero power Division by 0 Zero raised to a negative number A negative number raised to a fractional power.


What is the difference between Structured COBOL Programming and Object Oriented COBOL programming?

Answer :

Structured programming is logical way of programming where the functionalities are divided into modules and helps write the code logically. Object Oriented Cobol language is a Natural way of programming in which you identify the objects, and then write functions and procedures around that object.


What are INPUT PROCEDURE and OUTPUT PROCEDURE?

Answer :

In the INPUT PROCEDURE, the input file is opened, records are read and edited and then are released to the sorting operation. Finally the file will be closed. [plain]RELEASE recordname FROM inputrecord[/plain] In the OUTPUT PROCEDURE, output file is opened, the sorted record is returned to the Output record and then the record will be written. Finally the file will be closed. [plain]RETURN file RECORD into outputrecord[/plain]


What is an in-line PERFORM?

Answer :

An IN-LINE PERFORM Statement allows the routine being performed to be nested within the perform statement itself instead of being a seperate paragraph The PERFORM and END-PERFORM statements are used to block the cobol statements between them. In line PERFORM work as long as there are no internal GO TOs, not even to an exit.


What guidelines should be followed to write a structured COBOL program?

Answer :

Following guidelines to be following while writing Cobol program: Use ‘EVALUATE’ statement for constructing cases. Use scope terminators for nesting. Use in-line Perform statement for writing ‘do’ constructions. Use Test Before and Test After in the Perform statement while writing Do-While statements.


What are all the divisions of a COBOL program?

Answer :

There are four divisions in a cobol program: IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION


What is the Purpose of Pointer in the string?

Answer :

The Purpose of Pointer is to specify the leftmost position within receiving field where the first transferred character will be stored.


What is binary search?

Answer :

First, we have to compare the item to be searched with the item at the center. If it matches, it is good to go with the value else repeat the process with the left half or the right half depending on where the item lies.


What is the difference between a binary search and a sequential search?

Answer :

In a binary search, the table element key values will be in ascending or descending sequence. The table is ‘halved'(Divided into two) to search for equal to, greater than or less than conditions until the element is found. In a sequential search, the table is searched from top to bottom, so the elements do not have to be in a specific sequence. The binary search is much faster for more tables, while sequential Search works well with lesser ones. SEARCH ALL is used for binary search; SEARCH for sequential search.


Name the divisions in a COBOL program.

Answer :

Identification Division, Environment Division, Data Division, and Procedure Division.


What are the different data types available in COBOL?

Answer :

Alpha-numeric (X), Alphabetic (A), and Numeric (9).


What is 'IS NUMERIC' clause?

Answer :

IS NUMERIC clause is used to check if any item is numeric or not. It returns TRUE when the item against which it is used contains only numbers(0 to 9). The item can be positive or negative.


What are 66 and 88 level used for?

Answer :

Level 66 is used for RENAMES clause and Level 88 is used for condition names.


What is the difference between subscript and index?

Answer :

Subscript is the occurrence in an array. Index is the displacement from the beginning of an array.


What is the difference between SEARCH and SEARCH ALL?

Answer :

SEARCH is a serial search, whereas SEARCH ALL is a binary search. A table must be in sorted order before using SEARCH ALL.


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

Answer :

Performing a SECTION will cause all the paragraphs that are a part of the section to be performed. Performing a PARAGRAPH will cause only a paragraph to be performed.

What is a scope terminator?

Answer :

Scope terminator is used to mark the end of a verb. Example: IF and END-IF.


What are the file opening modes in COBOL?

Answer :

File opening modes in COBOL include: INPUT, OUTPUT, I-O, and EXTEND.


What is the maximum size of a numeric field we can define in COBOL?

Answer :

The maximum size of a numeric field is PIC 9(18).


What is the difference between CONTINUE and NEXT SENTENCE?

Answer :

CONTINUE transfers the control to the next statement after the scope terminator. NEXT SENTENCE transfers the control to the statement after the first period encountered.


Why we can not define occurs clause at 01 level?

Answer :

01 is of the record level. We repeat the fields within a record, not the record itself. So an Occurs clause can not be used at 01 level.


What is the mode in which you will OPEN a file for writing?

Answer :

To write into a file, the file has to be opened in either OUTPUT or EXTEND mode.


What is the difference between Call By Content and Call By Reference?

Answer :

The parameters passed in a Call By Content are protected from modification by the called program. In Call By Reference, parameters can be modified by the called program.


What is a linkage section?

Answer :

The linkage section is a part of a called program that 'links' or maps to data items in the calling program's working storage.


What will happen if you code GO BACK instead of STOP RUN in a stand alone COBOL program?

Answer :

The program will go in an infinite loop.

How is sign stored in a COMP-3 field?

Answer :

It is stored in the last nibble.


What is the difference between comp and comp-3?

Answer :

Comp is a binary usage, while comp-3 indicates packed decimal.


What is the purpose of Identification Division?

Answer :

Identification Division is used for documentation purpose.


What is the difference between static call and dynamic call?

Answer :

In static call, the called program is a stand alone program, it is an executable program. During run time we can call it in our called program. As about dynamic call, the called program is not an executable program; it can be executed through the called program only.


What is Redefines clause?

Answer :

Redefines clause is used to allow the same storage allocation to be referenced by different data names.


What is the Purpose of Pointer Phrase in STRING command?

Answer :

The Purpose of Pointer phrase is to specify the leftmost position within the receiving field where the first transferred character will be stored.


What is 77 level used for?

Answer :

It is an elementary level item which cannot be subdivided.


What is binary search?

Answer :

Compare the item to be searched with the item at the centre. If it matches fine else repeat the process with the left half or the right half depending on where the item lies.


What is the use of EVALUATE statement?

Answer :

Evaluate is like a case statement and can be used to replace nested Ifs. No break is required as the control comes out as a soon as match is found.


Can I redefine an X(10) field with a field of X(20)?

Answer :

Yes, as Redefines causes both fields to start at the same location.


What is COMP-1 and COMP-2?

Answer :

COMP-1 is single precision floating point that uses 4 bytes. COMP-2 is double precision floating point that uses 8 bytes.


What is the function of Accept Verb?

Answer :

Accept Verb is used to get data such as date, time, and day from operating system or directly from the user. If a program is accepting data from the user, then it needs to be passed through the JCL.


What is a Compute Statement?

Answer :

Compute statement is used to write arithmetic expressions in COBOL. This is a replacement for Add, Subtract, Multiply, and Divide.


How do you define the files referred to in a subroutine program?

Answer :

Supply the DD cards in JCL just as you would for files referred to in the main program.


What divisions, sections and paragraphs are mandatory in a COBOL program?

Answer :

Identification Division and Program-Id paragraph are mandatory in a COBOL program.


Where does AREA B in COBOL start from?

Answer :

Area B starts from 12 to 72 column.


Where does the FILE-CONTROL paragraph appear?

Answer :

It appears in the Input-Ouput Section in the Environment Division.


What is the difference between Perform With Test After and Perform With Test Before?

Answer :

If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. If TEST AFTER is specified, the condition is tested at the end of each repeated execution of the PERFORM range. The range is executed at least once in TEST AFTER.


What is LOCAL-STORAGE SECTION?

Answer :

Local-Storage is allocated each time a program is called and will be de-allocated when the program stops via an EXIT PROGRAM, GOBACK, or STOP RUN. It is defined in the DATA DIVISION after the WORKING-STORAGE SECTION.


What are the access modes of START statement?

Answer :

Access modes are SEQUENTIAL or DYNAMIC for the start statement.


What is the difference between PIC 9.99 and PIC9v99?

Answer :

PIC 9.99 is a four position field that actually contains a decimal point where as PIC 9v99 is three position numeric field with assumed decimal position.


Can a Search be done on a table with or without Index?

Answer :

No, the table must be indexed to search on a table.


Why is it necessary to open a file in I-O mode for REWRITE?

Answer :

Before REWRITE is performed, the record must be opened and read from the file. Therefore, the file must be opened in I-O mode for rewrite functionality.


What are literals?

Answer :

A literal is a data item that consists value by itself. It cannot be referred by a name. They are constant data items.


What will happen if you code GO BACK instead of STOP RUN in a stand alone COBOL program?

Answer :

A Stop run ends the unit of work and returns control to the operating system whereas GOBACK returns control to calling program. So if we code GO BACK instead of Stop Run, it will go in infinite loop.


What is the mode in which you will OPEN a file for writing?

Answer :

To write into a file, the file has to be opened in either OUTPUT or EXTEND mode.


Where does the FILE-CONTROL paragraph appear?

Answer :

FILE-CONTROL paragraph appears in the Input-Ouput Section in the Environment Division which provides information of external data sets used in the program.


What is the length of PIC 9.999?

Answer :

Length of PIC 9.999 is 5 as '.' takes 1 byte. So total 1 byte for '.' and 4 bytes for 9.


Which cobol verb is used for updating a file?

Answer :

Rewrite verb is used to update the records. File should be opened in I-O mode for rewrite operations. It can be used only after a successful Read operation. Rewrite verb overwrites the last record read.


If 123 value is moved to a PP999 PIC clause, then what is edited value taken?

Answer :

.00123 edited value will be taken. P is assumed decimal scaling position which is used to specify the location of an assumed decimal point when the point is not within the number that appears in the data item. .PIC PP999 means that numeric data item is of 3 characters and there are 5 positions after the decimal point.


Where can we specify OCCURS clause?

Answer :

In array declaration, we can specify occurs clause on Elementary item as well as on Group item also.


How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy?

Answer :

9(7) will take 7 bytes and 1 byte for SIGN TRAILING SEPARATE, so total 8 bytes it will take.


How many times following loop will execute?

MOVE 5 TO X. PERFORM X TIMES. MOVE 10 TO X. END-PERFORM.

Answer :

PERFORM loop will execute for 5 times. As it reads the first statement PERFORM 5 times. It replaces X with the value 5.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUM1 PIC X(4) VALUE '15AB'. PROCEDURE DIVISION. MOVE 'XXXX' TO WS-NUM1 DISPLAY WS-NUM1. STOP RUN.

Answer :

Value of WS-NUM1 will be displayed. While declaring the WS-NUM1 variable we have set the value as '15AB' but in the procedure division we have moved 'XXXX' value in WS-NUM1. So XXXX value is displayed.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-ID PIC 9(5). PROCEDURE DIVISION. A000-FIRST-PARA. INITIALIZE WS-ID REPLACING NUMERIC DATA BY 12345. DISPLAY WS-ID. STOP RUN.

Answer :

WS-ID will be initialized and numeric data will be replaced by 12345 as mentioned in the statement.


What is the output of the following code?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUM1 PIC 9(9). 01 WS-NUM2 PIC 9(6). PROCEDURE DIVISION. A000-FIRST-PARA. MOVE 123456789 TO WS-NUM1. MOVE WS-NUM1(3:6) TO WS-NUM2. DISPLAY WS-NUM2 STOP RUN.

Answer :

WS-NUM1(3:6) indicates that select from 3rd column & up to 6 digits. So result will 345678.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUMA PIC 9(9) VALUE 10. 01 WS-NUMB PIC 9(9) VALUE 10. 01 WS-NUMC PIC 9(9) VALUE 10. 01 WS-NUMD PIC 9(9) VALUE 100. 01 WS-NUME PIC 9(9) VALUE 10. PROCEDURE DIVISION. SUBTRACT WS-NUMA WS-NUMB WS-NUMC FROM WS-NUMD GIVING WS-NUME. DISPLAY WS-NUME. STOP RUN.

Answer :

000000070 The formula will be like (WS-NUME = WS-NUMD - WS-NUMA - WS-NUMB - WS-NUMC).


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUMA PIC 9(9) VALUE 100. 01 WS-NUMB PIC 9(9) VALUE 15. 01 WS-NUMC PIC 9(2). 01 WS-REM PIC 9(2). PROCEDURE DIVISION. DIVIDE WS-NUMA BY WS-NUMB GIVING WS-NUMC REMAINDER WS-REM. DISPLAY WS-NUMC ', ' WS-REM STOP RUN.

Answer :

06, 10 Formula will be like WS-NUMC = NUMA/NUMB and remainder will be stored in WS-REM.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUM1 PIC 9(9) VALUE 10 . 01 WS-NUM2 PIC 9(9) VALUE 10. 01 WS-NUM3 PIC 9(9) VALUE 10. 01 WS-NUMA PIC 9(9) VALUE 50. 01 WS-NUMB PIC 9(9) VALUE 10. 01 WS-NUMC PIC 9(3). PROCEDURE DIVISION. COMPUTE WS-NUMC= (WS-NUM1 * WS-NUM2) - (WS-NUMA / WS-NUMB) + WS-NUM3. DISPLAY WS-NUMC STOP RUN.

Answer :

105


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-DESCRIPTION. 05 WS-DATE1 VALUE '20140831'. 10 WS-YEAR PIC X(4). 10 WS-MONTH PIC X(2). 10 WS-DATE PIC X(2). 05 WS-DATE2 REDEFINES WS-DATE1 PIC 9(8). PROCEDURE DIVISION. DISPLAY WS-DATE2. STOP RUN.

Answer :

20140831 When we redefine WS-DATE1 to WS-DATE2, automatically values from WS-DATE1 will be moved to WS-DATE2.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-DESCRIPTION. 05 WS-NUM. 10 WS-NUM1 PIC 9(2) VALUE 20. 10 WS-NUM2 PIC 9(2) VALUE 56. 05 WS-CHAR. 10 WS-CHAR1 PIC X(2) VALUE 'AA'. 10 WS-CHAR2 PIC X(2) VALUE 'BB'. 10 WS-RENAME RENAMES WS-NUM2 THRU WS-CHAR2. PROCEDURE DIVISION. DISPLAY "WS-RENAME : " WS-RENAME. STOP RUN.

Answer :

This program will give compilation error as Renames should be defined at 66 level number.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUM1 PIC 9(9). 01 WS-NUM2 PIC 9(9). PROCEDURE DIVISION. A000-FIRST-PARA. MOVE 25 TO WS-NUM1 MOVE 15 TO WS-NUM2 IF WS-NUM1 > WS-NUM2 THEN DISPLAY 'IN LOOP 1 - IF BLOCK' ELSE DISPLAY 'IN LOOP 1 - ELSE BLOCK' END-IF. STOP RUN.

Answer :

IN LOOP 1 - IF BLOCK WS-NUM1 is greater than WS-NUM2, so condition is satisfied and it will to IF loop.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUM PIC 9(3). 88 PASS VALUES ARE 041 THRU 100. 88 FAIL VALUES ARE 000 THRU 40. PROCEDURE DIVISION. A000-FIRST-PARA. MOVE 65 TO WS-NUM. IF PASS DISPLAY 'Passed with ' WS-NUM ' marks'. IF FAIL DISPLAY 'FAILED with ' WS-NUM 'marks'. STOP RUN.

Answer :

Passed with 065 marks WS-NUM contains 65 so PASS condition is satisfied as values lies in range of 041 to 100.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. A-PARA. PERFORM DISPLAY 'A' END-PERFORM. PERFORM C-PARA THRU E-PARA. B-PARA. DISPLAY 'B'. STOP RUN. C-PARA. DISPLAY 'C'. D-PARA. DISPLAY 'D'. E-PARA. DISPLAY 'E'.

Answer :

ACDEB


How many times following B-para loop will execute?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-A PIC 9 VALUE 0. PROCEDURE DIVISION. A-PARA. PERFORM B-PARA VARYING WS-A FROM 1 BY 1 UNTIL WS-A=5 STOP RUN. B-PARA. DISPLAY 'IN B-PARA ' WS-A.

Answer :

B-para will execute for 4 times as value of WS-A is 1 in starting and we are incrementing it by 1 in each iteration. Here condition is WS-A=5 and when this condition will be satisfied it will come out of the loop. So B-para will be executed 4 times.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-A PIC 9 VALUE 2. PROCEDURE DIVISION. A-PARA. DISPLAY 'A' GO TO B-PARA. B-PARA. DISPLAY 'B'. GO TO C-PARA D-PARA DEPENDING ON WS-A. C-PARA. DISPLAY 'C'. D-PARA. DISPLAY 'D'. STOP RUN.

Answer :

ABD This is to show how control goes from one GOTO statement to other. Go step by step you will understand the flow. From B-para control will go to D-para as value in WS-A is 2, so it will go to the 2nd para which is mentioned in the GOTO statement.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-CNT PIC 9(2) VALUE 0. 01 WS-STRING PIC X(15) VALUE 'AABCDACDAAEAAAF'. PROCEDURE DIVISION. INSPECT WS-STRING TALLYING WS-CNT FOR ALL 'A'. DISPLAY WS-CNT STOP RUN.

Answer :

08 Inspect statement will count the number of 'A' in the string and will put the value in WS-CNT.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-STRING PIC X(15) VALUE 'ABCDACDADEAAAFF'. PROCEDURE DIVISION. INSPECT WS-STRING REPLACING ALL 'A' BY 'X'. DISPLAY WS-STRING. STOP RUN.

Answer :

XBCDXCDXDEXXXFF Replacing command will replace all the 'A' by 'X'.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-TABLE. 05 WS-A PIC A VALUE 'A' OCCURS 5 TIMES. PROCEDURE DIVISION. DISPLAY WS-TABLE. STOP RUN.

Answer :

We are displaying the complete table so all the 5 occurrences will come 'AAAAA'.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-TABLE. 05 WS-A OCCURS 3 TIMES. 10 WS-B PIC A(2). 10 WS-C OCCURS 2 TIMES. 15 WS-D PIC X(3). PROCEDURE DIVISION. MOVE '12ABCDEF34GHIJKL56MNOPQR' TO WS-TABLE. DISPLAY 'WS-C(3,1) : ' WS-C(3,1). STOP RUN.

Answer :

MNO It is a 2-D array and we are using subscript to the access the elements in the table. WS-C(3,1) has MNO value in it.ws


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-STRING PIC A(30). 01 WS-STR1 PIC A(15) VALUE 'TESTING'. 01 WS-STR2 PIC A(7) VALUE 'Welcome'. 01 WS-STR3 PIC A(7) VALUE 'To AND'. 01 WS-COUNT PIC 99 VALUE 1. PROCEDURE DIVISION. STRING WS-STR2 DELIMITED BY SIZE WS-STR3 DELIMITED BY SPACE WS-STR1 DELIMITED BY SIZE INTO WS-STRING WITH POINTER WS-COUNT ON OVERFLOW DISPLAY 'OVERFLOW!' END-STRING. DISPLAY 'WS-STRING: 'WS-STRING. STOP RUN.

Answer :

WelcomeToTESTING String command is used to concatenate the strings.


What is the output of following program?

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-STRING PIC A(30) VALUE 'WELCOME TO TESTING'. 01 WS-STR1 PIC A(7). 01 WS-STR2 PIC A(2). 01 WS-STR3 PIC A(15). 01 WS-COUNT PIC 99 VALUE 1. PROCEDURE DIVISION. UNSTRING WS-STRING DELIMITED BY SPACE INTO WS-STR1, WS-STR2, WS-STR3 END-UNSTRING. DISPLAY WS-STR2. STOP RUN.

Answer :

To Unstring verb is used to split one string into multiple sub-strings.
Previous Post Next Post