Boolean

From Abap2Java

Jump to: navigation, search

ABAP

ABAP has no built-in boolean data type. Typically, Character Strings with the length 1 are used. Often one of the Data Elements BOOLEAN, BOOLE_D, XFELD or CHAR1 are used.
Typically, the character 'X' is interpreted as TRUE, while ' ' (or the keyword SPACE) is interpreted as FALSE. For these two values, many applications have defined constants, like myclass=>sc_true or myclass=>sc_false. Furthermore, also the constants abap_true or abap_false of the Type Pool ABAP can be used.

DATA b(1) TYPE C.
b = my_class->has_elements( ).
IF b = my_co_class=>sc_true.
  my_class->do_it( ).
ENDIF.

Java

A boolean variable can either be true or false. Use logical operator to calculate with boolean values. Comparision of boolean values can be done with == or !=.

boolean b = true;
boolean c = false;
boolean d = b && c;

b = myObj.hasElements( );

if (b) { //not possible in ABAP
 myObj.do_it( );
}

There is also a Object representing boolean values. Be reminded that Java is case sensitive. Boolean is the object wheras boolean is the primitive data type. The object representation is needed when inserting a value into a Collection like a Vector.

Boolean b = new Boolean(true);

Vector v = new Vector();
v.add(b);

boolean b1 = b.booleanValue();
  
if (b.equals(Boolean.TRUE)) {
   ...
}

See also:

Data type, Logical operator, Boolean Operator, Fast Assignment

Personal tools