CRITICAL
Rule Definition
The keyword WHEN OTHERS is executed when none of the conditions being tested for in the CASE statement are met or executed. Having no WHEN OTHERS means that there is a strong assumption about the value of data.
The cases that are "impossible" today are the ones most likely to be the causes of untraceable bugs in the future, when the impossible changes to the standard.
Remediation
Add the proper exception handling code in the WHEN OTHERS clause.
Violation Code Sample
CASE tp_materialtype.
WHEN co_materialtype_raw.
* Handling of material type RAW starts here
WHEN co_materialtype_semi.
* Handling of material type SEMI starts here
ENDCASE.
Fixed Code Sample
Remediation example:
CASE tp_materialtype.
WHEN co_materialtype_raw.
* Handling of material type RAW starts here
WHEN co_materialtype_semi.
* Handling of material type SEMI starts here
WHEN OTHERS
* The exception is caught here
ENDCASE.
Reference
Enhancing the Quality of ABAP Development,
Meijs-Krouwels-Heulmans-Sommen, SAP Press
ISBN 1-59229-030-2
Page 223
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
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.