Directive PeopleCode Functions and Constructs

PeopleCode pre-compile directives enable developers to select which portions of the code will be compiled based on the PeopleTools release. Developers can write separate blocks of code that are pertinent to different PeopleTools releases and encapsulate these portions in different if-then-else-style blocks. Then, the directive PeopleCode can be compiled in one of two ways:

Description

Use the #Else keyword to create an else clause in a #If block. See #If for more information.

Description

Use the #End-If keyword terminate a #If block. See #If for more information.

Syntax

#If directive_expression #Then
   statement_list
[#Else
   statement_list]
#End-If

Description

Use the #If construct to compile PeopleCode statements conditionally, depending on the evaluation of the directive conditional expression. Similar to regular If-Then-Else structures, the #Then and #Else clauses of an #If structure consist of arbitrary lists of statements. The #Else clause is optional and may be omitted. If the directive condition evaluates to True, all statements in the #Then clause are compiled; otherwise, all statements in the #Else clause are compiled.

Note: During compilation, the entire directive block that evaluates to False is treated as a PeopleCode comment. This PeopleCode comment has a special limit of 32,766 characters (unlike regular PeopleCode comments which are limited to 16,383 characters). If your PeopleCode program has a block that evaluates to False that is greater than 32,766 characters, you will be unable to save your program and will receive an error message.

Parameters

Field or Control

Definition

directive_expression

Specifies a directive function (for example, #ToolsRel) in a standard comparison that evaluates to a Boolean value.

To combine multiple directive expressions, use && (AND) or || (OR) as the Boolean operators.

Note: && and || cannot be used in parentheses.

Returns

None.

Example

Note: Unlike regular If structures, a semicolon separator is not required after an #End-If.

In the following example, the #If block is compiled for an version of PeopleTools greater than or equal to 8.54.00. The #Else block is compiled for any other versions of PeopleTools.

#If #ToolsRel >= "8.54" #Then
   ...
   MessageBox(0, "", 0, 0, "PeopleTools version 8.54 and above");
#Else
...
Messagebox(0, "" , 0 , 0, "PeopleTools version less than 8.54");
#End-If

In the following example, the #If block is compiled for specific patch levels: 8.54.01 and 8.54.02. The #Else block is compiled for any other versions of PeopleTools.

#If #ToolsRel >= "8.54.01" && #ToolsRel < "8.54.03" #Then 
   ...
#Else
...
#End-If

Description

Use the #Then keyword in a #If block. See #If for more information.

Syntax

#ToolsRel

Description

Use the #ToolsRel function to return a string value representing the current PeopleTools release in the following format:

PT_major_rel.PT_minor_rel.patch_level

Use the #ToolsRel function in a directive expression to compare the return value to a literal string. Similar to the value returned by the #ToolsRel function, this literal string must be specified in the following format:

PT_major_rel.PT_minor_rel[.patch_level]

When the literal string contains the optional patch level, the comparison is performed to the patch level in the directive expression. However, if the literal string does not specify the optional patch level, the comparison is performed to the release level in the directive expression. Therefore, because the comparison is performed to the release level only, the following directive expression evaluates to True when the current PeopleTools release is 8.54.00, 8.54.01, 8.54.02, and so on:

#ToolsRel = "8.54"

Considerations for Directive Expressions

Directive expressions are logical expressions evaluated before compile time. They are always provided between the #If and #Then directive keywords. Directive expressions use directive functions and regular PeopleCode comparison operators for evaluating the directive expressions.

Important! Directive functions can be used in conjunction with directives in directive expressions only. Using a directive function anywhere else will result in a compile time error.

Parameters

None.

Returns

A String value.