$condition

Return the result of evaluating a conditional expression.

$condition(Condition {, DataList})

Parameters

Parameters
Parameter Data Type Description
Condition String Any legal conditional ProcScript expression or compiled conditional expression; can be a string, or a field (or indirect reference to a field), a variable, or a function that evaluates to a string.
  • Only ProcScript allowed in the current component type can be used.
  • An operand in the expression cannot contain another expression. For example, an expression that includes $fieldendmod cannot be used in a report or service.
  • Any field referred to must be included in the field list for the component entity.
  • Variables included in Condition must be in scope.
DataList String List used to substitute variables (or fields) in the expression with data. This works just like the string substitution. Optional.

Return Values

$condition returns either TRUE or to FALSE after evaluating Condition.

If an error occurs, $procerror contains a negative value that identifies the exact error.

Values of $procerror Commonly Returned Following $condition and $expression
Value  Error constant Meaning
-1301 <UPROCERR_SYNTAX> Syntax error.
-1302 <UPROCERR_SERVICE> Function not allowed in service.
-1303 <UPROCERR_REPORT> Function not allowed in report.
-1304 <UPROCERR_UNKNOWN_CONTEXT> Function not allowed, unknown context.
-1305 <UPROCERR_EXPRESSION> Expression not allowed.
-1306 <UPROCERR_CONDITION> Condition not allowed.
-1307 <UPROCERR_EXTRACTION_EXPR> Extraction expression is a condition.
-1308 <UPROCERR_INDIRECTION> Indirection followed by brackets.
-1309 <UPROCERR_PARENTHESES> Operand followed by parentheses.
-1310 <UPROCERR_BRACKETS> Operand followed by square brackets.
-1311 <UPROCERR_UNRESOLVED_OPERAND> A field, parameter, or variable could not be found in current context.

Use

Allowed in all component types.

Description

$condition returns the Boolean result of evaluating the conditional expression Condition. The conditional expression is parsed at run time and evaluated as if it were a compiled conditional expression; in other words, the conditional expression is interpreted.

Optional Argument for $condition

The following example shows the use of the optional argument IdItemList for $condition.

$2="one=1;two=2;three=3"
$1=$condition("one+two+three=6", $2)

Compiling ProcScript at Runtime

The following example demonstrates the use of proccompile, $condition, and $expression. proccompile is used to check the entered business rules in the DO_DISCOUNT and DISCOUNT fields, $condition is used to evaluate DO_DISCOUNT, and $expression is used to return the result of DISCOUNT.

The field DO_DISCOUNT contains the condition for a discount and DISCOUNT contains the actual expression for the discount. At run time, values can be entered for both fields that will determine whether a discount should be given, and the actual amount of the discount.

For example, the following line should be entered in the field DO_DISCOUNT if a discount should be given when more then 100 articles are ordered (where the field AMOUNT contains the number of ordered articles):

AMOUNT>100

And the following line should be entered in the field DISCOUNT if the actual discount is 10 percent of the total cost of the articles (where the field PRICE contains the unit price of the ordered article):

0.1*AMOUNT*PRICE

The following ProcScript checks the entered business rules and executes them accordingly:

entry total_cost
variables
   numeric vDiscount
endvariables
; This ProcScript entry calculates total cost of ordered article including discount
; Check syntax of discount condition in field DO_DISCOUNT

proccompile/condition DO_DISCOUNT, "FIELDS=AMOUNT"
if ($procerror < 0)
   message/error "Incorrect syntax for discount condition (%%$procerror)"
   putmess $procerrorcontext
   return -1
endif

; Check discount condition
if ($condition($result)) ; Use compiled ProcScript in $result
; A discount should be given
; Check syntax of discount expression in field DISCOUNT
   proccompile/expression DISCOUNT, "FIELDS=AMOUNT!;PRICE"
   if ($procerror < 0)
      message/error "Incorrect syntax for discount expression (%%$procerror)"
      putmess $procerrorcontext
      return -1
   endif

; Execute discount
; Use compiled ProcScript in $result
   vDiscount = $expression($result)

; Or, use uncompiled expression
; vDiscount = $expression(DISCOUNT)
else
; No discount should be given
; Set discount to 0
   vDiscount = 0
endif
COST = AMOUNT * PRICE - vDiscount
return 0
end

Related Topics