Decision structures

Two decision structures are available for use in scripts.

If then...end if

The if then...end if statement is one of the structures you can use to make decisions. The if then...end if statement evaluates boolean expressions and, based on the results, executes a set of sanScript statements.

The following script uses an if then...end if statement to execute a set of statements based upon the value of the Purchase Amount field.

if 'Purchase Amount' > 'Credit Limit' then
	error "Credit limit exceeded. Can't process the transaction";
	'Transaction Complete' = false;
else
	'Transaction Complete' = true;
end if;

If the purchase amount is greater than the credit limit, an error message is displayed and the Transaction Complete field is set to false. Otherwise, the Transaction Complete field is set to true.

Case...end case

The other decision structure you can use in scripts is the case...end case statement. Like the if then...end if statement, this statement allows a series of statements to run on a conditional basis.

The following script uses the case...end case statement to o set the rebate amount to be paid to customers based upon their total purchases for the fiscal year.

case 'FY Total Purchases'
	in [-99999 to 999] 
	'Rebate Award Amount' = 0;
	in [1000 to 2999] 
	'Rebate Award Amount' = 15;
	in [3000 to 4999] 
	'Rebate Award Amount' = 25;
else
	'Rebate Award Amount' = 50;
end case;

The case...end case statement makes it easy to run sanScript statements based on ranges of values.


Documentation Feedback