# Operators

PeopleCode expressions can be modified and combined using math, string, comparison, and Boolean operators.

This section discusses:

• Math operators.

• Operations on dates and times.

• String concatenation.

• @ operator.

• Comparison operators.

• Boolean operators.

PeopleCode uses standard mathematical operators:

• +

• -

Subtract (or unary negative sign)

• *

Multiply

• /

Divide

• **

Exponential

Exponentiation occurs before multiplication and division; multiplication and division occur before addition and subtraction. Otherwise, math expressions are evaluated from left to right. You can use parentheses to force the order of operator precedence.

The minus sign can also, of course, be used as a negation operator, as in the following expressions:

``````-10
- &NUM
- Product(&PERCENT_CUT, .01, SALARY)
``````

You can add or subtract two date values or two time values, which provides a Number result. In the case of dates, the number represents the difference between the two dates in days. In the case of time, the number represents the difference in seconds. You can also add and subtract numbers to or from a time or date, which results in another date or time. Again, in the case of days, the number represents days, and in the case of time, the number represents seconds.

The following table summarizes these operations:

Operation

Result Type

Result Represents

Time + number of seconds

Time

Resulting time

Date + number of days

Date

Resulting date

Date - date

Number

Difference in days

Time - time

Number

Difference in seconds

Date + time

DateTime

Date and time combined

The string concatenation operator ( | ) is used to combine strings. For example, assuming &OPER_NICKNAME is “Dave”, the following statement sets &RETORT to “I can’t do that, Dave.”

``&RETORT = "I can't do that, " | &OPER_NICKNAME |  "."``

The concatenation operator automatically converts its operands to strings. This conversion makes it easy to write statements that display mixed data types. For example:

``````&DAYS_LEFT = &CHRISTMAS - %Date;
WinMessage("Today is " | %Date | ".  Only " | &DAYS_LEFT | " shopping days left!");
``````

The @ operator converts a string storing a definition reference into the definition. This is useful, for example, if you want to store definition references in the database as strings and retrieve them for use in PeopleCode; or if you want to obtain a definition reference in the form of a string from the operator using the Prompt function.

To take a simple example, if the record field EMPLID is currently equal to 8001, the following expression evaluates to 8001:

``@"EMPLID"``

The following example uses the @ operator to convert strings storing a record reference and a record field reference:

``````&STR1 = "RECORD.BUS_EXPENSE_PER";
&STR2 = "BUS_EXPENSE_DTL.EMPLID";
&STR3 = FetchValue(@(&STR1), CurrentRowNumber(1), @(&STR2), 1);
WinMessage(&STR3, 64);
``````

Note: String literals that reference definitions are not maintained by PeopleTools. If you store definition references as strings, then convert them with the @ operator in the code, this creates maintenance problems whenever definition names change.

The following function takes a rowset and a record, passed in from another program, and performs some processing. The GetRecord method does not take a variable for the record, however, you can dereference the record name using the @ symbol. Because the record name is never hard-coded as a string, if the record name changes, this code does not have to change.

``````Function Get_My_Row(&PASSED_ROWSET, &PASSED_RECORD)

For &ROWSET_ROW = 1 To &PASSED_ROWSET.RowCount
&UNDERLYINGREC = "RECORD." | &PASSED_ROWSET.DBRecordName;
&ROW_RECORD = &PASSED_ROWSET.GetRow(&ROWSET_ROW).GetRecord(@(&UNDERLYINGREC));

/* Do other processing */

End-For;

End-Function;
``````

Comparison operators compare two expressions of the same data type. The result of the comparison is a Boolean value. The following table summarizes these operators:

Operator

Meaning

=

Equal

!=

Not equal

<>

Not equal

<

Less than

<=

Less than or equal to

>

Greater than

>=

Greater than or equal to

You can precede any of the comparison operators with the word Not, for example:

• Not=

• Not<

• Not>=

Expressions formed with comparison operators form logical terms that can be combined using Boolean operators.

String comparisons are case-sensitive. You can use the Upper or Lower built-in functions to do a case-insensitive comparison.

The logical operators And, Or, and Not are used to combine Boolean expressions. The following table shows the results of combining two Boolean expressions with And and Or operators:

Expression 1

Operator

Expression 2

Result

False

And

False

False

False

And

True

False

True

And

True

True

False

Or

False

False

False

Or

True

True

True

Or

True

True

In complex logical expressions using the operations And, Or, and Not, Not takes the highest precedence, And is next, and Or is lowest. Use parentheses to override precedence. (Generally, it is a good idea to use parentheses in logical expressions anyway, because it makes them easier to decipher.) If used on the right side of an assignment statement, Boolean expressions must be enclosed in parentheses.

The following are examples of statements containing Boolean expressions:

``````If ((&HAS_FLEAS Or
&HAS_TICKS) And
SOAP_QTY <= MIN_SOAP_QTY) Then
SOAP_QTY = SOAP_QTY + OrderFleaSoap(SOAP_ORDER_QTY);
End-If;
``````

The Not operator negates Boolean expressions, changing a True value to False and a False value to True. The Not operator can also negate comparison operators.

There are several methodologies for negating a Boolean value. You can use the Not operator:

``````Local boolean &Flag;

&Flag = True;
&Flag = ( Not &Flag);
If Not &Flag Then
WinMessage("Flag = False");
End-If;``````

Alternatively, you can compare the Boolean value to False:

``````Local boolean &Flag;

&Flag = True;
&Flag = (&Flag = False);
If Not &Flag Then
WinMessage("Flag = False");
End-If;
``````