Perform logic by cases, such as a decision table.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.
Syntax: for Format 1
Standard evaluation procedure
EVALUATE identifier
WHEN valuexpression1
statementblock
[ .
.
.
WHEN valuexpressionN
statementblockN ]
[WHEN OTHER
statementblock ]
Syntax: for Format 2
Decision table.
EVALUATE identifier1[, ..., identifierN]
WHEN valuexpression1[, ..., valuexpressionN]
statementblock
[ .
.
.
WHEN valuexpressionN+1[, ..., valuexpressionN+N]
statementblock ]
[WHEN OTHER
statementblock ]
General Rules:
- For run time efficiency, AMB generates the GO TO ... DEPENDING ON translation with Format 1, if the code meets the following criteria.
- Each WHEN
valuexpression is a numeric literal.
- The literals increase in value from left to right, top to bottom.
- The largest (last) literal in the statement is less than four times as big as the number of WHEN clauses, not counting WHEN OTHER.
- If the above criteria are met and the evaluated field is not defined as numeric, a COBOL error occurs.
- Only the first WHEN condition met is executed.
- If a WHEN
condition is true and it does not include an optional statement block, program control passes to the next statement with the same or less indentation as the word EVALUATE.
- To prevent logic from falling through if no WHEN conditions are met, code WHEN OTHER.
- EVALUATE does not evaluate 88-levels, as the COBOL II EVALUATE statement does.
- If a COBOL II EVALUATE statement is also valid S-COBOL EVALUATE syntax, AMB processes it as S-COBOL statement.
- You can evaluate a maximum of 255 conditions/fields. You can code a maximum of 102 WHEN conditions.
- You can use EVALUATE to code the NEXT SENTENCE concept of passing program control out of a particular construct to the next executable statement.
Parameters:
identifier
|
Any COBOL identifier
|
value-xpression
|
In Format 1, a data name or a group of COBOL literals, identifiers, and arithmetic expressions forming
expression1,
expression2, . . ..
|
|
In Format 2, one of the following
ANY, or
expression1 [THRU
expression2]... OR
expression3[THRU
expression4]... [OR
expression5 [THRU
expression6]]
Symbols such as =, <, and > are not valid.
|
Example:
Create a mailing list that includes new subscribers (less than 1 year) and preferred subscribers (more than 5 years) broken down by region.
EVALUATE MONTHS, REGION
WHEN 1 THRU 11, 'EAST'
WRITE NEW-EAST-REC
WHEN 1 THRU 11, 'WEST'
WRITE NEW-WEST-REC
WHEN 61 THRU 9999, 'EAST'
WRITE PREFERRED-EAST-REC
WHEN 61 THRU 9999, 'WEST'
WRITE PREFERRED-WEST-REC