COBOL Interview Questions (51 - 58)
51. Which Search verb is equivalent to PERFORM...VARYING?
SEARCH (Sequential Search) is equivalent to PERFORM ... VARYING because:
- It searches sequentially through a table (one element at a time).
- It does not require sorting of the table.
- It uses an index (INDEXED BY) instead of a subscript.
52. What is the difference between a binary search and a sequential search?
Sequential search (SEARCH) | Binary search (SEARCH ALL) |
---|---|
SEARCH is a linear or sequential search. | SEARCH ALL is a binary search. |
Should handle index initialization and increment. | Only initialization is required for an index. Incrementing is taken care of automatically by the system. |
Coding multiple WHEN conditions are allowed and validated. | Only one WHEN condition is allowed to code. |
Can use arithmetic operators like =, >, <, <=, >=, NOT=. | Only = operator is allowed. |
Search process is slow. | Search process is fast. |
SEARCH can be used on single-dimensional and multidimensional tables. | SEARCH ALL can be used for only single-dimensional arrays. |
Data inside an array need not be in sorted order. | Data inside an array should be in a sorted order. |
53. What are INPUT PROCEDURE and OUTPUT PROCEDURE?
INPUT PROCEDURE (Used in SORT Statement):
- Used to read and process records before sorting.
- Allows pre-processing (filtering, modifying, validating data) before passing to SORT.
OUTPUT PROCEDURE (Used in SORT Statement):
- Used to process sorted records after sorting.
- Allows post-processing (formatting, writing to a file, displaying results).
54. What kind of error is trapped by ON SIZE ERROR option?
The ON SIZE ERROR clause traps errors that occur during arithmetic operations when:
- Numeric Overflow – Result exceeds the PIC clause size.
- Division by Zero – Attempting to divide by zero.
- Truncation Error – Data loss due to inadequate storage size.
55. What is length is Cobol?
LENGTH is a special register that returns the size (number of bytes) of a variable or data item.
- Used to determine the length of a data item at runtime.
- Helps in dynamic processing of variable-length fields.
56. Describe the concept of COPY and REPLACING statements?
COPY Statement:
- Used to include pre-written code from a COPYBOOK into a program.
- Helps in code reuse and standardization.
- Typically used for record layouts, file definitions, and constants.
COPY Statement with REPLACING:
- Used to modify specific text or keywords within a COPYBOOK.
- Works with or without COPY statements.
- Helps in dynamic replacement of code.