COBOL Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. Explain the Division structure in COBOL.
The Division structure in COBOL consists of Identification, Environment, Data, and Procedure divisions. These divisions help organize the program's structure.
Ques 2. Differentiate between COMP and COMP-3 in COBOL.
COMP and COMP-3 are data types in COBOL. COMP is used for binary representation, while COMP-3 is used for packed decimal representation.
Ques 3. Explain the difference between CALL and PERFORM in COBOL.
CALL is used to transfer control to another program or a specific paragraph within the same program. PERFORM is used for looping and invoking paragraphs or sections.
Ques 4. How is indexing done in COBOL?
Indexing in COBOL is typically done using INDEXED BY clause. It associates an index name with a data item, allowing for efficient access to table elements.
Example:
01 EMPLOYEE-TABLE OCCURS 10 TIMES INDEXED BY EMPLOYEE-INDEX.
...
Ques 5. Explain the difference between static and dynamic calls in COBOL.
Static calls are resolved at compile-time, while dynamic calls are resolved at run-time. CALL and PERFORM are examples of static calls, while CALL 'subprogram' USING ... is a dynamic call.
Ques 6. Explain the concept of 88 level in COBOL.
The 88 level in COBOL is used for condition names. It allows the programmer to associate a condition with a data item, simplifying the writing of conditionals.
Example:
01 STATUS-CODE PIC 99.
88 SUCCESS VALUE 00.
88 FAILURE VALUE 01.
Ques 7. What is the significance of the OCCURS clause?
The OCCURS clause in COBOL is used to define arrays or tables. It specifies the number of occurrences or elements, allowing for efficient handling of repetitive data.
Example:
01 SALES-AMOUNT OCCURS 12 TIMES PIC 9(5).
Ques 8. Explain the INSPECT verb in COBOL.
The INSPECT verb in COBOL is used for string manipulation. It allows the programmer to search, replace, or delete characters in a string.
Example:
INSPECT NAME-STRING REPLACING ALL '- ' BY SPACE.
Ques 9. Explain the EVALUATE statement in COBOL.
The EVALUATE statement in COBOL is used for multi-way branching. It simplifies complex nested IF statements and enhances code readability.
Example:
EVALUATE TRUE
WHEN AGE < 18 DISPLAY 'Minor'
WHEN AGE > 65 DISPLAY 'Senior'
WHEN OTHER DISPLAY 'Adult'.
Ques 10. Explain the concept of the INDEXED BY clause.
The INDEXED BY clause in COBOL is used to associate an index name with a table or array. It provides a way to reference individual elements efficiently.
Example:
01 EMPLOYEE-TABLE OCCURS 10 TIMES INDEXED BY EMPLOYEE-INDEX.
...
Ques 11. Explain the concept of the PERFORM VARYING statement.
The PERFORM VARYING statement in COBOL is used for iterative processing. It allows a specified set of statements to be repeated while incrementing or decrementing a loop variable.
Example:
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
DISPLAY 'Iteration ' I.
END-PERFORM.
Ques 12. How do you handle date and time in COBOL?
COBOL provides the special registers CURRENT-DATE and CURRENT-TIME to handle date and time operations. These registers store system date and time values.
Example:
MOVE FUNCTION CURRENT-DATE TO DATE-FIELD.
Ques 13. How does COBOL support data validation?
COBOL supports data validation through the use of conditions, the IF statement, and the EVALUATE statement. These constructs help ensure data integrity.
Example:
IF AMOUNT < 0
DISPLAY 'Invalid amount'
END-IF.
Ques 14. Explain the purpose of the EXIT statement.
The EXIT statement in COBOL is used to terminate a loop prematurely. It allows the program to exit a PERFORM loop or a Section before reaching the normal end.
Example:
PERFORM UNTIL EOF-FLAG = 'Y'
...
IF SOME-CONDITION
EXIT.
END-IF.
END-PERFORM.
Ques 15. Explain the purpose of the USAGE clause in COBOL.
The USAGE clause in COBOL is used to specify the internal representation of data items. It defines how data is stored in memory, such as binary, packed-decimal, or display.
Example:
01 AMOUNT PIC 9(5) USAGE COMP-3.
Ques 16. What is the significance of the MOVE CORRESPONDING statement?
The MOVE CORRESPONDING statement in COBOL is used to move corresponding data items from one record to another. It simplifies the process of copying similar fields between records.
Example:
MOVE CORRESPONDING RECORD-1 TO RECORD-2.
Ques 17. What is the purpose of the SEARCH statement in COBOL?
The SEARCH statement in COBOL is used to search a table for a specified value. It is commonly used with the WHEN clause to perform conditional actions based on the search result.
Example:
SEARCH ITEM-TABLE AT END DISPLAY 'Item not found'.
Ques 18. Explain the concept of the STRING statement in COBOL.
The STRING statement in COBOL is used for string concatenation. It allows the programmer to concatenate and manipulate character strings efficiently.
Example:
STRING 'Hello' ' ' 'World' DELIMITED BY SIZE INTO OUTPUT-STRING.
Ques 19. Explain the concept of the UNSTRING statement in COBOL.
The UNSTRING statement in COBOL is used to break down a delimited string into its individual components. It is useful for parsing and extracting data from strings.
Example:
UNSTRING NAME-STRING DELIMITED BY ',' INTO FIRST-NAME LAST-NAME.
Ques 20. Explain the concept of the INDEX in COBOL.
The INDEX in COBOL is a special register that is used to store the position within a table. It is often manipulated using the SET and PERFORM statements.
Example:
SET TABLE-INDEX TO 1.
Ques 21. What is the purpose of the EXIT PARAGRAPH statement?
The EXIT PARAGRAPH statement in COBOL is used to exit a specific paragraph prematurely. It is useful for controlling the flow within a section of code.
Example:
PERFORM PROCESS-DATA.
IF ERROR-FLAG = 'Y' THEN
EXIT PARAGRAPH.
END-IF.
Ques 22. What is the purpose of the USE statement in COBOL?
The USE statement in COBOL is used to declare and specify the usage of indexes in a SEARCH statement. It associates an index with a table to optimize search operations.
Example:
USE EMPLOYEE-INDEX.
Ques 23. Explain the concept of the EXIT SECTION statement.
The EXIT SECTION statement in COBOL is used to terminate the current section prematurely. It allows the program to skip the remaining code within a particular section.
Example:
PERFORM PROCESS-DATA SECTION.
IF ERROR-FLAG = 'Y' THEN
EXIT SECTION.
END-IF.
Most helpful rated by users:
Related interview subjects
Embedded C interview questions and answers - Total 30 questions |
C++ interview questions and answers - Total 142 questions |
VBA interview questions and answers - Total 30 questions |
COBOL interview questions and answers - Total 50 questions |
R Language interview questions and answers - Total 30 questions |
Python Coding interview questions and answers - Total 20 questions |
Scala interview questions and answers - Total 48 questions |
Swift interview questions and answers - Total 49 questions |
Golang interview questions and answers - Total 30 questions |