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

Boolean statement

Former Member
0 Likes
5,247

Hello,

I am wondering how do you write a boolean statment in ABAP. I tried to do something like this below:


bool = text1 IS initial OR text2 IS initial.

where text1 and text2 are text boxes in the selection screen.

And I ended up having error like this:

Incorrect arithmetic or bit expression: Instead of "IS", an operator (+, -, *, /, ... or BIT-AND, BIT-XOR, BIT-OR) was expected.

What is wrong with the statement above? Thanks!

Regards,

Anyi

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,533

Really there is no boolean in ABAP, it is just a TYPE C field with either an "X" or a SPACE. But you can write something like this.



report zrich_0001.

type-pools: abap.

constants: true type abap_bool value 'X'.
constants: false type abap_bool value ' '.

data:  value type c.


if value = true.

elseif value = false.

endif.


Regards,

Rich Heilman

5 REPLIES 5
Read only

Former Member
0 Likes
2,533

Hi

IF TEXT1 IS INITIAL OR
    TEXT2 IS INITIAL.
* Do something
ENDIF

Max

Read only

Former Member
0 Likes
2,533

Hullo,

IIRC there is no such thing as a boolean in ABAP.

However, you can solve this using an IF statement:

DATA: bool(1) TYPE c.

IF text1 IS INITIAL OR text2 IS INITIAL.
  bool = 'T'  .
ELSE.
  bool = 'F'.
ENDIF.

Where the values 'T' stands for true and 'F' stands for false. (Usually in ABAP the value for true is 'X' and ' ' for false though).

Hope this helps.

Read only

Former Member
0 Likes
2,533

if text1 is initial or

text2 is inital.

ensid

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,534

Really there is no boolean in ABAP, it is just a TYPE C field with either an "X" or a SPACE. But you can write something like this.



report zrich_0001.

type-pools: abap.

constants: true type abap_bool value 'X'.
constants: false type abap_bool value ' '.

data:  value type c.


if value = true.

elseif value = false.

endif.


Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,533

hi Anyi,

There is no boolean type defined in ABAP like any other language.

Boolean hold the value true or false - all those cases where you need to check you can use if else statement. ie

if (Condition1 is true)
 //code....111
else.
 //code...222
endif.

This is the way to handle the use of boolean in ABAP. Actually ABAP does not need boolean datatype.

Regards,

Richa.