Data Objects for Truth Values
Truth values are results of logical expressions. A truth value is either true or false. ABAP does not yet support boolean data types and thus does not support data objects for truth values. Therefore, the result of a logical expression cannot be assigned directly to a data object.
It has become common practice to express the truth value "true" as value "X" and the truth value "false" as a blank (" "). There are also boolean functions that have a logical expression as an argument and are returned as the value "X" or a blank, depending on the result.
To make it easier to handle truth values expressed in this way, the type group
contains a data type
abap_bool of elementary type
with length 1, and the constants
abap_true of value " " and
of value " " as substitutes for a real boolean data type. There is also a constant
abap_undefined of value "-".
Using the Data Type abap_bool for Truth Values
When working explicitly with truth values, use the type
abap_bool as a substitute
for a real boolean data type. A data object declared in this way should have no values other than the
Using the type
abap_bool and the constants
abap_false makes it clear that you are working with truth values.
According to the rule for
avoiding literals in operand positions, you should not just work with the literals
'X' and '
'. State queries about the predicates
IS INITIAL and IS
NOT INITIAL and the use of the constant
space are also not advisable,
because they require knowledge of the technical values of
abap_false, which do not play any role in the sense of real boolean data objects.
The type group
abap contains a third constant for the type
abap_undefined. However, implementing a three-value logic is only
useful and recommended in exceptional cases. In this case, note that
does not contain the initial value for a variable of type
initial value is always the value of
abap_false. However, the value of
abap_undefined can, if required, be specified using the addition
VALUE when declaring a truth value as the start value.
The following source code shows an unsuitable emulation of the boolean data objects not present in ABAP.
DATA is_found TYPE c LENGTH 1.
is_found = 'X'.
IF is_found IS NOT INITIAL.
The following source code shows the recommended emulation of the boolean data objects not present in ABAP.
DATA is_found TYPE abap_bool.
is_found = abap_true.
IF is_found = abap_true.