fbpx

Top 100 COBOL Interview Questions and Answers

Top 100 COBOL Interview Questions and Answers

Contents show

1. What is COBOL?

Answer:
COBOL stands for Common Business-Oriented Language. It is a high-level programming language developed in the 1950s and has been predominantly used for business, finance, and administrative systems.
Reference: COBOL standard


2. What are the different divisions in a COBOL program?

Answer:
A COBOL program has four divisions: Identification, Environment, Data, and Procedure. They provide the program’s metadata, environment details, variable declarations, and logic respectively.


3. What is the ‘PIC’ clause in COBOL?

Answer:
‘PIC’ stands for Picture. It’s used in the Data Division to define the format and type of data a variable can hold. Example:

01 NUM-EXAMPLE PIC 9(3).

This defines a numeric variable of 3 digits.


4. Differentiate between MOVE and MOVE CORRESPONDING.

Answer:
MOVE assigns a value to a specific variable, while MOVE CORRESPONDING transfers matching data between two group items. MOVE is for singular fields, whereas MOVE CORRESPONDING is used for matched group variables.


5. What are REDLINES in COBOL?

Answer:
REDLINES are used for computational fields. They indicate how data is stored in memory. For instance, PIC 9(3)V99 represents a value with 3 integer and 2 decimal places.


6. Explain the difference between CONTINUE and NEXT SENTENCE in COBOL.

Answer:
Both are used for control flow. While they appear similar, CONTINUE transfers control to the next statement after the scope terminator, while NEXT SENTENCE transfers to the statement after the nearest period.


7. What is the PERFORM statement?

Answer:
The PERFORM statement calls a paragraph or section for execution. Code snippet:

PERFORM PARAGRAPH-NAME

It invokes the logic present in the PARAGRAPH-NAME paragraph.


8. How can you initiate a COBOL program’s execution?

Answer:
A COBOL program begins execution from the paragraph or section named in the PROCEDURE DIVISION header, unless directed elsewhere by using the MAIN keyword or specific environment setup.


9. What is the purpose of the EVALUATE statement?

Answer:
EVALUATE is COBOL’s version of a switch-case. It evaluates an expression and transfers control based on the value.

EVALUATE TRUE
    WHEN CONDITION-1 
        STATEMENT-1
    WHEN CONDITION-2
        STATEMENT-2
    WHEN OTHER 
        STATEMENT-3
END-EVALUATE.

10. What does the 88 level number indicate?

Answer:
Level 88 in COBOL denotes a condition name. It’s a way to associate a mnemonic with a specific value or range of values for a variable.

01 VAR-NAME PIC X(5).
   88 IS-TRUE VALUE 'TRUE'.

11. What are the different types of files in COBOL?

Answer:
COBOL supports Sequential, Indexed, and Relative files. Sequential files have records in sequence, Indexed have key-based access, and Relative files use relative record numbers.


12. What is the purpose of INSPECT?

Answer:
INSPECT is used for string handling operations, like counting the occurrences of a substring or replacing characters in a string.


13. How can you debug a COBOL program?

Answer:
COBOL debugging can be done using the DISPLAY statement to print values or using specialized debugging tools provided by certain COBOL platforms or IDEs.


14. Explain CALL and LINK.

Answer:
CALL is used to invoke another COBOL program or method. LINK is used in mainframes to pass control and data between programs, with the difference that LINK can return control to the calling program.


15. How is a COPYBOOK used in COBOL?

Answer:
A COPYBOOK contains reusable COBOL code which can be included in multiple programs. It’s used with the COPY statement, promoting code reusability and maintainability.


16. Define REDEFINES in COBOL.

Answer:
REDEFINES allows a data item to occupy the same memory space as another data item. It’s used for data representation alternatives without duplicating storage.
[Reference: REDEFINES](https://www.ibm.com/docs

/en/cobol-zos/6.3?topic=statements-redefines)


17. How are arrays represented in COBOL?

Answer:
Arrays are termed as ‘Tables’ in COBOL. They’re defined using the OCCURS clause in the Data Division. For instance:

01 ARRAY-NAME OCCURS 10 TIMES.
   05 ELEMENT PIC 9(3).

