COBOL Realtime (Scenario based) Interview Questions (51 - 60)
51. What are the file open modes for reading the indexed and relative files?
Input and I-O modes.
52. Can we read indexed files sequentially without using START statement?
Yes. we can read the file from beginning.
53. Can we delete a record from the indexed file directly?
Yes. We can delete the record directly from indexed file without issuing and READ with UPDATE.
54. What happened if I didn't close the files after usage?
The files get automatically closed at the end of the program execution.
55. What happen when we coded STOP RUN instead of GOBACK in subprogram?
Control returns to the Operating System instead of the Main program.
56. What happen when we coded GOBACK instead of STOP RUN in main program?
There is no change in the control return and it returns to the Operating System.
57. Can we access sequential file randomly? Why?
No, sequential files cannot be accessed randomly in COBOL. Reason:
- Sequential files are designed to be read record by record in order.
- No direct access mechanism like indexed or relative files.
- To find a specific record, the program must read all preceding records.
58. What is the importance of using REPLACING option in a COPY statement?
The REPLACING option in a COPY statement dynamically replaces specific text or variables within the copybook during compilation. Allows reusability of copybooks by modifying field names, literals, or reserved words without changing the original copybook.
Example: Copybook declaration - EMPLOYEE
01 EMP-DETAILS.
05 EMP-ID PIC 9(5).
05 EMP-NAME PIC X(20).
Example With REPLACING:
COPY EMPLOYEE REPLACING ==EMP== BY ==STUDENT==.
The program will contain:
01 STUDENT-DETAILS.
05 STUDENT-ID PIC 9(5).
05 STUDENT-NAME PIC X(20).
59. How is SSRANGE different from NOSSRANGE?
SSRANGE | NOSSRANGE |
---|---|
Enables subscript/index range checking at runtime. | Disables range checking for subscripts and indexes. |
If an out-of-range index is used, the program abends (runtime error). | No runtime error; may access unintended memory (unpredictable behavior). |
Slightly slower due to extra checks. | Faster, as no additional checks are performed. |
Used during testing/debugging to catch out-of-bound errors. | Used in production for better performance. |
60. What happens during INPUT PROCEDURE and OUTPUT PROCEDURE?
INPUT PROCEDURE (Before Sorting): Reads records from an input file. Performs data validation, filtering, or modifications before sorting. Uses RELEASE to send records to the SORT process.
OUTPUT PROCEDURE (After Sorting): Receives sorted records one by one. Performs data formatting, aggregation, or writing to output files. Uses RETURN to fetch sorted records.