Cleanest way to flip a Boolean

abap, boolean

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

Problem

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"

Original source