Evaluate function

Syntax

Evaluate left_term
   When [relop_1] right_term_1
      [statement_list]
   .
   .
   .
   [When [relop_n] right_term_n
      [statement_list]]
   [When-Other
      [statement_list]]
End-Evaluate

Description

Use the Evaluate statement to check multiple conditions. It takes an expression, left_term, and compares it to compatible expressions (right_term) using the relational operators (relop) in a sequence of When clauses. If relop is omitted, then = is assumed. If the result of the comparison is True, it executes the statements in the When clause, then moves on to evaluate the comparison in the following When clause. It executes the statements in all of the When clauses for which the comparison evaluates to True. If and only if none of the When comparisons evaluates to True, it executes the statement in the When-other clause (if one is provided).

To end the Evaluate after the execution of a When clause, you can add a Break statement at the end of the clause.

Example

The following is an example of a When statement taken evaluates ACTION and performs various statements based on its value:

&PRIOR_STATUS = PriorEffdt(HIRE.EMPL_STATUS);
Evaluate HIRE.ACTION
When = "HIR"
   If %Mode = "A" Then
      Warning MsgGet(1000, 13, "You are hiring an employee and Action is not set to Hire.");
   End-If;
   Break;
When = "REH"
   If All(&PRIOR_STATUS) And
         Not (&PRIOR_STATUS = "T" Or
            &PRIOR_STATUS = "R") Then
      Error MsgGet(1000, 14, "Hire or Rehire action is valid only if employee status is Terminated or Retired.");
   End-If;
   Break;
When-Other
   /* default code */
End-Evaluate;

Considerations Using When Clause

Generally, you use the When clause without a semicolon at the end of the statement. However, in certain circumstances, this can cause an error. For example, the following PeopleCode produces an error because the PeopleCode compiler cannot separate the end of the When clause with the beginning of the next statement:

When = COMPONENT.GARBAGE
   (create BO_SEARCH:Runtime:BusinessContact_Contact(&fBusObjDescr, Null, &fDerivedBOID, &fDerivedBORole, &fBusObjDescr1, Null, &fContactBOID, &fContactRoleID, &fCustBOID, &fCustRoleID, "")).SearchItemSelected();
End-Evaluate;

If you place a semicolon after the When clause, the two expressions are read separately by the compiler:

 When = COMPONENT.GARBAGE;