EVALUATE

Function

Determines the value of a column, literal, or variable and takes action based on that value.

Syntax

EVALUATE {any_lit|_var|_col}

This command is equivalent to case/switch in C or Java. The general format of EVALUATE is:

EVALUATE {any_lit|_var|_col}
WHEN comparison_operator {any_lit|_var|_col}
SQR_Commands...
[BREAK]
[WHEN comparison_operator {any_lit|_var|_col}
SQR_Commands...
[BREAK]]
[WHEN-OTHER SQR_Commands...
[BREAK]]
END-EVALUATE

Arguments

any_lit|_var|_col

A text or numeric column; a text, numeric, or date variable; or a text or numeric literal to use in the evaluation. In short, an evaluation argument.

comparison_operator

Any valid comparison operator. See comparison operators in Table 45, Operators.

WHEN

Evaluation expression. The evaluation argument is compared with the argument, beginning from the first WHEN. If the expression is TRUE, Production Reporting processes the commands after the WHEN. If the expression is FALSE, Production Reporting processes the next WHEN expression. Each WHEN must be on its own line.

If more than one WHEN expression appears directly before a set of commands, any one of them, if TRUE, causes the commands to execute.

BREAK

Immediately exits EVALUATE. Use BREAK at the end of a set of commands.

WHEN-OTHER

Signifies the start of default commands to process if all other WHEN expressions are FALSE. WHEN-OTHER must appear after all other WHEN expressions.

Description

EVALUATE is useful for branching to different commands depending on the value of a specified variable or column.

EVALUATE commands can be nested.

Evaluating a date variable or column with a string results in a date comparison (chronological, not a byte by byte comparison as is done for strings). The string must be in the proper format as follows:

Examples

evaluate &code
  when = 'A'
     move 1 to #j
     break
  when = 'B'
  when = 'C'
     move 2 to #j ! Will happen if &code is B or C.
     break
  when > 'D'
     move 3 to #j ! Move 3 to #j and continue checking.
  when > 'H'
     add 1 to #j  ! Add 1 to #j and continue checking.
  when > 'W'
     add 2 to #j
     break
  when-other
     if isnull (&code)
         do null_code
     else
         move 0 to #j  ! Unknown code.
     end-if
     break
end-evaluate 

See Also

IF and LET