3
votes

I know abap has no real boolean type. Instead 'X' and ' ' is used. Up to this time I always used an if-statement that way:

IF myObj->is_sth( ) = abap_true.

ENDIF.

Now I did something like this:

IF myObj->is_sth( ).

ENDIF.

And I'm wondering that this seems to work. Return Type is boolean. I'm on Netweaver 7.4. Can I use this without problems? It's like my lovely C# writing :p.

1

1 Answers

5
votes

This is called a predicative method call:

A predicative method call is a relational expression whose only operand is a functional method call meth( ... ). The result of the relational expression is true if the result of the functional method call is not initial and false if the result of the functional method call is initial. The result of the functional method call (the return value of the called function method) can have any data type. A check is made on the type-friendly initial value.

A predicative method call, like any relational expression, can be a full logical expression or part of a logical expression. This means it can be specified as a condition in control statements and other statements, as an argument in Boolean functions or conditional expressions, or in joins with Boolean operators.

This was introduced in 7.40 SP08. Be aware that this only works reliably if the initial value is false and false is the initial value. For instance, IS-H uses a character field where 0 is false and 1 is true - but since the initial value of a character field is a space, that's neither true nor false, so using any method that returns this value will always branch as if the method had returned true...