rspec/rules/S131/abap/rule.adoc

57 lines
1014 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
The requirement for an ``++OTHERS++`` clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken.
2020-06-30 12:47:33 +02:00
=== Noncompliant code example
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,abap]
2020-06-30 12:47:33 +02:00
----
CASE SY-INDEX. // Noncompliant; missing WHEN OTHERS clause
WHEN ONE.
WRITE 'One'.
WHEN 2.
WRITE 'Two'.
ENDCASE.
----
=== Compliant solution
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,abap]
2020-06-30 12:47:33 +02:00
----
CASE SY-INDEX.
WHEN ONE.
WRITE 'One'.
WHEN 2.
WRITE 'Two'.
WHEN OTHERS. // Compliant
WRITE 'Unexpected result'
ENDCASE.
CASE SY-INDEX.
WHEN OTHERS. // Compliant
WRITE 'Unexpected result'
WHEN ONE.
WRITE 'One'.
WHEN 2.
WRITE 'Two'.
ENDCASE.
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]