SAP BOOLE FUNCTIONS



Get Example source ABAP code based on a different SAP table
  


• boolc ABAP_FUNCTION
• boolx ABAP_FUNCTION
• xsdbool ABAP_FUNCTION
• bool boolx function
• bit boolx function

boolc, boolx, xsdbool, Boolean Functions

ABAP_VARIANTS:
1 ... boolc( log_exp ) ...
2 ... boolx( bool = log_exp bit = bit ) ...
3 ... xsdbool( log_exp ) ...

What does it do?
The built-in Boolean functions determine the truth value of a logical expression log_exp specified as an argument. For log_exp, any logical expression can be specified in accordance with the applicable rules. The return value of a Boolean function has a data type dependent on the function and expresses the truth value of the logical expression with a value of this type.



Latest notes:

These functions can be considered a partial replacement for the Boolean data type for truth values that is not available in ABAP. In particular, xsdbool and, under certain circumstances, boolc can be used in many operand positions where values of the type abap_bool of the type pool ABAP are expected.
NON_V5_HINTS
ABAP_HINT_END

ABAP_VARIANT_1 ... boolc( log_exp ) ...

What does it do?
The function boolc returns a single-character character string of the type string. If the logical expression is true, X is returned. If the logical expression is false, a blank is returned. In principle, boolc is one of the processing functions with character-like results and can be specified in general expression positions and in character-like expression positions.



Latest notes:

If boolc requires return values other than X or blank (for example, Y and N or 1 and 0), the result of boolc can be processed directly using the function translate or another suitable processing function.
The result of boolc should not be compared with the constants abap_true and abap_false in relational expressions, since the latter converts from c to string and ignores any blanks. Comparisons of this type are not usually necessary. If a comparison of this type is to be executed anyway, the function xsdbool can be used instead of boolc whose result has the same ABAP type as abap_bool.
If the logical expression is false, the result of boolc does not meet the condition IS INITIAL, since a blank and no empty string is returned. If this is desired, the function xsdbool can be used instead of boolc.
If boolc is used in inappropriate places as specified in the points above, this leads to a syntax warning, which can be hidden using a pragma.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The value 0, 1, or 2 is assigned to the variable bool_value, depending on the result of the logical expressions log_exp1 and log_exp2. DATA bool_value TYPE i.

bool_value = strlen( condense( val = boolc( log_exp1 ) ) ) +
strlen( condense( val = boolc( log_exp2 ) ) ).
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX
Call of a method, where the input parameter no_dialog is supplied with the character-like representation of the results of a predicate expression.
ABEXA 00833
ABAP_EXAMPLE_END

ABAP_EXAMPLE_V5
Call of a method, where the input parameter no_dialog is supplied with the character-like representation of the results of a predicate expression.
ABEXA 01706
ABAP_EXAMPLE_END

ABAP_VARIANT_2 ... boolx( bool = log_exp bit = bit ) ...

What does it do?
The function boolx returns a byte chain of the type xstring . If the logical expression is true, the byte chain is filled as if the function bit-set( bit ) were executed. If the logical expression is false, the byte chain is filled as if the function bit-set( 0 ) were executed. bit expects a data object of the type i. In principle, boolx belongs to the bit functions and can be used in all positions where a bit expression is also allowed.



Latest notes:

The function boolx can be used for efficient storage of sequences of truth values.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The result of the following bit expression is hexadecimal 55, which corresponds to the calculated bit string 01010101.
ABEXA 00834
The bit expression above can be expressed using the following iteration with the operator REDUCE .
ABEXA 00835
ABAP_EXAMPLE_END

ABAP_VARIANT_3 ... xsdbool( log_exp ) ...

What does it do?
Like boolc, the function xsdbool returns the value X for true and a blank for false. The data type of the return value, however, has the type c of the length 1 here.
The return value references the type XSDBOOLEAN from the ABAP Dictionary. This type, which refers to the identically named domain of type CHAR and length 1, is handled like a real Boolean type in serializations and deserializations to or from asXML and asJSON using CALL TRANSFORMATION. The XML or JSON values true and false are assigned to the values X and blank of this type.
xsdbool can be specified in general and character-like expression positions.



Latest notes:

The result of xsdbool can be used like a value of the type abap_bool and can be compared with the constants abap_true and abap_false without any problems.
If the logical expression is false, the result of boolc fulfills the condition IS INITIAL, since the returned blank is the type-dependent initial value at the same time.
The result of xsdbool cannot usually be converted directly using a processing function such as translate, since the trailing blanks here are ignored in text fields of type c. The result of a false logical expression would be ignored. The result of the function boolc of type string is better suited for conversions of this type.
The abbreviation xsd stands for XML schema data types.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
This example sets the type and the value of the variable gui_flag declared inline using the Boolean function xsdbool for whose argument a predicative method call is listed. The variable is then serialized to asXML and asJSON using the predefined identity transformation ID. This produces the value true or false. After a comparison with the identically typed constant abap_false, the formatted result of the serialization is either read or displayed.
The result would be quite different if boolc were used instead of xsdbool. First, the transformations would have a different result since the values X and blank are not transformed to true or false; second, the logical expression gui_flag = abap_false would always be false, since abap_false loses its blank when converting to the type string.
ABEXA 00836
ABAP_EXAMPLE_END