TOP Cobol Interview Questions and Answers
What guidelines should be followed to write a structured COBOL program?
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.
How do we get current date from system with century?
Current date with the century is achieved by using Intrinsic function called FUNCTION CURRENT-DATE.
What are all the divisions of a COBOL program?
There are four divisions in a cobol program:
- IDENTIFICATION DIVISION
- ENVIRONMENT DIVISION
- DATA DIVISION
- PROCEDURE DIVISION
What is a SSRANGE and NOSSRANGE?
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.
What is COMP-1? COMP-2?
COMP-1 is a Single precision floating point and uses four bytes. COMP2 is the double precision floating number and uses eight bytes.
What is the difference between PIC 9.99 and PIC9v99?
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
What is the Purpose of Pointer in the string?
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?
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?
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.
Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?
TEST BEFORE is the default statement and the condition is checked before executing the instructions under Perform.
Can a Search can be done on a table with or without Index?
No, the table must be indexed to search on a table.
What are the different rules of SORT operation?
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
What are the different rules to perform a Search?
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
A table has two indexes defined. Which one will be used by the SEARCH?
The index named first can be used by search.
When is a scope terminator mandatory?
Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. Make scope terminator as explicit for good coding standards.