Conditional Logic
Sterling Gentran:Server® uses conditional logic to test conditions and then, depending on the results of the test, perform different operations. Conditions can be nested to any level. Do not end conditions with a semicolon (;) – this terminating syntax is necessary for statements only.
if...then...else
You can use the if/then keywords to execute one or more statements conditionally. The condition is typically a comparison, but it can be any expression that concludes with a numeric value. Sterling Gentran:Server interprets the value as either true or false. The system interprets a zero value as false and a nonzero value as true.
If you include more than one statement in the body of an if/then loop, you must surround the statements with the begin/end keywords. If you only use a single statement, you can omit the begin and end.
Sterling Gentran:Server evaluates the if/then condition, and if it is true, the system executes all the statements that follow the then keyword. If the condition is false, none of the statements following then are executed.
You can use the else keyword in conjunction with if/then to define several blocks of statements, one of which is executed. Sterling Gentran:Server tests the first if/then condition. If the condition is false, the system proceeds to test each sequential condition until it finds one that is true. The system executes the corresponding block of statements for the true condition. If none of the if/then conditions are true, the system executes the statements following the else keyword.
Syntax
IF condition THEN
BEGIN
statement1;
statement2;
END
ELSE
BEGIN
statement3;
statement4;
ENDExample
An example of when you may use conditional logic is if you need to evaluate whether an N1 or NAD group contains billing or shipping information (this depends on the qualifier that a field in the group contains), and then map that information to the appropriate application fields.
For this example, you need to add an On End extended rule to the N1/NAD. The rule is executed when the group terminates. An example of the syntax of the rule follows:
IF #0098 = "BT" THEN
BEGIN
$Group_Name.#BILLTONAME = #0093;
$Group_Name. #BILLTOADDR1 = #0166;
$Group_Name.#BILLTOADDR2 = #0166:2;
$Group_Name.#BILLTOCITY = #0019;
$Group_Name.#BILLTOSTATE = #0156;
$Group_Name. #BILLTOPCODE = #0116;
END
IF #0098 = "ST" THEN
BEGIN
$Group_Name.#SHIPTONAME = #0093;
$Group_Name.#SHIPTOADDR1 = #0166;
$Group_Name.#SHIPTOADDR2 = #0166:2;
$Group_Name.#SHIPTOCITY = #0019;
$Group_Name.#SHIPTOSTATE = #0156;
$Group_Name.#SHIPTOPCODE = #0116;
END