Boolean expression examples

The code that is required to check the format of an input field is a good example of where problems can occur in concatenating tests.
  • The following is an example of how to check a 2-character field.
    The field called FLD contains 2 characters that can be either of the following:
    • The characters KL
    • Two numeric characters.
    This implies the following:
    (FLD='K' AND FLD+1='L') OR (FLD>='0' AND FLD<='9' AND FLD+1>='0' AND FLD+1<='9')
    There are two groups, separated by the OR connector. The ORIF connector is used to separate groups, so the expression can be written as follows:
             #IF   FLD,EQ,C'K',AND,FLD+1,EQ,C'L',
             #     ORIF,FLD,GE,C'0',AND,LE,C'9',
             #     AND,FLD+1,GE,C'0',AND,LE,C'9'     Format of field correct
               :
    *   Code to process the field.
               :
             #ELSE                                   Format error
               :
    *   Code to process the illegal field.
               :
             #EIF
    
  • The following is an example of how to check a 3-character field.
    The field called FLD contains 3 characters. The first 2 characters must be KL and the third character can be either of the following:
    • The character M
    • A numeric character.
    This implies the following:
       FLD='K' AND FLD+1='L' AND (FLD+2='M' OR FLD+2>='0' AND FLD+2<='9')

    Again, there are two groups, separated by the AND connector. However, simply replacing the AND connector with the ANDIF connector does not work because of rule 4, which states that each ANDIF connector must be preceded by either an OR or an ORIF connector; otherwise, it has no grouping effect and functions as a normal AND connector.

    The ANDIF connector must be preceded by an OR connector so the sequence has to be reversed to allow the ANDIF connector to function. The conditional expression in condensed form is:
             #IF   FLD+2,EQ,C'M',OR,GE,C'0',AND,LE,C'9',
             #     ANDIF,FLD,EQ,C'K',AND,
             #     FLD+1,EQ,C'L'                     Format of field correct
               :
    *   Code to process the field.
               :
             #ELSE                                   Format error
               :
    *   Code to process the illegal field.
               :
             #EIF
    
  • The following is another example of checking a 3-character field.
    The field called FLD contains 3 characters.
    • The first character must be a K.
    • The second character can be an L or a U.
    • If the second character is a U, the third character must be either 0 or 1.
    This implies the following:
       FLD='K' AND (FLD+1='L' OR FLD+1='U' AND (FLD+2='0' OR FLD+2='1'))
    This expression uses double parentheses and, therefore, contains nested groups. The SPM evaluator does not support nested groups. However, the expression can be split into two groups by duplicating the first test.
       FLD='K' AND FLD+1='L' ORIF FLD='K' AND FLD+1='U' AND (FLD+2='0' OR FLD+2='1')
    This still leaves a parenthesis preceded by an AND connector, which cannot be split simply by replacing the AND connector with an ANDIF connector (see rule 1). The expression must be rearranged as follows:
             #IF  (FLD+2,EQ,C'0'),OR
             #    (FLD+2,EQ,C'1'),ANDIF
             #    (FLD+1,EQ,C'U'),ORIF,
             #    (FLD+1,EQ,C'L'),ANDIF,
             #    (FLD,EQ,C'K')                      Format of field correct
               :
    *   Code to process the field.
               :
             #ELSE                                   Format error
               :
    *   Code to process the illegal field.
               :
             #EIF