Expressions

This section discusses:

  • Expression fundamentals.

  • Constants.

  • Functions as expressions.

  • System variables.

  • Metastrings.

  • Record field references.

  • Definition name references.

  • PeopleCode reserved words.

Expressions evaluate to values of PeopleCode data types. A simple PeopleCode expression can consist of a constant, a temporary variable, a system variable, a record field reference, or a function call. Simple expressions can be modified by unary operators (such as a negative sign or logical NOT), or combined into compound expressions using binary operators (such a plus sign or logical AND).

Definition name references evaluate to strings equal to the name of a PeopleTools definition, such as a record or page. They enable you to refer to definitions without using string literals, which are difficult to maintain.

Metastrings (also called meta-SQL) are special expressions used within SQL string literals. At runtime, the metastrings expand into the appropriate SQL for the current database platform.

PeopleCode supports numeric, string, and Boolean constants, as well as user-defined constants. It also supports the constant Null, which indicates an object reference that does not refer to a valid object.

Note: You can express Date, DateTime, and Time values by converting from String and Number constants using the Date, Date3, DateTime6, DateTimeValue, DateValue, Time3, TimePart, and the TimeValue functions. You can also format a DateTime value as text using FormatDateTime.

Numeric Constants

Numeric constants can be any decimal number. Some examples are:

  • 7

  • 0.8725

  • -172.0036

String Constants

