Boolean

This keyword declares a boolean variable capable of encapsulating two possible values - in this case, TRUE (1) or FALSE (0).

Syntax

Local    Boolean NAME
Local    Boolean NAME(DIMENSIONS)
Variable Boolean NAME(DIMENSIONS)
Value    Boolean NAME(DIMENSIONS)
Const    Boolean NAME(DIMENSIONS)
  • NAME is the name of the declared variable.
  • DIMENSIONS can be:
    • A single numeric value DIM, which means that we have an array with an index range from 0 to DIM-1.
    • A range of numeric values INDEX1..INDEX2. The index varies between INDEX1 and INDEX2.
    • Several indexes or index ranges separated by a comma. For multiple dimension arrays, up to four dimensions are possible.

Several variable declarations can be done on the same line, separated by a comma.

Local declarations create the variables in the current local variable class that is not seen by nested or calling subprograms. The Call / Subprog and func / Funprog insulate the local variables as well as the calls of method by fmet.

Const, Variable, and Value declarations state the arguments sent by a Call, func, or fmet. With these syntaxes, the dimensions and the index ranges can be omitted wherever the parentheses are present. The dimension and index ranges are defined by the calling program.

Examples

Local Boolean BOOL : BOOL = TRUE

#A sub-program returning a True (1) value
Funprog RETURN_TRUE()
Local Boolean WT : WT = TRUE
END WT

#A sub-program returning a False (0) value
Funprog RETURN_FALSE()
Local Boolean WF : WF = FALSE
END WF

Operators

Boolean variables can be used to perform logical operations such as and, or, xor, and not.

and operator

Truth table

A B A and B
0 0 0
0 1 0
1 0 0
1 1 1

Example


Funprog AND_EXAMPLE(WA, WB)
Value Boolean WA
Value Boolean WB
End WA and WB

or operator

Truth table

A B A or B
0 0 0
0 1 1
1 0 1
1 1 1

Example

Funprog OR_EXAMPLE(WA, WB)
Value Boolean WA
Value Boolean WB
End WA or WB

xor operator

Truth table

A B A xor B
0 0 0
0 1 1
1 0 1
1 1 0

Example

Funprog XOR_EXAMPLE(WA,WB)
Value Boolean WA
Value Boolean WB
End WA xor WB

not operator

It negates the original value of the boolean variable.

Example

Funprog NOT_EXAMPLE(WBOL)
Value Boolean WBOL
End not WBOL

Implicit data type conversion

The Boolean data type will implicitly convert Tinyint, Shortint, Integer, Double, Float, and Decimal data types to a boolean.

When Tinyint, Shortint, Integer, Double, Float, and Decimal data types are converted to a boolean:

  • Value zero (0) becomes FALSE.

  • A non-zero value becomes TRUE.

When a boolean is converted to Tinyint, Shortint, Integer, Double, Float, or Decimal data types:

  • FALSE becomes zero (0).

  • TRUE becomes one (1).

When the keywords TRUE and FALSE are assigned to Tinyint, Shortint, Integer, Double, Float, and Decimal data types:

  • FALSE becomes zero (0).

  • TRUE becomes one (1).

See also

Global, Local, Variable, Value, Const, Tinyint, Libelle, Date, Shortint, Integer, Float, Double, Decimal, Char, Clbfile, Blbfile, Uuident, Datetime, Instance.