code-pal-for-abap-cloud icon indicating copy to clipboard operation
code-pal-for-abap-cloud copied to clipboard

Check for proper treatment of booleans

Open bjoern-jueliger-sap opened this issue 2 years ago • 0 comments
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 '' or space instead of abap_true and abap_false. In a first approximation it should not even be necessary to check whether the variable this is assigned or compared to is typed with abap_bool since even if it's not a boolean you probably should use meaningful constants instead of a literal 'X'.
  • Usages of is initial instead of = abap_false for variables typed as abap_bool or abap_boolean.
  • IF-THEN-ELSE constructs that can be replaced by xsdbool assignments (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..

bjoern-jueliger-sap avatar Oct 23 '23 12:10 bjoern-jueliger-sap