Logical Operators

Logical Data

Logical data is data that has been converted to a logical format for use in logical operations. There are three values that logical data can have: TRUE, FALSE, or NULL. Three types of data—numeric data, string data, and the null value—can function as logical data.

  1. Numeric Data
    The numeric value 0 (zero), is false; all other numeric values are true. The following are examples of the logical equivalent of numeric data:
    • 1 = TRUE
    • 25 = TRUE
    • 0 = FALSE
  2. String Data

    An empty character string is false; all other string data is true. The following are examples of the logical equivalent of string data:

    • "example" = TRUE
    • "var1" = TRUE
    • "" = FALSE
  3. Null Value

    The null value is neither true nor false. It represents data whose value is undefined.

Logical Operators

Logical operators perform tests on logical expressions. Logical expressions that evaluate to zero or an empty string are false. Logical expressions that evaluate to null are null. Expressions that evaluate to any other value are true.

There are three logical operators in InfoSphere® DataStage® BASIC:

  1. AND (or the equivalent &)
  2. OR (or the equivalent |)
  3. NOT

The operands of logical operators are considered to be logical data types. The following sections show the results of each operator in detail.

The AND operator

The following table displays how values for X and Y affect the value of the expression X AND Y. For example, the first row shows that if X is true and Y is true, then the value of X AND Y is true.

Table 1. The AND Operator
X Y X AND Y
TRUE TRUE TRUE
TRUE NULL NULL
TRUE FALSE FALSE
NULL TRUE NULL
NULL NULL NULL
NULL FALSE FALSE
FALSE TRUE FALSE
FALSE NULL FALSE
FALSE FALSE FALSE
The OR operator

The following table displays how values for X and Y affect the value of the expression X OR Y. For example, the third row shows that if X is true and Y is false, then the value of X OR Y is true.

Table 2. The OR Operator
X Y X OR Y
TRUE TRUE TRUE
TRUE NULL TRUE
TRUE FALSE TRUE
NULL TRUE TRUE
NULL NULL NULL
NULL FALSE NULL
FALSE TRUE TRUE
FALSE NULL NULL
FALSE FALSE FALSE
The NOT operator

The NOT operator is slightly different from the preceding operators since NOT effectively reverses the value of the expression, that is, it inverts the logical value. Since NULL is an unknown logical value, the inverse is also NULL.

  • NOT TRUE = FALSE
  • NOT NULL = NULL
  • NOT FALSE = TRUE
Order of operations

Arithmetic and relational operations take precedence over logical operations. InfoSphere DataStage logical operations are evaluated from left to right (i.e., AND statements do not take precedence over OR statements).