This defines a 10-element numeric array.


18. What is a SEARCH statement?

Answer:
SEARCH is used to find an item in a table (array). SEARCH ALL is for binary search on indexed tables, while SEARCH does a top-to-bottom search.


19. What are the different data types available in COBOL?

Answer:
COBOL supports Alphabetic (A), Alphanumeric (X), Numeric (9), Packed Decimal (P), and Binary (B) data types.


20. How can you read a file in COBOL?

Answer:
Files are read using the READ statement. The AT END condition handles the scenario when the end of the file is reached. A loop typically manages the process of reading records.


21. What is the STRING operation?

Answer:
STRING concatenates multiple data items or literals into one data item. Delimiters can be specified, and upon execution, the resulting string is placed in the receiving field.


22. What is the purpose of the UNSTRING operation?

Answer:
UNSTRING is the opposite of STRING. It breaks a single string into multiple data items based on specified delimiters.


23. How do you handle exceptions in COBOL?

Answer:
Exceptions in COBOL are handled using condition names like INVALID KEY or AT END and the ON EXCEPTION or NOT ON EXCEPTION phrases after specific I/O operations.


24. How are multi-dimensional arrays defined in COBOL?

Answer:
Multi-dimensional arrays are defined using multiple OCCURS clauses.

01 MULTI-DIM-ARRAY.
   05 ROWS OCCURS 5 TIMES.
      10 COLUMNS PIC 9(3) OCCURS 10 TIMES.

This defines a 5×10 array.


25. What is the EXIT statement in COBOL?

Answer:
The EXIT statement serves as a placeholder. It indicates the end of a section or paragraph but has no executable function.



26. Explain the difference between READ INTO and READ WITH in COBOL.

Answer:
READ INTO is used to read data into a user-defined record structure, while READ WITH reads data into predefined COBOL data items, often referred to as ‘WORKING-STORAGE’ variables.


27. How is exception handling done in COBOL?

Answer:
Exception handling in COBOL is primarily achieved through condition names, CONTINUE, and the use of DISPLAY or STOP RUN to handle errors gracefully or terminate the program.


28. What is the purpose of the GO TO statement in COBOL?

Answer:
The GO TO statement allows for unconditional branching to a specified paragraph. It is generally discouraged and considered a poor programming practice because it can make code less structured and harder to maintain.


29. Explain the concept of “77-level” in COBOL.

Answer:
“77-level” is a special level number used to define elementary data items. It is typically used for simple variables that don’t require subfields or further subdivisions.


30. What is the role of WORKING-STORAGE in COBOL?

Answer:
WORKING-STORAGE is a Data Division section used to declare variables with program scope. It is typically used for temporary data storage during program execution.


31. How do you handle decimal arithmetic in COBOL?

Answer:
COBOL provides support for decimal arithmetic through the COMPUTE statement, allowing you to perform calculations with precision and rounding control.


32. Explain the concept of “level numbers” in COBOL.

Answer:
Level numbers in COBOL define the hierarchical structure of data items. They indicate whether a data item is elementary (e.g., level 01) or a group item (e.g., level 05).


33. What are the different types of file organizations supported by COBOL?

Answer:
COBOL supports various file organizations, including Sequential, Indexed, and Relative. Sequential files store records sequentially, Indexed files allow key-based access, and Relative files use relative record numbers.


34. How do you handle file processing errors in COBOL?

Answer:
File processing errors are handled using condition names like INVALID KEY or AT END in conjunction with READ, WRITE, or OPEN statements. These conditions allow you to handle errors gracefully.


35. What is the role of the INITIALIZE statement in COBOL?

Answer:
The INITIALIZE statement is used to set the initial values of data items in a COBOL program. It assigns predefined values, such as zero, to variables.


36. Explain the concept of “88-level” in COBOL.

Answer:
“88-level” is used to define condition names in COBOL. It associates a user-friendly name with a specific value or range of values for a variable, making the code more readable.


37. How do you perform string manipulation in COBOL?

Answer:
COBOL provides several string manipulation functions, including STRING, UNSTRING, and INSPECT, which allow you to concatenate, split, or modify strings as needed.


