문제

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"

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top