如何在 IF 条件下使用 ABAP 布尔值?

How to use ABAP boolean in IF condition?

我知道 abap 没有真正的布尔类型。而是使用 'X' 和 ' '。到目前为止,我总是这样使用 if 语句:

IF myObj->is_sth( ) = abap_true.

ENDIF.

现在我做了这样的事情:

IF myObj->is_sth( ).

ENDIF.

而且我想知道这似乎有效。 Return 类型为布尔值。我在 Netweaver 7.4 上。我可以毫无问题地使用它吗?这就像我可爱的 ​​C# 写作 :p.

这叫做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.

这是 introduced in 7.40 SP08。请注意,这仅在初始值为 false 且 false 为初始值时才可靠地工作。例如,IS-H 使用字符字段,其中 0 为假且 1 为真 - 但由于字符字段的初始值是 space,因此既不是真也不是假,所以使用任何 returns 这个值的方法总是分支,就好像该方法返回了 true...