Using real Boolean type in SAP ABAP

This approach is called a Predicative Method call. This will work if the initial value is false and false is the initial value for Boolean types in ABAP. Predicative method calls allow you to use method calls directly in logical expressions, making your code more concise and readable.

In SAP ABAP, the real Boolean type abap_bool was introduced to provide true Boolean functionality. Unlike character-based flags ('X' and ' '), Boolean types have clear true and false values with false being the initial value.

Using Boolean in Predicative Method Calls

When using real Boolean types, you can directly use method calls that return Boolean values in IF statements and other logical contexts ?

DATA: lv_result TYPE abap_bool.

" Direct use in IF statement
IF method_returning_boolean( ).
  " Execute when method returns true
ENDIF.

" Assignment and use
lv_result = method_returning_boolean( ).
IF lv_result = abap_true.
  " Execute when result is true
ENDIF.

Example

Here's a practical example showing how to implement and use Boolean methods ?

CLASS lcl_validator DEFINITION.
  PUBLIC SECTION.
    METHODS: is_valid_email 
              IMPORTING iv_email TYPE string
              RETURNING VALUE(rv_result) TYPE abap_bool.
ENDCLASS.

CLASS lcl_validator IMPLEMENTATION.
  METHOD is_valid_email.
    " Simple email validation logic
    IF iv_email CS '@' AND iv_email CS '.'.
      rv_result = abap_true.
    ELSE.
      rv_result = abap_false.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

" Usage with predicative method call
DATA: lo_validator TYPE REF TO lcl_validator,
      lv_email TYPE string VALUE 'user@example.com'.

CREATE OBJECT lo_validator.

" Direct use in IF statement (predicative method call)
IF lo_validator->is_valid_email( lv_email ).
  WRITE: 'Valid email address'.
ELSE.
  WRITE: 'Invalid email address'.
ENDIF.

For more detailed information about predicative method calls and additional examples, you can refer to the official SAP documentation:

SAP ABAP Documentation - Predicative Method Calls

Conclusion

Using real Boolean types with predicative method calls makes ABAP code more readable and follows modern programming practices. This approach eliminates the ambiguity of character-based flags and provides cleaner conditional logic.

Updated on: 2026-03-13T18:20:40+05:30

514 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements