ASSERT

ASSERT( condition [ , message ] [ , FAIL ] [ , CONST ])

ASSERT( recset, condition [ , message ] [ , FAIL ] [ , CONST ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

ASSERT( recset, assertlist [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

conditionThe logical expression that should be always be true.
messageOptional. The error to display in the workunit. If omitted, a message is generated from the approximate location in the code and the condition being checked.
FAILOptional. Specifies an exception is generated, immediately terminating the workunit.
CONSTOptional. Specifies the condition is evaluated during code generation.
recsetThe set of records for which to check the condition against each record.
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.
assertlistA comma-delimited list of ASSERTs of the first form, used to check multiple conditions against each record in the recset.

The ASSERT action evaluates the condition, and if false, posts the message in the workunit. The workunit terminates immediately if the FAIL option is present.

Form one is the scalar form, evaluating the condition once. Form two evaluates the condition once for each record in the recset. Form three is a variant of form two that nests multiple form one ASSERTs so that each condition is checked against each record in the recset.

Example:

val1 := 1;
val2 := 1;
val3 := 2;
val4 := 2 : STORED('val4');
ASSERT(val1 = val2);
ASSERT(val1 = val2, 'Abc1');
ASSERT(val1 = val3);
ASSERT(val1 = val3, 'Abc2');
ASSERT(val1 = val4);
ASSERT(val1 = val4, 'Abc3');
ds := DATASET([1,2],{INTEGER val1}) : GLOBAL;
 // global stops advanced constant folding (if ever done)
ds1 := ASSERT(ds, val1 = val2);
ds2 := ASSERT(ds1, val1 = val2, 'Abc4');
ds3 := ASSERT(ds2, val1 = val3);
ds4 := ASSERT(ds3, val1 = val3, 'Abc5');
ds5 := ASSERT(ds4, val1 = val4);
ds6 := ASSERT(ds5, val1 = val4, 'Abc6');
OUTPUT(ds6);
ds7 := ASSERT(ds(val1 != 99),
    ASSERT(val1 = val2),
    ASSERT(val1 = val2, 'Abc7'),
    ASSERT(val1 = val3),
    ASSERT(val1 = val3, 'Abc8'),
    ASSERT(val1 = val4),
    ASSERT(val1 = val4, 'Abc9'));
OUTPUT(ds7);
rec := RECORD
  INTEGER val1;
  STRING text;
END;
rec t(ds l) := TRANSFORM
  ASSERT(l.val1 <= 3);
  SELF.text := CASE(l.val1,1=>'One',2=>'Two',3=>'Three','Zero');
  SELF := l;
END;
OUTPUT(PROJECT(ds, t(LEFT)));

See Also: FAIL, ERROR