简体   繁体   English

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

[英]How to use ABAP boolean in IF condition?

I know abap has no real boolean type.我知道 abap 没有真正的布尔类型。 Instead 'X' and ' ' is used.而是使用了 'X' 和 ' '。 Up to this time I always used an if-statement that way:到目前为止,我总是这样使用 if 语句:

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.我在 Netweaver 7.4 上。 Can I use this without problems?我可以毫无问题地使用它吗? It's like my lovely C# writing :p.这就像我可爱的 ​​C# 写作:p。

This is called a predicative method call :这称为谓词方法调用

A predicative method call is a relational expression whose only operand is a functional method call meth( ... ).谓词方法调用是一个关系表达式,其唯一的操作数是函数方法调用 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 .这是在 7.40 SP08引入的 Be aware that this only works reliably if the initial value is false and false is the initial value.请注意,这仅在初始值为 false 且初始值为 false 时可靠地工作。 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...例如,IS-H 使用一个字符字段,其中0为假, 1为真——但由于字符字段的初始值是一个空格,这既不是真也不是假,因此使用任何返回该值的方法将始终分支为如果该方法返回true...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM