Conversion of WHERE Condition to SELECT-OPTIONS

SELECT-OPTIONS describe a subset of the set of formulas expressible as WHERE conditions. The following table shows the structure of a SELECT-OPTIONS range-table:

SELNAME KIND SIGN OPTION LOW HIGH
col1 S I1,1    
         
col1 S I1,k    
col1 S E1,1    
         
col1 S E1,m    
         
coln S In,1    
         
coln S In,np    
coln S En,1    
         
coln S En,nq    

Whereby the columns have the following meaning:

The following formula is logically equivalent to the above-mentioned range-table:

→ (I1,1 ∨ … ∨ I1,k) ∧ ¬ (E1,1 ∨ … ∨ E1,n) ∧ … ∧ (In,1 ∨ … ∨ In,NP) ∧ ¬ (En,1 ∨ … ∨ En,NQ)

Where:

  1. ∀ i, j, k: Ii,j and Ii,k are predicates using the same column!
  2. ∀ i, j, k, m, with i ≠ j: Ii,k and Ij,m cannot be predicates using the same column!
  3. All predicates Ii,j and Ek,m are of the form <column> <logical-operator> <constant>!

This can be transformed into the following (logically equivalent) formula in CNF (conjunctive normal form):

→ (I1,1 ∨ … ∨ I1,k) ∧ ¬ E1,1 ∧ … ∧ ¬ E1,n ∧ … ∧ (In,1 ∨ … ∨ In,NP) ∧ ¬ En,1 ∧ … ∧ ¬ En,NQ

Conversion of WHERE Condition to SELECT-OPTIONS (restricted form of CNF)

The following procedure describes the steps necessary to convert an arbitrary WHERE condition into a logically equivalent SELECT-OPTIONS range-table, where possible, or prove that this is not possible:

  1. Check that all I and E predicates are of the kind: <column> <logical-operator> <constant>
  2. Convert WHERE condition to CNF:
    1. Replace ⇒ and ≡ with ∧, ∨ and ¬:
      A ⇒ B → ¬ A ∨ B
      A ≡ B → (¬ A ∨ B) ∧ (¬ B ∨ A)
    2. Push negations inwards using:
      ¬(A ∧ B) → ¬A ∨ ¬B
      ¬(A ∨ B) → ¬A ∧ ¬B
      ¬¬A → A
    3. use distributivity laws for ∨ over ∧:
      A ∨ (B ∧ C) → (A ∨ B) ∧ (A ∨ C)
      (A ∧ B) ∨ C) → (A ∨ C) ∧ (B ∨ C)
    4. use commutativity:
      A ∧ B → B ∧ A
      A ∨ B → B ∨ A
  3. Check if resulting CNF has the form (†) with the additional above-mentioned restrictions. If yes, the conversion is possible and the formula in CNF can be (as easily can be seen) rewritten as SELECT-OPTIONS range-table. If not, the conversion is not possible and the WHERE condition can not be used in conjunction with queries against data sources using the BI SAP Query Connector.