38. What is the purpose of the REPLACE statement in COBOL?

Answer:
The REPLACE statement in COBOL is used to find and replace specific characters or substrings within a string. It allows for efficient data cleansing and transformation.


39. How can you handle variable-length records in COBOL?

Answer:
Variable-length records can be handled using the DEPENDING ON clause in the OCCURS clause. This allows the record length to vary dynamically based on data content.


40. Explain the role of the CALL statement in COBOL.

Answer:
The CALL statement is used to invoke other COBOL programs or subroutines, allowing for modular and reusable code organization. It supports the concept of program modularity.


41. What is “CobolScript”?

Answer:
CobolScript is a scripting language based on COBOL syntax. It is often used for web development and allows COBOL programmers to create dynamic web applications.


42. How do you perform date and time manipulation in COBOL?

Answer:
COBOL provides intrinsic functions like CURRENT-DATE and DATE-OF-INTEGER to work with dates and times. It allows you to manipulate and calculate date/time values efficiently.


43. Explain the role of the MERGE statement in COBOL.

Answer:
The MERGE statement in COBOL is used to merge records from two or more sorted input files into a single sorted output file. It is often used for data consolidation and report generation.


44. What is “Embedded SQL” in COBOL?

Answer:
Embedded SQL allows SQL statements to be included directly within COBOL programs. It enables COBOL programs to interact with relational databases seamlessly.


45. How do you handle indexed files in COBOL?

Answer:
Indexed files in COBOL are handled using the READ and WRITE statements, along with key fields specified in the KEY clause. Indexed files provide efficient random access to data.


46. Explain the concept of “USAGE” in COBOL.

Answer:
“USAGE” in COBOL specifies the data representation method for a data item. Common usages include DISPLAY, BINARY, COMP, and COMP-3 for different data types and storage formats.


47. How is recursion implemented in COBOL?

Answer:
Recursion in COBOL is achieved by calling a program or subroutine from within itself. Care must be taken to define proper termination conditions to avoid infinite loops.


48. What is the purpose of the EXIT PROGRAM statement in COBOL?

Answer:
The EXIT PROGRAM statement is used to terminate the current program’s execution and return control to the calling program. It is often used to handle program flow in modular programming.


49. How can you perform arithmetic operations with packed decimal data in COBOL?

Answer:
COBOL provides arithmetic operations like ADD, SUBTRACT, MULTIPLY, and DIVIDE for packed decimal data. These operations automatically handle decimal point alignment.


50. What is the role of the COMMIT statement in COBOL?

Answer:
The COMMIT statement is used in COBOL programs that interact with databases to save changes made during the program’s execution. It ensures data consistency and durability.



51. What is the SIGN clause in COBOL?

Answer:
The SIGN clause in COBOL specifies how the sign of a numeric data item (positive or negative) is stored. It can be LEADING, TRAILING, or SEPARATE depending on its position and representation.


52. What’s the difference between START and OPEN statements in COBOL?

Answer:
The OPEN statement initializes file handling by establishing a connection to the file. START is specific to indexed files, positioning the file pointer at a specific record based on key values.


53. How can you handle dynamic arrays in COBOL?

Answer:
COBOL supports dynamic arrays using the OCCURS DEPENDING ON clause. This allows the size of the array to change dynamically based on a specified variable.


54. How is fixed-point arithmetic handled in COBOL?

Answer:
In COBOL, fixed-point arithmetic is achieved using PIC S9(n)V9(m). Here, n is the number of integer digits and m is the number of decimal places. Arithmetic operations respect this structure.


55. What is RENAMES in COBOL?

Answer:
RENAMES clause provides an alternative name for a group of data items, allowing you to reference a group of contiguous data items as one.


56. What is LINKAGE section in COBOL?

Answer:
The LINKAGE section in COBOL defines data that is passed from one program to another. It is primarily used for parameter passing between the calling and called programs.


57. How do you handle errors in COBOL programs related to database operations?

Answer:
Database errors in COBOL are often handled using condition handlers like INVALID KEY, END-OF-FILE, or specific SQLCODE error values after SQL operations.


58. How do you define constants in COBOL?

Answer:
Constants in COBOL are defined in the WORKING-STORAGE section using the VALUE clause. Example:

