### Operators

This section lists the operators supported in sanScript. Examples show how each operator is used in the different types of expressions.

Operator

Description

Example

unary minus (-)

In numeric expressions, the unary minus operator (-) indicates a negative value.

neg_val = –10;

In numeric expressions, the result is the sum of the two values.

total = subtotal + 5;

In string expressions, the result is the concatenation of the first and second strings.

name = "Steve " + "Jones";

In date expressions, a numeric quantity may be added to a date to form a new date. The numeric value is treated as a number of days.

due_date = sysdate() + 30;

In time expression, a numeric quantity may be added to a time value to form a new time value. The numeric value is treated as a number of minutes.

next_hour = systime() + 60;

subtraction (-)

In numeric expressions, the result is the difference of the two values.

total = price - discount;

In date expressions, a numeric quantity may be subtracted from a date value to form a new date value. The numeric value is treated as a number of days.;

yesterday = sysdate() – 1;

Two date values can be subtracted to find the difference between them in days.

days_to_pay = due_date - sysdate();

In time expressions, a numeric quantity may be subtracted from a time value. The numeric value is treated as a number of minutes.

start_time = systime() – 30;

Two time values can be subtracted to find the difference between them in minutes.

elapsed_time = start_time – end_time;

multiplication (*)

The multiplication operator (*) is used in numeric expressions. The result is the product of the two numbers.

total = number_of_periods * contribution;

division (/)

The division operator (/) is used in numeric expressions. The result is the quotient of the two numbers.

check_total = salary / number_of_pay_periods;

modulus (%)

The modulus operator (%) is used in numeric expressions. The result is the remainder of the division of the first number by the second number (for example, 71 % 10 = 1).

single_items = items_ordered % items_per_box;

power (^)

The power operator is used in numeric expressions. The result is the first operand raised to the power of the second operand. Only powers of 10 may be calculated.

number = 10 ^ 5;

<< or shiftl

The shift left operator is used with numeric expressions. The result is the supplied integral value with its bits shifted to the left a specified number of positions. Zeros are shifted into the value.

result = 16 << 2;

result = 8 shiftl 3;

>> or shiftr

The shift right operator is used with numeric expressions. The result is the supplied integral value with its bits shifted to the right a specified number of positions. Zeros are shifted into the value.

result = 16 >> 2;

result = 256 shiftr 3;

equality (=)

The equality operator is supported in numeric, boolean, string, date and time expressions. In all expressions the result is true if the two operands are equal, and false if they are not equal.

if total = 100 then
result = true;

end if;

inequality (<>)

The inequality operator is supported in numeric, boolean, string, date and time expressions. In all expressions the result is false if the two operands are equal, and true if they are not equal.

abort script;

end if;

less than (<)

The less than operator is supported in numeric, string, date and time expressions. In all expressions the result is true if the first operand is less than the second operand, and false if it is not.

if total < 100 then
warning "Total is not 100%";

end if;

greater than (>)

The greater than operator is supported in numeric, string, date and time expressions. In all expressions the result is true if the first operand is greater than the second operand, and false if it is not.

if current_date > sysdate() then
warning "Date is not valid.";

end if;

less than or equal to (<=)

The less than or equal to operator is supported in numeric, string, date and time expressions. In all expressions the result is true if the first operand is less than or equal to the second operand, and false if it is not.

if systime() <= posting_time then
warning "Posting can't begin.";

end if;

greater than or equal to (>=)

The greater than or equal operator is supported in numeric, string, date and time expressions. In all expressions the result is true if the first operand is greater than or equal to the second operand, and false if it is not.

if total >= 100 then
discount = 10;

else
discount = 0;

end if;

and

In boolean expressions, the result is true if both of the operands are true, and false if either of the operands is false.

if (count > 100) and (total > 0) then
set discount to 15;

end if;

In numeric expressions, the and operator performs a logical and operation of the corresponding bits of two integral values and returns the result.

result = status and 16;

or

In boolean expressions, the result is true if either of the operands is true, and false if both of the operands are false.

if (count > 100) or (total > 100) then
discount = 20;

end if;

In numeric expressions, the or operator performs a logical or operation of the corresponding bits of two integral values and returns the result.

result = status or 255;

xor

In boolean expressions, the result is true if either of the operands is true, and false if both of the operands are true or both operands are false.

if printer xor screen then
run report 'Customer List';

end if;

In numeric expressions, the xor operator performs an exclusive or operation of the corresponding bits of two integral values and returns the result.

result = status xor 255;

not

In boolean expressions the not operator is used to complement (reverse) the value of a boolean expression.

if not enabled, then
warning "Printing not enabled.";

end if;

In numeric expressions, it performs a logical not operation on each bit of an integral value and returns the result.

result = not status;

implication or conditional (imp)

In boolean expressions, the implication operator examines the first operand. If it is true, the value of the second operand is returned; otherwise, the value true is returned.

result = a imp b;