COBOL Interview Questions and Answers (31 - 40)
31. What is the difference between CONTINUE & NEXT SENTENCE?
Both CONTINUE and NEXT SENTENCE are used to skip execution and move forward, but they behave differently in terms of flow control.
Feature | CONTINUE | NEXT SENTENCE |
---|---|---|
Purpose | Acts as a "do nothing" placeholder | Moves control to the next sentence (next sentence after period .) |
Effect | Control passes to the next statement inside the same paragraph/block | Control jumps to the next sentence (after the next period .) |
Common Usage | Used inside loops, IF blocks to indicate no action | Used inside IF statements to skip remaining statements until the next period |
Nested Conditions | Preferred for better control within structured programming | Less recommended due to unexpected jumpss |
32. What is the difference between an in-line PERFORM and outline PERFORM?
Both in-line PERFORM and outline PERFORM are used to execute a set of instructions repeatedly, but they differ in how and where the execution logic is defined.
Feature | In-Line PERFORM | Outline PERFORM |
---|---|---|
Execution Scope | Executes code within the PERFORM block | Calls a separate paragraph or section |
Reusability | Not reusable; executes only within the block | Reusable across different parts of the program |
Termination | Requires END-PERFORM | No termination needed |
Code Structure | Best for short operations | Best for long, structured, and reusable logic |
Readability | Reduces extra paragraphs | Improves modularity and maintainability |
33. Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?
The default is TEST BEFORE in a PERFORM UNTIL or PERFORM VARYING loop.
34. What is the difference between PERFORM ... WITH TEST AFTER and PERFORM ... WITH TEST BEFORE?
The TEST BEFORE or TEST AFTER option in a PERFORM loop determines when the loop condition is checked—either before or after executing the loop body.
Feature | WITH TEST BEFORE | WITH TEST AFTER |
---|---|---|
Condition Check | Before executing the loop body | After executing the loop body |
Ensures at Least One Execution? | No | Yes |
Behavior If Condition Is True Initially | Loop does not execute | Loop executes at least once |
Default in COBOL | Yes | No (must be explicitly mentioned) |
35. What is the Purpose of Pointer in the string?
A pointer in the STRING operation is used to track the position where data is being stored in the destination field.
36. What are the different OPEN modes available in Cobol?
The OPEN statement is used to open a file before processing. The available OPEN modes are:
Mode | Purpose | File Must Exist? | Allows Read? | Allows Write? |
---|---|---|---|---|
INPUT | Opens the file for reading only. | Yes | Yes | No |
OUTPUT | Opens the file for writing (creates a new file or replaces existing content). | No | No | Yes |
I-O (Input-Output) | Opens the file for both reading and updating (reading & writing). | Yes | Yes | Yes |
EXTEND | Opens the file for appending new records without deleting existing data. | Yes | No | Yes |
37. What are the access mode for START statement?
The START statement is used to position an indexed or relative file for sequential reading, but it requires the file to be opened in ACCESS MODE IS DYNAMIC.
Valid File Access Modes for START:
- DYNAMIC → Allows both random and sequential access (Required for START).
Invalid File Access Modes for START:
- SEQUENTIAL → Not allowed for START, as it requires direct positioning.
- RANDOM → Cannot perform READ NEXT after START.
38. Why is it necessary that file needs to be opened in I-O mode for REWRITE?
The REWRITE statement is used to update an existing record in a file. Since updating involves both reading the record and writing the modified data, the file must be opened in I-O (Input-Output) mode.
- Allows both Reading and Writing → I-O mode enables modifying an existing record.
- Prevents Accidental Overwriting → Ensures only the correct record is updated.
- Mandatory for REWRITE → COBOL requires the file to be in I-O mode; otherwise, a runtime error occurs.
39. Which access mode is used to operate the sequential file?
A sequential file operates using the SEQUENTIAL access mode. The records in the sequential file are processed one after another in the order they were written.
Valid Open Modes for Sequential Files:
- INPUT → To read an existing file.
- OUTPUT → To write a new file (creates or replaces the file).
- EXTEND → To append new records to an existing file.
40. What is Static and Dynamic calling?
STATIC CALL attaches the SUBPROG load module to the MAINPROG load module to increase processing speed. The load modules of MAINPROG and SUBPROG are stored together, that reduces the loading time of the SUBPROG load module into the main memory.
CALL "SUBPROG"
DYNAMIC CALL removes the compilation dependency of MAINPROG when the SUBPROG is modified. The CALL statement is coded with a variable containing the SUBPROG name to separate the load modules stored independently.
MOVE "SUBPROG" TO WS-PROG-VAR.
CALL WS-PROG-VAR