Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Robust ABAP →  Data Types and Data Objects 

Data Objects for Logic Values

Other versions: 7.31 | 7.40 | 7.54


Logic values are results of logical expressions. A logic value is either true or false. ABAP does not yet support boolean data types and thus does not support data objects for logic values. Therefore, the result of a logical expression cannot be assigned directly to a data object.

It has become common practice to express the logic value "true" as value "X" and the logic 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 logic values expressed in this way, the type group abap contains a data type abap_bool of elementary type c with length 1, and the constants abap_true of value "X" and abap_false 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 Logic Values

When working explicitly with logic 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 relevant constants abap_true and abap_false (also abap_undefined).


Using the type abap_bool and the constants abap_true and abap_false makes it clear that logic values are being used here.

In accordance with the rule for avoiding literals in operand positions, not only the literals 'X' and ' ' should be used. State queries about the predicate operators IS INITIAL and IS NOT INITIAL or the use of the constant space are also not advisable, because they require knowledge of the technical values of abap_true and abap_false, which are not significant in the sense of real boolean data objects.

The type group abap contains a third constant for the type abap_bool, namely abap_undefined. However, implementing a three-value logic is only useful and recommended in exceptional cases. In this case, note that abap_undefined does not contain the initial value for a variable of type abap_bool. The 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 logic value as the start value.

Bad example

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'.

Good example

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.