EVALUATE WS-INPUT WHEN 1 WHEN 2 DISPLAY ‘OPTION 2’ WHEN 3 DISPLAY ‘OPTION 3’ WHEN OTHER DISPLAY ‘OTHER’ END-EVALUATE What will be displayed when WS-INPUT is 1?
-
Nothing will be displayed
-
OPTION 2
-
OPTION 3
-
OTHER
In COBOL EVALUATE, when a WHEN clause has no associated statements, it falls through to the next WHEN clause. When WS-INPUT is 1, it matches 'WHEN 1' (which has no statements), then execution continues to 'WHEN 2' which displays 'OPTION 2'. This fall-through behavior means the output is 'OPTION 2', not nothing, 'OPTION 3', or 'OTHER'.
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) Nothing will be displayed - This option is incorrect because according to the given EVALUATE statement, when WS-INPUT is 1, there is a WHEN 1 clause that does not have a DISPLAY statement associated with it.
Option B) OPTION 2 - This option is correct because when WS-INPUT is 2, the EVALUATE statement matches the condition in the WHEN 2 clause and displays "OPTION 2".
Option C) OPTION 3 - This option is incorrect because when WS-INPUT is 1, the condition in the WHEN 3 clause is not met.
Option D) OTHER - This option is incorrect because when WS-INPUT is 1, the condition in the WHEN OTHER clause is not met.
The correct answer is B) OPTION 2. This option is correct because when WS-INPUT is 2, the EVALUATE statement matches the condition in the WHEN 2 clause and displays "OPTION 2".