COBOL Interview Questions and Answers (41 - 50)


41. What is the difference between static and dynamic calls?

FeatureStatic CallingDynamic Calling
CompilationCalled program is linked at compile time.Called program is linked at runtime.
FlexibilityLess flexible (needs recompilation if the subprogram changes).More flexible (subprogram can be modified without recompiling main program).
PerformanceFaster (no runtime loading).Slightly slower (due to runtime loading).
Executable SizeLarger (subprogram is part of the executable).Smaller (subprogram is separate).
CALL SyntaxCALL "SUBPROG".CALL WS-PROG-NAME.
Use CaseBest for fixed, high-performance programs.Best for modular, reusable, and frequently changing programs.

42. How can we find that module can be called – whether DYNAMICALLY or STATICALLY?

Check the CALL Statement:

  • Static Call → The program name is hardcoded in quotes (CALL "SUBPROG").
  • Dynamic Call → The program name is stored in a variable (CALL WS-PROG-NAME).

Check the Compiled Options:

  • DYNAM → Call will treated as Dynamic call.
  • NODYNAM → Call will treated as static call.

43. How many ways to pass the data to the COBOL program (no CICS)?

Data can be passed to a COBOL program in several ways depending on how it is coded. The main methods include:

  • Passing Data Using CALL ... USING (Subprogram Calls)
  • Passing Data Using JCL PARM= (Batch Processing)
  • Passing Data using JCL SYSIN DD
  • Passing Data Using Files

44. What is the difference between STOP RUN and GOBACK?

FeatureSTOP RUNGOBACK
PurposeTerminates the entire COBOL program (including main and subprograms)Returns control to the calling program (or ends execution if in the main program)
UsageUsed in main programs to stop execution completelyUsed in both main and subprograms to return to the caller
Effect in SubprogramsEnds the entire application (even the main program)Returns control to the main program without stopping it
Control FlowNo further execution after STOP RUNExecution continues in the calling program

45. What is the difference between calling program and called program?

FeatureCalling (Main) ProgramCalled (Sub) Program
DefinitionThe program that initiates the callThe program that executes when called
Control FlowTransfers control to the called program and waitsExecutes logic and returns control to the caller
DeclarationResumes execution after the called program finishesUses LINKAGE SECTION to receive parameters
Execution ContinuationNo further execution after STOP RUNEnds execution with GOBACK or EXIT PROGRAM
Data HandlingPasses parameters using USING clauseReceives parameters via LINKAGE SECTION
Example StatementCALL "SUBPROG" USING WS-DATAPROCEDURE DIVISION USING LK-DATA

46. How arrays can be defined in COBOL?

Arrays in COBOL are called tables and are defined using the OCCURS clause.

01 EMPLOYEE-TABLE.
   05 EMPLOYEE-DETAILS OCCURS 5 TIMES.
      10 EMP-ID   PIC 9(5).
      10 EMP-NAME PIC X(20).

This defines an array of 5 employee records, each containing EMP-ID and EMP-NAME.

47. What is the difference between subscript and index?

SubscriptIndex
Subscript is no of occurrences of an array. An index is the number of displacement positions of an array.
Subscript should declare separately with S9(04) COMP in WORKING-STORAGE SECTION. The index doesn't require a separate declaration. INDEX BY phrase used to declare it along with table declaration.
Subscript is slow in accessing table data. The index is faster in accessing table data.
Subscript can initialize by using MOVE statement. An index should be initialized by using the SET statement.
Subscript can increase by an ADD statement and decrease by using the SUBTRACT statement. An index can increased and decreased by using the SET statement.

48. What is binary search?

Binary Search (SEARCH ALL) is a fast searching technique used to find an element in a sorted table (array) by repeatedly dividing the search range in half. It is faster than sequential search but requires the table to be sorted before searching.

Key Features:

  • Requires the table to be sorted before searching.
  • Uses SEARCH ALL for efficient searching.
  • Works faster than sequential search, especially for large datasets.

49. Can a Search can be done on a table with or without Index?

Both linear search (SEARCH) and binary search (SEARCH ALL) requires an index (INDEXED BY) to perform search on the table.

50. A table has two indexes defined. Which one will be used by the SEARCH?

SEARCH uses the index that is set before execution (SET EMP-INDEX1 TO 1).

...
01 EMP-TABLE.
   05 EMP-DETAILS OCCURS 10 TIMES 
      INDEXED BY EMP-INDEX1, EMP-INDEX2.
      10 EMP-ID   PIC 9(5).
      10 EMP-NAME PIC X(20).

PROCEDURE DIVISION.
    SET EMP-INDEX1 TO 1.  *> This index will be used
    SEARCH EMP-DETAILS
        WHEN EMP-ID (EMP-INDEX1) = WS-SEARCH-ID
            DISPLAY "Employee Found: " EMP-NAME (EMP-INDEX1)
	END-SEARCH.