Skip to main content

EVALUATE

EVALUATE action

[attrname := ] EVALUATE(expression) ;

[attrname := ] EVALUATE(module [, defname ] ) ;

attrnameOptional. The action name, which turns the action into a definition, therefore not executed until the attrname is used as an action.
expressionThe function to call in an action context.
moduleThe module to evaluate.
defnameOptional. The name of a specific definition within the module to evaluate. If omitted, all definitions in the module are evaluated.

The first form of the EVALUATE action names an expression (typically a function call) to execute in an action context. This is mainly useful for calling functions that have side-effects, where you don't care about the return value.

The second form of the EVALUATE action recursively expands the exported definitions of the module and evaluates them. If a defname is specified, then only that definition is evaluated.

Example:

Form 1 example:

myService := SERVICE
  UNSIGNED4 doSomething(STRING text);
END;

ds := DATASET('MyFile', {STRING20 text} , THOR);

APPLY(ds, EVALUATE(doSomething(ds.text)));
 //calls the doSomething function once for each record in the ds
 // dataset, ignoring the returned values from the function

Form 2 example:

M := MODULE
  EXPORT a := 10;
  EXPORT b := OUTPUT('Hello');
END;
 
M2 := MODULE
  EXPORT mx := M;
  EXPORT d := OUTPUT('Richard');
END;
 
EVALUATE(M2); 
//produces three results:
//  Result_1: 10
//  Result_2: Hello
//  Result_3: Richard

See Also: APPLY, SERVICE Structure,

EVALUATE function

EVALUATE(onerecord, value)

onerecordA record set consisting of a single record.
valueThe value to return. This may be any expression yielding a value.
Return:EVALUATE returns a single value.

The EVALUATE function returns the value evaluated in the context of the onerecord set (which must be a single record, only). This function typically uses indexing to select a single record for the onerecord recordset. The usage is to return a value from a specific child record when operating at the parent record's scope level. The advantage that EVALUATE has over using recordset indexing into a single field is that the value returned can be any expression and not just a single field from the child dataset.

Accessing Field-level Data in a Specific Record

To access field level data in a specific record, the recordset indexing capability must be used to select a single record. The SORT function and recordset filters are useful in selecting and ordering the recordset so that the appropriate record can be selected.

Example:

WorstCard := SORT(Cards,Std.Scoring);
MyValue   := EVALUATE(WorstCard[1],Std.Utilization);
 // WorstCard[1] uses indexing to get the first record
 // in the sort order, then evaluates that record
 // returning the Std.Utilization value

ValidBalTrades := trades(ValidMoney(trades.trd_bal));
HighestBals := SORT(ValidBalTrades,-trades.trd_bal);
Highest_HC := EVALUATE(HighestBals[1],trades.trd_hc);
 //return trd_hc field of the trade with the highest balance
 // could also be coded as (using indexing):
 // Highest_HC := HighestBals[1].trades.trd_hc;

OUTPUT(Person,{per_last_name,per_first_name,Highest_HC});
 //output that Highest_HC for each person
 //This output operates at the scope of the Person record
 // EVALUATE is needed to get the value from a Trades record
 // because Trades is a Child of Person

IsValidInd := trades.trd_ind_code IN ['FM','RE'];
IsMortgage := IsValidInd OR trades.trd_rate = 'G';
SortedTrades := SORT(trades(ValidDate(trades.trd_dopn),isMortgage),
      trades.trd_dopn_mos);
CurrentRate := MAP(~EXISTS(SortedTrades) => ' ',
                   EVALUATE(SortedTrades[1], trades.trd_rate));

OUTPUT(person,{CurrentRate});

See Also: SORT