Ansicht
Dokumentation

ABENBOOLE_FUNCTIONS - BOOLE FUNCTIONS

ABENBOOLE_FUNCTIONS - BOOLE FUNCTIONS

ABAP Short Reference   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

boolc, boolx, xsdbool, Boolean Functions

Variants:

1. ... boolc( log_exp ) ...

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

3. ... xsdbool( log_exp ) ...

Effect

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.

Note

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.

Variant 1

... boolc( log_exp ) ...


Effect

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.

Notes

  • If boolc requires return values other than "X" or " " (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.

Example

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

Example

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

Variant 2

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


Effect

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.

Note

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

The result of the following bit expression is hexadecimal 55, which corresponds to the calculated bit string 01010101.

The bit expression above can be expressed using the following iteration with the operator REDUCE.

Variant 3

... xsdbool( log_exp ) ...


Effect

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 " " of this type.

xsdbool can be specified in general and character-like expression positions.

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.

Example

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






CPI1466 during Backup   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.

Length: 10463 Date: 20240420 Time: 130259     sap01-206 ( 157 ms )