Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Return boolean in condition method -> best practice?

schmelto
Active Participant
4,911

I wonder if this is best practice for returning a boolean variable for a given condition.

Here is an example program:

CLASS class DEFINITION.

PUBLIC SECTION.
    METHODS is_x
        IMPORTING
            string TYPE string
        RETURNING VALUE(is_x) TYPE abap_boolean.
ENDCLASS.

CLASS class IMPLEMENTATION.
  METHOD is_x.
    IF ( string = 'x' ).
        is_x = abap_true.
    ELSE.
        is_x = abap_false.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(class) = NEW class( ).
IF ( class->is_x( string = 'x' ) ).
    WRITE: 'Yes'.
ELSE.
    WRITE: 'No'.
ENDIF.
1 ACCEPTED SOLUTION
Read only

joltdx
Active Contributor
3,647

Hi!

Check the sections Use ABAP_BOOL for Booleans and Use XSDBOOL to set Boolean variables in the Clean ABAP guidelines...

2 REPLIES 2
Read only

joltdx
Active Contributor
3,648

Hi!

Check the sections Use ABAP_BOOL for Booleans and Use XSDBOOL to set Boolean variables in the Clean ABAP guidelines...

Read only

Sandra_Rossi
Active Contributor
3,647

You don't need parenthesis after IF (must be a java/C habit 😄 )

It's abap_bool, not abap_boolean.