bdfs1m0l | Structured Programming Macros |
The overall processing sequence is as follows:
For example, the expression A AND B OR C is evaluated in Boolean logic as (A AND B) OR C.
To ensure that the expression is evaluated unambiguously, one of the following solutions is required:
A AND B ORIF C
C OR A AND B
For example, the test:
A and (B or C)
is coded as:
B OR C ANDIF A
to force two groups.
As a summary of the processing rules described previously, Table 6 and Table 7 show the steps that are used to evaluate an
expression based on whether the connector is AND, ANDIF, OR, or ORIF.
Table 6. Decision Table: Boolean Expression Evaluation for AND or ANDIF
Connected by AND or ANDIF? | Left Expression True? | Expression Followed by ORIF? | Result |
---|---|---|---|
Yes | Yes | Yes or No | Test the next conditional expression. |
Yes | No | Yes | Test the expression after the next ORIF. |
Yes | No | No | The whole conditional expression is FALSE. |
Table 7. Decision Table: Boolean Expression Evaluation for OR or ORIF
Connected by OR or ORIF? | Left Expression True? | Expression Followed by ANDIF? | Result |
---|---|---|---|
Yes | Yes | Yes | Test the expression after the next ANDIF. |
Yes | Yes | No | The whole conditional expression is TRUE. |
Yes | No | Yes or No | Test the next conditional expression. |
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 field called FLD contains 2 characters that can be either of the following:
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 field called FLD contains 3 characters. The first 2 characters must be KL and the third character can be either of the following:
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 8, 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 field called FLD contains 3 characters.
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 5). 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