String constants can be delimited by using either single (') or double (") quotation marks. If a quotation mark occurs as part of a string, the string can be surrounded by the other delimiter type. As an alternative, you can include the delimiter twice. Some examples are:

  • "This is a string constant."

  • 'So is this.'

  • 'She said, "This is a string constant."'

  • "She said, ""This is a string constant."""

Use the following code to include a literal quotation mark as part of your string:

&cDblQuote = '"'; /* singlequote doublequote singlequote */

The following also produces a string with two double quotation marks in it:

&cDblQuote = """"; /* dquote dquote dquote dquote */

You can also directly embed the doubled double quotation mark in strings, such as:

&sImage = Char(10) | '<IMG SRC="%IMAGE(' | &pImageName | ')"';

Strings must be contained on a single line. If you need to create a multi-line string, you must use concatenation to connect the lines to be a single sting. For example, one method to do this is:

&string = "Line 1" | Char(10) | "Line 2" | Char(10);

Boolean Constants

Boolean constants represent a truth value. The two possible values are True and False.

Null Constant

Null constants represent an object reference value that does not refer to a valid object. This means that calling a method on the object or trying to get or set a property of it fails. The Null constant is just the keyword Null.

User-Defined Constants

You can define constants at the start of a PeopleCode program. Then you can use the declared constant anywhere that the corresponding value would be allowed. Constants can be defined as numbers, strings, or Boolean values.

User-defined constants can only be declared as Local.

The following is an example of user-defined constant declarations:

Constant &Start_New_Instance = True; 
Constant &Display_Mode = 0; 
Constant &AddMode = "A": 
Local Field &Start_Date; 
. . . 
MyFunction(&Start_New_Instance, &Display_Mode, &Add_Mode);

You can use any function that returns a value as an expression. The function can be used on the right side of an assignment statement, passed as a parameter to another function, or combined with other expressions to form a compound expression.

System variables are preceded by a percent (%) symbol whenever they appear in a program. Use these variables to get the current date and time, or to get information about the user, the current language, the current record, page, or component, and more.

Metastrings are special SQL expressions. The metastrings, also called meta-SQL, are preceded with a percent (%) symbol, and can be included directly in string literals. They expand at runtime into an appropriate substring for the current database platform. Metastrings are used in or with:

  • SQLExec.

  • Scroll buffer functions (ScrollSelect and its relatives).

  • PeopleSoft Application Designer to construct dynamic views.

  • Some rowset object methods (Select, SelectNew, Fill, and so on).

  • SQL objects.

  • Application Engine.

  • Some record class methods (Insert, Update, and so on).

  • COBOL.

Use record field references to retrieve the value stored in a record field or to assign a value to a record field.

Record Field Reference Syntax

References to record fields have the following form:

[recordname.]fieldname

You must supply the recordname only if the record field and your PeopleCode program are in different record definitions.

For example, suppose that in a database for veterinarians you have two records, PET_OWNER and PET. A program in the record definition PET_OWNER must refer to the PET_BREED record field in the PET record definition as PET.PET_BREED.

However, a program in the PET record definition can refer to this same record field more directly as PET_BREED.

If the program is in the PET_BREED record field itself, it can refer to this record field using the caret (^) symbol.

The PeopleCode Editor replaces the caret symbol with the actual record field name.

You can also use object dot notation to refer to record fields, for example:

&FIELD = GetRecord(RECORD.PET_OWNER).GetField(FIELD.PET_BREED);

See Understanding Component Buffer Structure and Contents.

Legal Record Field Names

A record field name consists of two parts, the record name and the field name, separated by a period.

The field names used in PeopleCode are consistent with the field names allowed in the field definition. Case is ignored, although the PeopleCode Editor for the sake of convention, automatically formats field names in uppercase. A field name can be 1 to 18 characters, consisting of alphanumeric characters determined by your current language setting in Microsoft Windows, and characters #, @, $, and _.

A record name can be 1 to 15 characters, consisting of alphanumeric letters determined by your current language setting in Microsoft Windows, and characters #, @, $, and _.

Definition name references are special expressions that reference the name of a PeopleTools definition, such as a record, page, component, business interlink, and so on. Syntactically, a definition name reference consists of a reserved word indicating the type of definition, followed by a period, then the name of the PeopleTools definition. For example, the definition name reference RECORD.BUS_EXPENSE_PER refers to the definition name BUS_EXPENSE_PER.

Generally, definition name references are passed as parameters to functions. If you attempt to pass a string literal instead of a definition name reference to such a function, you receive a syntax error.

You also use definition name references outside function parameter lists, for example, in comparisons:

If (%Page = PAGE.SOMEPAGE) Then 
   /* do stuff specific to SOMEPAGE */ 
End-If;
 

In these cases, the definition name reference evaluates to a string literal. Using the definition name reference instead of a string literal enables PeopleTools to maintain the code if the definition name changes.

If you use the definition name reference, and the name of the definition changes, the change automatically ripples through the code, so you do not have to change it or maintain it.

In the PeopleCode Editor, if you place your cursor over any definition name reference and right-click, you can select View Definition to open the definition.

In addition, for most definitions, if you specify a definition that was not created in PeopleSoft Application Designer, you receive an error message when you try to save your program.

Legal and Illegal Definition Names

Legal definition names, as far as definition name references are concerned, consist of alphanumeric letters determined by your current language setting in Microsoft Windows, and the characters #, @, $, and _.

In some cases, however, the definition supports the use of other characters. You can, for example, have a menu item named A&M stored in the menu definition even though & is an illegal character in the definition name reference. The illegal character results in an error when you validate the syntax or attempt to save the PeopleCode.

You can avoid this problem in two ways:

  • Rename the definition so that it uses only legal characters.

  • Enclose the name of the definition in quotation marks in the reference, for example: ITEMNAME."A&M"

The second solution is a commonly used workaround in cases where the definition name contains illegal characters. If you use this notation, the definition name reference is not treated as a string literal: PeopleTools maintains the reference the same way as it does other definition name references.

Note: If your definition name begins with a number, you must enclose the name in quotation marks when you use it in a definition name reference. For example, CompIntfc."1_DISCPLIN_ACTN".

Reserved Word

Common Usage

AnalyticModel

Used with the GetAnalyticModel method.

BarName

Used with transfers and modal transfers.

BusActivity

Used with TriggerBusinessEvent.

BusEvent

Used with TriggerBusinessEvent.

BusProcess

Used with TriggerBusinessEvent.

CompIntfc

Used with Component Interface Classes.

Component

Used with transfers and modal transfers, as well as for generating URLs.

Field

Used with methods and functions to designate a field.

FileLayout

Used with the SetFileLayout File class method.

HTML

Used with the GetHTMLText function.

Image

Used in with functions and methods to designate an image.

Interlink

Used with the GetInterlink function.

ItemName

Used with transfers and modal transfers.

Market

Used with transfers and URL generation.

MenuName

Used with transfers and modal transfers.

Message

Used with Messaging functions and methods.

Node

Used with transfers and modal transfers, as well as generating URLs.

Operation

Used with the CreateMessage function.

Page

Used with transfers and modal transfers to pass the page item name (instead of the page name), and with controls and other functions to pass the page name.

Panel

Used with the deprecated TransferPanel function.

Note: Use the TransferPage function and the Page reserved word instead.

PanelGroup

Used with the deprecated DoModalPanelGroup function.

Note: Use the DoModalComponent function and the Component reserved word instead.

Portal

Used with transfers and modal transfers, as well as generating URLs.

Record

Used in functions and methods to designate a record.

Rowset

Used in functions and methods to designate a rowset.

RowsetCache

Scroll

The name of the scroll area in the page. This name is always equal to the primary record of the scroll.

SQL

Used with SQL definitions.

StyleSheet

Used with style sheets.

URL

Used with file attachment functions.