Question

Are there any existing methods or function modules that flip boolean values efficiently?

I've come up with a simple implementation should I have to define my own utility method, but I'm wondering if this is the most efficient approach:

IF iv_bool = abap_true.
    rt_bool = abap_false.
ELSEIF iv_bool = abap_false.
    rt_bool = abap_true.
ELSE.
    rt_bool = abap_undefined.
ENDIF.

EDIT: As mentioned by Smigs, this implementation flips three-valued booleans or "trileans"

Was it helpful?

Solution

rt_bool = boolc( iv_bool <> abap_true ).

will flip a boolean. However, it wouldn't deal with abap_undefined.

From 740 SP08 onwards, you can use xsdbool( ) instead of boolc( ) to achieve the same result. There is no difference for the example given, but xsdbool( ) is safer when using in comparisons

OTHER TIPS

Just put a "not" before the condition:

rv_bool = xsdbool( not ( a = b and c = d ) ).

There is no need for workarounds. You can code it straight on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top