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.

FeatureCONTINUENEXT SENTENCE
PurposeActs as a "do nothing" placeholderMoves control to the next sentence (next sentence after period .)
EffectControl passes to the next statement inside the same paragraph/blockControl jumps to the next sentence (after the next period .)
Common UsageUsed inside loops, IF blocks to indicate no actionUsed inside IF statements to skip remaining statements until the next period
Nested ConditionsPreferred for better control within structured programmingLess 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.

FeatureIn-Line PERFORMOutline PERFORM
Execution ScopeExecutes code within the PERFORM blockCalls a separate paragraph or section
ReusabilityNot reusable; executes only within the blockReusable across different parts of the program
TerminationRequires END-PERFORMNo termination needed
Code StructureBest for short operationsBest for long, structured, and reusable logic
ReadabilityReduces extra paragraphsImproves 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.

FeatureWITH TEST BEFOREWITH TEST AFTER
Condition CheckBefore executing the loop body After executing the loop body
Ensures at Least One Execution?NoYes
Behavior If Condition Is True InitiallyLoop does not executeLoop executes at least once
Default in COBOLYesNo (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:

ModePurposeFile Must Exist?Allows Read?Allows Write?
INPUTOpens the file for reading only.YesYesNo
OUTPUTOpens the file for writing (creates a new file or replaces existing content).NoNoYes
I-O (Input-Output)Opens the file for both reading and updating (reading & writing).YesYesYes
EXTENDOpens the file for appending new records without deleting existing data.YesNoYes

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