Dear readers, these Cobol Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your Job interview for the subject of Cobol. As per my experience good interviewers hardly plan to ask any particular question during your Job interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answers:
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.
There are three data types in Cobol:
Alphabetic (A) and
Subscript refers to the occurrence of an array but index is the displacement from the beginning of the array.
An index can only be modified using PERFORM, SEARCH & SET.
SECTION will have all the paragraphs that are part of the section, to be performed.
PARAGRAPH will have only that paragraph to be performed.
CONTINUE is like a null statement and it continues execution, while NEXT SENTENCE transfers control to the next sentence.
Open modes can be used for
Input – Output
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.
Evaluate is just like a case statement or it can be used like a Nested IFs. The difference between EVALUATE and case is that ‘break’ is not used in Evaluate statement and the control comes out of the EVALUATE once a match is found.
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 the each repeated execution of the PERFORM range. The range is executed at least once in TEST AFTER.
REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.
COPY <Name> REPLACING BY
ON SIZE ERROR option is raised when there is
Zero raised to the zero power
Division by 0
Zero raised to a negative number
A negative number raised to a fractional power.
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.
Local-Storage is allocated each time the 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 WORKING-STORAGE SECTION
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]
The linkage section is used to pass data from one program to another program or to pass data from a procedure to a program. It is part of a called program that maps to data items in the calling program’s working storage.
Access modes are SEQUENTIAL or DYNAMIC for the start statement.
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.
Identification division and Program ID are mandatory for a COBOL program.
Global variables are accessible only to the batch program whereas external variables can be referenced from any batch program residing in the same system library.
Pic 9v99 is a three position Numeric field with an implied or assumed decimal point after the first position.
Here, v means an implied decimal point.
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.
Current date with the century is achieved by using Intrinsic function called FUNCTION CURRENT-DATE.
There are four divisions in a cobol program:
These are options for a compiler to find the subscript out of range. NOSSRANGE is the default option where there will not be any run time error if index or subscript went out of a range.
COMP-1 is a Single precision floating point and uses four bytes. COMP2 is the double precision floating number and uses eight bytes.
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.
The Purpose of Pointer is to specify the leftmost position within receiving field where the first transferred character will be stored.
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.
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.
No, the table must be indexed to search on a table.
The SEARCH can be applied to a table
Which has OCCURS clause
INDEXED BY phrase
Search Index must have some initial value
Set the index value to 1
TEST BEFORE is the default statement and the condition is checked before executing the instructions under Perform.
SORT can be performed when
Input and Output files must remain closed
Working file must have a select clause
Input and Output files have FD entries
Work file should have short description in File Section
The index named first can be used by search.
Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. Make scope terminator as explicit for good coding standards.
Before the REWRITE is performed, the record must be open and read from the file. Therefore, the file must be opened in I-O mode for rewrite functionality.
The ONLY way is to look at the output of the linkage editor or the load module.
If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be exist in the load module.
The serial SEARCH verb is equivalent to Perform.. Varying statement and it is nothing but search without ALL.
There are six sections in Data Division:
Working Storage Section
Local Storage Section
Comp is for binary usage, while comp-3 indicates packed decimal.
If EXIT is used, it won’t be more than only sentence within a paragraph.
End IF and End Evaluate are the examples of command terminators.
A call is an actual COBOL command which provokes an external program and returns. Link is same as Call but it does not belong to a COBOL verb.
An O-I mode (Output/Input mode) is used for starting and initiation of processing files. Processing of files is determined by successful execution of an OPEN statement.
S(8) can store 4 bytes and the highest value is 99999999.
Arrays can be defined as -
05 Array1 PIC X(9) which occurs 10 times
05 Array2 PIC X(9) which occurs 20 times
A literal is a data item which consists value by itself. It cannot be referred by a name. They are constant data items. There are two types of literals:
String / Alphanumeric Literals
A report item is a field to be printed which has Edit Symbols.
Yes, we can redefine the values from bigger number to smaller number.
Length is like a special register to have the length of a group or an elementary item.