COBOL Interview Questions and Answers (41 - 50)
41. What is the difference between static and dynamic calls?
Feature | Static Calling | Dynamic Calling |
---|---|---|
Compilation | Called program is linked at compile time. | Called program is linked at runtime. |
Flexibility | Less flexible (needs recompilation if the subprogram changes). | More flexible (subprogram can be modified without recompiling main program). |
Performance | Faster (no runtime loading). | Slightly slower (due to runtime loading). |
Executable Size | Larger (subprogram is part of the executable). | Smaller (subprogram is separate). |
CALL Syntax | CALL "SUBPROG". | CALL WS-PROG-NAME. |
Use Case | Best 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?
Feature | STOP RUN | GOBACK |
---|---|---|
Purpose | Terminates the entire COBOL program (including main and subprograms) | Returns control to the calling program (or ends execution if in the main program) |
Usage | Used in main programs to stop execution completely | Used in both main and subprograms to return to the caller |
Effect in Subprograms | Ends the entire application (even the main program) | Returns control to the main program without stopping it |
Control Flow | No further execution after STOP RUN | Execution continues in the calling program |
45. What is the difference between calling program and called program?
Feature | Calling (Main) Program | Called (Sub) Program |
---|---|---|
Definition | The program that initiates the call | The program that executes when called |
Control Flow | Transfers control to the called program and waits | Executes logic and returns control to the caller |
Declaration | Resumes execution after the called program finishes | Uses LINKAGE SECTION to receive parameters |
Execution Continuation | No further execution after STOP RUN | Ends execution with GOBACK or EXIT PROGRAM |
Data Handling | Passes parameters using USING clause | Receives parameters via LINKAGE SECTION |
Example Statement | CALL "SUBPROG" USING WS-DATA | PROCEDURE 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?
Subscript | Index |
---|---|
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.