01 CONST-VALUE       PIC X(10) VALUE 'CONSTANT'.

59. What is the SUBTRACT CORRESPONDING statement?

Answer:
SUBTRACT CORRESPONDING performs arithmetic subtraction on matching data names of two group items. Only items with the same name in both groups are considered for the operation.


60. How do you define a two-dimensional array in COBOL?

Answer:
Two-dimensional arrays in COBOL are defined using nested OCCURS clauses. Example:

01 MATRIX.
   05 ROWS           OCCURS 10 TIMES.
      10 ELEMENTS    PIC 9(3) OCCURS 5 TIMES.

61. How can you sort data in a COBOL program?

Answer:
Data in a COBOL program can be sorted using the SORT verb. It allows sorting of files or arrays based on specific keys.


62. What is STOP RUN in COBOL?

Answer:
The STOP RUN statement indicates the end of the main program’s execution, returning control back to the operating system or calling program.


63. How are comments added in COBOL programs?

Answer:
Comments in COBOL are added using the *> prefix. They provide explanatory text within the program and are not executed.


64. What are different modes of opening a file in COBOL?

Answer:
In COBOL, files can be opened in various modes: INPUT (read-only), OUTPUT (write-only), I-O (for both reading and writing), and EXTEND (append mode).


65. How do you delete a record from a file in COBOL?

Answer:
Records can be deleted from a file using the DELETE verb followed by the file’s logical name, especially relevant for indexed and relative files.


66. What is a CURSOR in COBOL?

Answer:
A CURSOR in COBOL, used with embedded SQL, is a control structure to traverse and fetch rows from the result set of an SQL query.


67. How can you update a record in a COBOL database file?

Answer:
To update a record in a COBOL database file, use the REWRITE verb followed by the record name. Ensure the record is correctly positioned before the update.


68. How do you handle null values in COBOL?

Answer:
Null values in COBOL, especially with databases, can be managed using the IS NULL or IS NOT NULL conditions and setting or evaluating the NULL INDICATORS.


69. What is the difference between SEQUENTIAL and RANDOM access in file handling?

Answer:
SEQUENTIAL access reads/writes records one after another, while RANDOM access directly accesses records using a specific key, making it faster for specific record retrieval.


70. How is multithreading achieved in COBOL?

Answer:
Modern COBOL implementations, especially on platforms like Java and .NET, support multithreading. It allows parallel execution of COBOL programs or sections using specific THREAD directives.



71. What is the DIVIDE statement in COBOL?

Answer:
The DIVIDE statement is used to perform division operations. You can divide two numbers and store the quotient and remainder separately.


72. Explain PERFORM UNTIL.

Answer:
The PERFORM UNTIL statement repetitively executes a set of COBOL statements until a specific condition becomes true.


73. How is dynamic memory allocation handled in COBOL?

Answer:
COBOL uses the SET statement along with the POINTER clause for dynamic memory allocation and deallocation. This can be combined with ALLOCATE and FREE verbs in modern implementations.


74. What is the purpose of the USAGE clause?

Answer:
The USAGE clause in COBOL dictates how data is stored in memory. Common options include DISPLAY (default, human-readable) and BINARY (efficient storage).


75. What are ACCEPT and DISPLAY verbs used for?

Answer:
ACCEPT reads input (often from the console or system settings), while DISPLAY outputs data, typically to the console. They’re fundamental for basic I/O operations in COBOL.


76. How can you reverse a string in COBOL?

Answer:
To reverse a string in COBOL, you’d typically use a loop in combination with the STRING and UNSTRING verbs, processing the string character by character.


77. Explain the difference between static and dynamic calls in COBOL.

Answer:
In static calls, the called program is a part of the calling program and remains so for its lifetime. In dynamic calls, the called program is loaded at run-time and can be replaced without affecting the calling program.


78. How do you concatenate strings in COBOL?

Answer:
Strings can be concatenated using the STRING verb, which combines multiple data items or literals into a single data item.


79. How is file status checked in COBOL?

Answer:
The FILE STATUS clause, associated with file I/O operations, provides a two-character code indicating the result of the last file operation, useful for error-handling.


