code-pal-for-abap-cloud
code-pal-for-abap-cloud copied to clipboard
Check for proper treatment of booleans
trafficstars
The guidance for the usage of booleans is currently not covered by any ATC check, but it should be feasible to do so. The check could detect:
- Usages of
'X'and''orspaceinstead ofabap_trueandabap_false. In a first approximation it should not even be necessary to check whether the variable this is assigned or compared to is typed withabap_boolsince even if it's not a boolean you probably should use meaningful constants instead of a literal'X'. - Usages of
is initialinstead of= abap_falsefor variables typed asabap_boolorabap_boolean. - IF-THEN-ELSE constructs that can be replaced by
xsdboolassignments (cf. style guide)
For all these cases we could also offer quick fixes.
To be discussed: What about is not initial comparisons? These are not semantically equivalent to comparisons = abap_true since there could be other characters in the variable (in particular abap_undefined), and the ABAP language has decided to make is not initial the "default check for truth" of the language - in predicative method calls like IF meth->is_true( )., the statement is equivalent to IF meth->is_true( ) IS NOT INITIAL..