Top COBOL Interview Questions and Answers
1. What is COBOL?
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.
2. What are the different data types in COBOL?
There are three data types in Cobol:
Alpha-numeric (X)
Alphabetic (A) and
Numeric (9)
3. What is the difference between subscript and index?
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.
4. What is the difference between performing a SECTION and a PARAGRAPH?
SECTION will have all the paragraphs that are part of the section, to be performed.
PARAGRAPH will have only that paragraph to be performed.
5. What is the difference between CONTINUE & NEXT SENTENCE?
CONTINUE is like a null statement and it continues execution, while NEXT SENTENCE transfers control to the next sentence.
6. What are the different OPEN modes available in Cobol?
Open modes can be used for
Input
Output
Input – Output
Extend
7. What is Static and Dynamic linking?
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.
8. What is the use of EVALUATE statement?
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.
9. What is the difference between PERFORM … WITH TEST AFTER and PERFORM … WITH TEST BEFORE?
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.
10. What is the point of the REPLACING option of a copy statement?
REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.
COPY REPLACING BY
11. What kind of error is trapped by ON SIZE ERROR option?
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.
12. What is the difference between Structured COBOL Programming and Object Oriented COBOL programming?
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.
13. What is the LOCAL-STORAGE SECTION?
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
14. What are INPUT PROCEDURE and OUTPUT PROCEDURE?
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]
15. What is the use of LINKAGE SECTION?
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.
16. What are the access modes of START statement?
Access modes are SEQUENTIAL or DYNAMIC for the start statement.
17. What is an in-line PERFORM?
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.
18. Which division and paragraphs are mandatory for a COBOL program?
Identification division and Program ID are mandatory for a COBOL program.
19. What is the difference between Global and External Variables?
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.
20. What is Pic 9v99 Indicates?
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.
21. 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.
22. 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.
23. 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
24. 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.
25. 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.
26. 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.
27. 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.
28. 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.
29. 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.
30. Can a Search can be done on a table with or without Index?
No, the table must be indexed to search on a table.