Ways to flip a Boolean
Whenever working with booleans while writing code there is almost always a scenario where one has to flip the boolean state i.e. true to false or vice-versa based on some condition.
In this post, I wanted to showcase different ways to do so.
Using Control statements:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Using If statement. | |
IF lv_someflag = abap_true. | |
lv_mybool = abap_false. | |
ELSE. | |
lv_mybool = abap_true. | |
ENDIF. |
Using ABAP logical functions such as boolc and xsdbool :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Using boolc function | |
lv_mybool = boolc( lv_someflag <> abap_true ). | |
"Using XSDBOOL. | |
lv_mybool = xsdbool( lv_someflag <> abap_true ). |
Hope you like it and use it in your day-to-day development.