Rule Definition
The EVALUATE statement allows the implementation of case structures in Cobol. Each case is managed by a WHEN phrase activated by a specific test of a variable. This variable can be the result of a database access, a file record type, the return code of a subprogram or an error code. The WHEN OTHER phrase allows the management of all the cases which have not been taken into account by the previous WHEN phrases. If the variable to be tested contains a new value that is not currently managed then the absence of the WHEN OTHER phrase will lead to a situation in which no process will be performed for this value and the program may have uncontrolled or undefined behavior.
Remediation
Add a WHEN OTHER clause into each EVALUATE statement.
Violation Code Sample
* If WS-STATUS is 3 then there is not action performed
EVALUATE WS-STATUS
WHEN 1
MOVE X TO Y
WHEN 2
MOVE Z TO Y
END-EVALUATE.
Fixed Code Sample
EVALUATE WS-STATUS
WHEN 1
MOVE X TO Y
WHEN 2
MOVE Z TO Y
WHEN OTHER
PERFORM DISPLAY-ERROR-MESSAGE
END-EVALUATE.
Related Technologies
Cobol
Technical Criterion
CWE-478 - Missing Default Case in Multiple Condition Expression
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.