-
Notifications
You must be signed in to change notification settings - Fork 47
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
Comments
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:
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, |
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.
The text was updated successfully, but these errors were encountered: