Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-Request: Replace bad boolean dataelements in declarations #260

Closed
SteffCF opened this issue Feb 28, 2024 · 1 comment
Closed

Feature-Request: Replace bad boolean dataelements in declarations #260

SteffCF opened this issue Feb 28, 2024 · 1 comment

Comments

@SteffCF
Copy link

SteffCF commented Feb 28, 2024

In abap abap_true is 'X' and abap_false is ''.
But there are some verry bad boolean types in abap, which don't comply with those settings.

E.g. Boolean or bool.

Perhaps it is possible to replace such dataelemts in local declarations.
For this feature it should be sufficient to just declare a blacklist of all bad boolean types, so that it is not necessary to read the domain-values from the backend.
The replacement also should only take place if the variable is used only as boolean.

" Bad code
DATA l_is_initial TYPE boolean VALUE abap_true. "boolsche Variable (X=true, -=false, space=unknown)
DATA l_is_initial_2 TYPE bool VALUE abap_true. "type c length 3

IF l_is_initial = abap_true.
l_is_initial = abap_false.
ENDIF.
l_is_initial_2 = xsdbool( 1 = 2 ).

" Better Code
DATA l_is_initial_3 TYPE xsdboolean VALUE abap_true.

IF l_is_initial = abap_false.
l_is_initial = abap_false.
ENDIF.

@jmgrassau
Copy link
Member

Hi SteffCF,

yes, this zoo of Boolean types really is a pain!

I don't think, though, that such a replacement could be safely automated, because some of those types have conflicting values:

  • BOOLEAN: space=unknown(!!), "-"=false(!!)
  • ABAP_BOOL: space=false (constant ABAP_FALSE), "-"=undefined (constant ABAP_UNDEFINED, which the documentation advises not to use)
  • ABAP_BOOLEAN, XFELD, BOOLEAN_FLG, XSDBOOLEAN (the return type of "xsdbool( … )") and BOOLE (the domain of the data element BOOLE_D): space=false (and no value for unknown)
  • BOOLE01, BOOLEAN01: "0"=false, "1"=true
  • BOOL: the value list only holds the values "AND", "OR", so this is about Boolean operators, not Boolean values.

If that's taken seriously, we would need to convert …

    DATA lv_flag TYPE boolean.
    lv_boolean = space. " neither true nor false

… into …

    DATA lv_flag TYPE abap_bool.
    lv_boolean = abap_undefined. " neither true nor false

Or more generally, have conversion code like this:

    DATA lv_abap_bool TYPE abap_bool.
    DATA lv_boolean   TYPE boolean.
    lv_boolean = SWITCH boolean( lv_abap_bool
                                 WHEN abap_false     THEN '-'
                                 WHEN abap_undefined THEN ' '
                                 ELSE                     'X' ).

I don't think anyone wants that. Surely, there may be secret knowledge such as: "in our team, nobody is even aware of this difference, we always use space for false, and never use unknown or undefined states", but how should ABAP cleaner be able to know about that and rely on it? And maybe the code calls function modules that do not follow this convention?

Also suppose a Boolean variable is determined via function call (and ABAP cleaner can't retrieve the signature to check the return type), or comes into our method as a parameter of a "bad" type, which should then be assigned to a variable with a "good" type…

So, I am afraid this would require careful manual work, trying to understand the original intent of the code.

Kind regards,
Jörg-Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants