COBOL Interview Questions and Answers (51 - 20)


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. Describe the purpose of the FD and SD entries?

FD (File Description) Entry:

  • Used in the FILE SECTION to define input or output files.
  • Specifies file structure, record layout, and organization.
  • Used for sequential, indexed, or relative files.

SD (Sort Description) Entry:

  • Used in the FILE SECTION to define a temporary sort work file.
  • Required when using the SORT statement.
  • Stores records during sorting operations but does not require explicit OPEN and CLOSE.

55. 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.

56. 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.

57. 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.

58. What is a SSRANGE and NOSSRANGE?

SSRANGE (Subscript Range Checking Enabled):

  • Enables runtime checking for array (table) out-of-bounds errors.
  • If a subscript or index exceeds the defined range, an error occurs.
  • Used for debugging and preventing memory corruption.

NOSSRANGE (Subscript Range Checking Disabled - Default):

  • Does not check array bounds at runtime.
  • Improves performance but may cause memory corruption if subscripts go out of range.

59. Difference between OS COBOL to VS COBOL II?

FeatureOS COBOLVS COBOL II
PerformanceSlower executionFaster execution with optimization
Memory UsageLimited memory handlingSupports large memory addressing (AMODE 31)
Structured ProgrammingSupports GO TO-based logicEncourages structured programming (no GO TO)
Dynamic Call SupportOnly supports static callsSupports both static and dynamic calls
DebuggingLimited debugging featuresBetter debugging and error diagnostics