80. Explain the role of the VALUE clause in COBOL.

Answer:
The VALUE clause initializes a data item’s value. It’s primarily used in the WORKING-STORAGE section to set initial values for variables.


81. What is the significance of the COPY statement?

Answer:
The COPY statement is used to include contents of a COPYBOOK (a reusable piece of COBOL code) into a COBOL program. It enhances modularity and reusability.


82. Describe the MOVE CORRESPONDING statement.

Answer:
MOVE CORRESPONDING transfers data between two group items. Only the elementary data items with matching names in both groups are affected.


83. How do you handle trailing spaces or zeros in COBOL?

Answer:
The INSPECT verb in conjunction with TALLYING or REPLACING options can be used to handle and manipulate trailing spaces or zeros in strings.


84. What are the different STRING handling functions in COBOL?

Answer:
COBOL provides a range of string functions, including STRING, UNSTRING, INSPECT, FUNCTION LENGTH, and REFERENCE MODIFICATION, aiding in various string manipulation tasks.


85. How do you define a structure or record in COBOL?

Answer:
In COBOL, structures or records are defined in the DATA DIVISION, often using hierarchical level numbers to represent fields and subfields of the record.


86. How are logical conditions evaluated in COBOL?

Answer:
COBOL evaluates logical conditions using relational operators like =, >, <, >=, <=, NOT =. Combined with AND, OR, they form complex conditions.


87. What is the THRU or THROUGH clause in COBOL?

Answer:
The THRU or THROUGH clause is used in range specifications, often in the PERFORM verb, indicating a range of paragraphs or sections to be executed.


88. How can you call an external subroutine in COBOL?

Answer:
An external subroutine can be invoked using the CALL statement, specifying the external program’s name and passing any required parameters.


89. Describe the significance of the FD entry in COBOL.

Answer:
FD (File Description) entry in COBOL describes the physical and logical properties of an external file. It is essential for file handling operations.


90. How is arithmetic overflow handled in COBOL?

Answer:
Arithmetic overflow in COBOL can be handled using the ON SIZE ERROR clause. It specifies the set of statements to be executed if an overflow occurs.


91. What is the difference between COMP and COMP-3?

Answer:
COMP is binary representation, whereas COMP-3 represents packed decimal format. COMP-3 stores data as BCD (Binary-Coded Decimal) and is space-efficient for decimal numbers.


92. How do you define optional arguments in a COBOL subroutine?

Answer:
Optional arguments in COBOL subroutines can be implemented using the LINKAGE SECTION with no corresponding arguments in the calling program. They’ll be treated as optional.


93. Explain the purpose of RETURN-CODE in COBOL.

Answer:
RETURN-CODE is a system-defined word that captures the status of the program’s execution. It’s used to determine if the program executed successfully or encountered an error.


94. How do you define a local variable in COBOL?

Answer:
Local variables in COBOL can be defined in the WORKING-STORAGE SECTION or the LOCAL-STORAGE SECTION. Variables in LOCAL-STORAGE are reinitialized with every invocation.


95. How can you extract a substring from a string in COBOL?

Answer:
A substring can be extracted using the REFERENCE MODIFICATION feature in COBOL. Syntax: string(starting-position : length).


96. How can you modify an existing COBOL program without changing its source code?

Answer:
Using the COPY and REPLACE directives, you can insert and replace specific portions of a COBOL program without altering the original source.


97. What is the difference between IN and OF in COBOL’s PERFORM?

Answer:
Both are used in loops. PERFORM ... TIMES executes a loop fixed times. PERFORM UNTIL loops until a condition becomes true, while PERFORM VARYING loops with an incrementing/decrementing index.


98. Describe the INSPECT verb in COBOL.

Answer:
The INSPECT verb is used for string handling operations, such as counting the occurrences of specific characters or replacing characters within a string.


99. How is data redefined in COBOL?

Answer:
Data can be redefined using the REDEFINES clause. It allows data storage at the same memory location but provides a new view or format.


100. What is the role of the EVALUATE statement?

Answer:
EVALUATE is COBOL’s version of a switch-case statement. It checks multiple conditions and executes the corresponding logic when a condition is true.