Meta-SQL

This section discusses:

Meta-SQL use.

Meta-SQL element types.

Meta-SQL Use

Meta-SQL expands to platform-specific SQL substrings, causes another function to be called, or substitutes a value. Meta-SQL
constructs are used in functions that pass SQL strings, such as the following:

SQLExec.

Scroll buffer functions (ScrollSelect and its relatives).

PeopleSoft Application Designer dynamic and SQL views.

Some Rowset class methods (Select, SelectNew, Fill, and so on.).

The SQL class.

PeopleSoft Application Engine programs.

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

COBOL functions.

Meta-SQL Element Types

There are three types of meta-SQL elements:

Construct.

Constructs are a direct substitution of a value, and help to build or modify a SQL statement.

Examples include %Bind, %InsertSelect, and %List.

Function.

Functions perform actions or cause another function to be called.

Examples include %ClearCursor, %Execute, and %ExecuteEdits.

Meta-variable.

Meta-variables enable substitution of text within SQL statements.

Examples include %AsOfDate, %Comma, and %JobInstance.

Parameter Markers

Parameter markers or bind variables are most commonly used in predicates, however some database platforms allow them in the
SELECT list. However, since this is not supported across all platforms, you should not code your SQL to use bind variables
in a SELECT list.

In addition, do not have bind variables as the operands of the same operator. This is not supported on all platforms. DB2/400
and DB2/OS390 cannot handle this type of operation.

Date Considerations

This section discusses:

Basic date meta-SQL guidelines.

Date, DateTime, or Time wrappers with Application Engine programs.

Date, DateTime, or Time wrappers for SQL and dynamic views.

{DateTimein-prefix} in Structured Query Language (SQR).

Basic Date Meta-SQL Guidelines

You can avoid confusion when using meta-SQL such as %Datein and %Dateout if you remember to use "in" functions in the Where
subclause of a SQL query and to use "out" functions in the Select (main) clause of the query. For example:

Date, DateTime, and Time Wrappers with Application Engine Programs

Use date or time wrappers (%Datein, %TimeOut, and so on) when selecting date or time columns into memory. Different database
platforms use different internal formats for these data types. Those different formats range from 1900-01-01 to 01-JAN-1900.
DateTime (timestamp) formats are even more complex.

In PeopleCode (SQLExecs and the like), use both an "out" wrapper when selecting a DateTime value into memory, as well as an
"in" wrapper when referencing the value as a bind variable.

In an Application Engine program, when you populate a DateTime state field in a %Select, you still must use an "out" wrapper
to get the value into the standard format. But when you reference this state field in a %Bind, Application Engine automatically
provides the "in" wrapper around the substituted literal or bind marker (the latter if reuse is in effect).

Actually, if you use the code %Bind(date) in the select list of another %Select statement, to load the value into another date field, Application Engine doesn't provide
a wrapper (since you are selecting a value that is already in the standard format, you don't need to use a wrapper).

Date, DateTime, and Time Out Wrappers for SQL and Dynamic Views

Dynamic views containing Date, Time, or DateTime fields must be wrapped with the appropriate meta-SQL. PeopleTools uses the
SQL directly from the view definition (view text) and doesn't generate anything, so no meta-SQL wrapping is done.

SQL views should not contain meta-SQL that wraps Date, Time, or DateTime fields.

{DateTimein-prefix} in SQR

In SQR, if you are using {DateTimein-prefix}, and so on, you need to do the following:

For string or let statements when using dynamic SQL, you need to use the following:

{DYN-Date***in/out-prefix/suffix}

For SQL statements, you need to use the regular SQL, as follows:

{Date*** in/out-prefix/suffix}

Meta-SQL Placement Considerations

Not all meta-SQL can be used by all programs. Some meta-SQL can be used only in Application Engine programs. Other meta-SQL
can only be used as part of a SQL statement in a SQL or dynamic view. The following table lists available meta-SQL elements
and where each element can be used.

If a meta-SQL construct, function, or meta-variable is supported in PeopleCode, it is supported in all types of PeopleCode
programs; that is, in Application Engine PeopleCode programs (actions), component interface PeopleCode programs, and so on.

Note. Even if a meta-SQL element is used in PeopelCode, you cannot use meta-SQL like a built-in function. You can use meta-SQL in
the SQLExec function, the Select method, the Fill method, and so on.

Note. Meta-SQL is not available in SQR.

Meta-SQL elements that are available for Application Engine only are described in PeopleSoft Application Engine documentation.

Meta-SQL Reference

This section discusses meta-SQL elements in alphabetical order.

Note. The parameter recname refers to a record name, not a table name. If you specify a table name (for example, PS_ST_OPTION_PARMS) you receive a SQL
error. Use the record name (for example, ST_OPTION_PARMS) instead. Also, do not use quotation marks around a record name.

%BINARYSORT

Syntax

%BINARYSORT(Recname)

Description

Any in-memory sorting performed using COBOL language functions is performed as a binary sort in the current character set
used for COBOL processing, and may not necessarily match the sort order returned by the database in response to an Order By
clause. Should you require the database to return data sorted using a binary sort of its encoding rather than the default
linguistically-correct sort, you must use the %BINARYSORT meta-SQL function around each column in the Where or Order By clause
where binary ordering is important.

However, for z/OS implementations, keep in mind that this binary sorting is only equivalent when the COBOL program is run
z/OS server. For example, the binary sort produced in COBOL differs from the binary sort produced by the database, as the
database is encoded in extended binary-coded decimal interchange code (EBCDIC) and the client is in an ASCII-based encoding.
Therefore, %BINARYSORT should only be used in COBOL programs that are not run using the RemoteCall function, where the z/OS
platform is not supported as a RemoteCall server.

When running against non-z/OS systems, %BINARYSORT can be used in both RemoteCall and non-RemoteCall programs.

Note. Using %BINARYSORT in Where and Order By clauses negates the use of any indexes, as most databases can't use indexes for functional
comparisons. (For example, WHERE %BINARYSORT(column) > 'X'). Use this syntax only when sorting equivalence of SQL statement results and COBOL memory order is required.

Parameters

Recname

Specify the record name to use with the sorting.

Example

SELECT RECNAME FROM PSRECDEFN WHERE %BINARYSORT(RECNAME) < %BINARYSORT('xxx')
SELECT RECNAME FROM PSRECDEFN ORDER BY %BINARYSORT(RECNAME)

%COALESCE

Use the %COALESCE function to return the first non-null argument provided to the function.

Note. This meta-SQL function is not implemented for COBOL.

Parameters

expr1. . .exprn

Specify the expressions to check.

Note. You cannot specify bind parameters using these expressions.

Example

The following example uses the PRODUCT_INFO table to organize a clearance sale of products. It gives a 10 percent discount
to all products with a list price. If there is no list price, the sale price is the minimum price. If there is no minimum
price, the sale price is 10.

%Concat

Syntax

string1 %Concat string2

Description

At runtime, the %Concat meta-SQL variable is replaced by the string concatenation operator appropriate for the relational
database management system (RDBMS) being used. For example, on DB2, the %Concat meta-SQL variable is replaced with CONCAT,
while on Sybase it's replaced with a +.

This meta-SQL variable is supported with the same limitations as the native concatenation operator for the RDBMS where the
meta-SQL is being executed. For example, some platforms enable you to concatenate a string with a numeric value; others flag
this as an error. PeopleTools makes no attempt to check or convert the data types of either of the operands.

Note. Concat is not available in COBOL, but the DYN-STMT-CONCAT field can be strung into dynamic COBOL strings to resolve into a
platform-specific concatenation operator.

%CurrentDateIn

Description

The %CurrentDateIn meta-SQL variable expands to a platform-specific SQL substring representing the current date in the Where
clause of a SQL Select or Update statement, or when the current date is passed in an Insert statement.

%CurrentDateOut

Description

The %CurrentDateOut meta-SQL variable expands to platform-specific SQL for the current date in the Select clause of an SQL
query.

%CurrentDateTimeIn

Description

The %CurrentDateTimeIn meta-SQL variable expands to a platform-specific SQL substring representing the current datetime in
the Where clause of a SQL Select or Update statement, or when the current date time is passed in an Insert statement.

%CurrentDateTimeOut

Description

The %CurrentDateTimeOut meta-SQL variable expands to platform-specific SQL for the current datetime in the Select clause
of a SQL query.

%CurrentTimeIn

Description

The %CurrentTimeIn meta-SQL variable expands to a platform-specific SQL substring representing the current time in the Where
clause of a SQL Select or Update statement, or when the current time is passed in an Insert statement.

%CurrentTimeOut

Description

The %CurrentTimeOut meta-SQL variable expands to platform-specific SQL for the current time in the Select clause of an SQL
query.

%DateAdd

Syntax

%DateAdd(date_from, add_days)

Description

The %DateAdd meta-SQL function returns a date by adding add_days to date_from. The add_days variable can be negative.

%DateIn

Syntax

%DateIn(dt)

Description

The %DateIn meta-SQL variable expands into platform-specific SQL syntax for the date. Use %DateIn whenever a date literal
or Date bind variable is used in a comparison in the Where clause of a Select or Update statement, or when a Date value is
passed in an Insert statement.

Restrictions Using COBOL

You can only use string literals when using this construct in COBOL. You cannot use it with bind parameters in COBOL. For
example, the following works in COBOL:

UPDATE PS_PERSONAL_DATA SET LASTUPDT = %DATEIN('2002-12-11')

The following SQL fails:

UPDATE PS_PERSONAL_DATA SET LASTUPDT = %DATEIN(:1)

Parameters

dt

Specify either a Date value or a date literal in YYYY-MM-DD format.

%DateNull

Syntax

%DateNull

Description

Use the %DateNull meta-SQL variable to specify a null value for a Date field. Only use this meta-SQL in Insert or Update clauses.
Do not use this meta-SQL in a Where clause.

Note. This meta-SQL variable is not implemented for COBOL.

This meta-SQL resolves into a database-specific SQL substring, as shown in the following table:

Database

Resolved Substring

Informix

empty string ('')

DB2

NULLIF(CURRENT DATE, CURRENT DATE)

All others

NULL

Parameters

None.

%DateOut

Syntax

%DateOut(dt)

Description

The %DateOut meta-SQL variable expands to a platform-specific SQL substring representing the date in the Select clause of
a SQL query.

Parameters

dt

Specify dt as a date column.

Note. You cannot specify a literal value for dt. Code such as %DateOut('1900-01-01') is not allowed.

%DatePart

Syntax

%DatePart(DTTM_Column)

Description

The %DatePart meta-SQL variable returns the date portion of the specified DateTime column.

Note. This meta-SQL variable is not implemented for COBOL.

Considerations using %DatePart

Use %DateOut meta-SQL when fetching values, as in the following example:

%DateOut(%DatePart(DTTM_COLUMN)) from some_table

If a literal is used as the parameter to %DatePart, it must be wrapped in %DateTimeIn:

%DateTimeDiff

The %DateTimeDiff meta-SQL function returns a time value, representing the difference between two datetimes in minutes.

Example

The following example returns the difference in hours between the current datetime and the requested datetime:

%DateTimeDiff(%CurrentDateIn, RQSTDTTM) < " | RECORD.FIELDNAME * 60;

The following example returns the difference in minutes:

%DateTimeDiff(%CurrentDateIn, RQSTDTTM) < " | RECORD.FIELDNAME;

%DateTimeIn

Syntax

%DateTimeIn(dtt)

Description

The %DateTimeIn meta-SQL variable expands to platform-specific SQL for a DateTime value in the Where clause of a SQL Select
or Update statement, or when a DateTime value is passed in an Insert statement.

Restrictions Using COBOL

You can only use string literals when using this construct in COBOL. You cannot use it with bind parameters in COBOL. For
example, the following works in COBOL:

%DateTimeOut

The %DateTimeOut meta-SQL variable expands to a platform-specific SQL substring representing a datetime column in the Select
clause of an SQL query.

Parameters

datetime_col

Specify a datetime column.

%DecDiv

Syntax

%DecDiv(a,b)

Description

The %DecDiv meta-SQL function returns a number representing the value of a divided by b, where a and b are numeric expressions.

If the result needs to be picked up by a bind variable, pick it up using the Character type or PIC X(50).

Parameters

a

Specify the number to be divided.

b

Specify the number to divide by.

Example

%DecDiv(1000.0, :1)

In the example, :1 is a bind variable in SQLExec PeopleCode.

%DecMult

Syntax

%DecMult(a,b)

Description

The %DecMult meta-SQL function returns a number representing a multiplied by b, where a and b are numeric expressions.

If the result needs to be picked up by a bind variable, pick it up using the Character type or PIC X(50).

Note. %DecMult is replaced with a simple multiplication function on all platforms except for the DB2 UDB for OS/390 and z/OS platform.
On this platform, it is converted to MULTIPLY_ALT. The MULTIPLY_ALT scalar function returns the product of the two arguments
as a decimal value. It is provided as an alternative to the multiplication operator, especially when the sum of the precisions
of the arguments exceeds 31.

Note. If you receive an overflow error using this meta-SQL, you may need to use the CAST function on the MSSQL, ORACLE, DB2UNIX
and DB2 UDB for OS/390 platforms, or the CONVERT function for SYBASE platforms, on your input first.

Parameters

a

Specify a number to be multiplied.

b

Specify a number to use for multiplying.

Example

%DecMult(12.3, 34.67)
%DecMult(c1 + c2, c3)

In the example, c1, c2, and c3 are fields of the Number data type.

%DTTM

Syntax

%DTTM(date, time)

Description

The %DTTM meta-SQL function combines the database date in the date value with the database time in the time value and returns a database timestamp value.

Note. This meta-SQL function is not implemented for COBOL.

Example

INSERT INTO TABLE1 (TIMESTAMP) SELECT %DTTM(DATE,TIME) FROM TABLE2

%EffDtCheck

The %EffDtCheck construct expands into an effective date subquery suitable for a Where clause. The value for as_of_date is automatically wrapped in %DateIn unless as_of_date is already wrapped in %DateIn or refers to other database columns.

Note. This meta-SQL construct is not implemented for COBOL.

%EffDtCheck only works with effective dates. It does not take effective sequence numbers (EFFSEQ) into account. It also does
not do effective-status (EFF_STATUS) checking.

Parameters

recordname

Specify the record name to use as the record in the effective-date checking. This can be a bind variable, a record object,
or a record name in the form recname. You cannot specify a RECORD.recname, a record name in quotation marks, or a table name.

Note. If you specify a bind variable, it should refer to a record object, not a string variable.

correlation_id1

(Optional) Specify the letter used inside the effective-dating subselect. If this parameter isn't specified, recordname is used.

correlation_id2

Specify the letter already assigned to the main record in the From clause of the SQL statement.

as_of_date

Specify the date to use in the effective date. This can be a bind variable, a variable, or a hard-coded date. The value for
as_of_date is automatically wrapped in %DateIn unless as_of_date is already wrapped in %DateIn or refers to other database columns.

%InsertSelect

The %InsertSelect meta-SQL construct generates an Insert statement with a Select statement. It does not generate a From statement.
You must specify the select records before you specify override fields.

Note. %InsertSelect has a limit of 99 override fields.

The Insert column list is composed of all the fields in the specified insert_recname, with the exception of LongChar or Image fields.

Note. Because of the way long values (LongChar and Image fields) are handled in the various database platforms for Insert statements,
all long values in insert_recname are skipped in the generated Insert statement. This implies that these fields should be defined in such a manner as to allow
null values.

The corresponding value in the Select list is generated based on the following precedence:

If the Insert fieldname appears as an override_field, the corresponding value is used in the Select list.

If the Insert field name matches a field name in one of the select_recname variables specified, the corresponding Select field is used in the Select list.

The search order of the select_recname records is the order that they are specified in the %InsertSelect function.

If the Insert field name has a constant default value defined in PeopleSoft Application Designer, that value is used in the
Select list.

A default value appropriate for the data type of the Insert field is used (blank for characters, zero for numbers, NULL for
Date, Time, and DateTime values, and so on.)

Use the optional override_field variable to specify values for a particular field.

Note. You cannot use bind variables with the override_field.

For each field you specify, the matching logic described in the preceding list is not performed. Instead, the value that you
specify after the equal sign is used for that field in the actual Select list. Use this technique to let PeopleTools or PeopleSoft
Application Engine handle most of the fields in the record, while specifying some of them explicitly. Also, you can use override_field to specify aggregate functions like Sum, Max, and so on.

Note. This meta-SQL is not implemented for COBOL.

Parameters

DISTINCT

Specify if the Select statement being generated should contain a Distinct clause.

insert_recname

Specify the name of record being inserted into. You must specify a record name, not RECORD.recname, a record name in quotation marks, a bind variable, or a table name.

Note. If the record for insert_recname is a temporary table, %InsertSelect automatically substitutes the corresponding table instance (PS_TARGETnn instead of PS_TARGET).

select_recname

Specify the name of record being selected from. You can specify more than one record. You must specify a record name, not
a RECORD.recname, a record name in quotation marks, or a table name.

correlation_id

Identify the correlation ID to be used for the select_recname records and fields.

override_field

Specify the name of a field on insert_recname that you want to supply a value for (instead of using the value supplied from the select_recname.)

Value

Specify the value that should be used for the override_field instead of the value from select_recname.

%InsertValues

The %InsertValues meta-SQL construct produces a comma-separated list of the record's non-null field values. Input processing
is applied to the fields in the following ways:

If the field is a Date, a Time, or a DateTime data type, its value is automatically wrapped in %Datein, %TimeIn, or %DateTimeIn,
respectively.

If the field is a string, its value is automatically wrapped in quotation marks.

If the field has a null value, it is not included in the list.

Note. This meta-SQL construct can only be used in PeopleCode programs, not in Application Engine SQL actions. Also, this meta-SQL
construct is not implemented for COBOL.

Parameters

recname

Specify the name of the record to be used for inserting. This can be a bind variable, a record object, or a record name in
the form recname. You can't specify a RECORD.recname, a record name in quotation marks, or a table name.

%Join

where override_field_list is an arbitrary-length list of fields to be substituted in the resulting text string, in the form:

field1 [, field2]. . .

Description

Use the %Join meta-SQL construct to dynamically build a Where clause joining one table to another. At runtime, the entire
construct is replaced with a character string.

Note. This meta-SQL construct is not implemented for COBOL. If date key fields are not marked as required in the record definition
for either of the referenced tables in the %Join clause, a Null clause check is added to the date field comparison. This additional
clause can have a significant impact on the execution time for the generated SQL statement.

Parameters

{COMMON_KEYS | COMMON_FIELDS}

Use COMMON_KEYS to specify that all common primary key fields are used in constructing a Where clause; use COMMON_FIELDS to
specify all common fields, not just key fields. You can select either COMMON_KEYS or COMMON_FIELDS.

join_recname

Specify the name of the record to be joined. This can be a bind variable, a record object, or a record name in the form recname. You can't specify a RECORD.recname, a record name in quotation marks, or a table name.

correlation_id1

Identify the correlation ID used to relate the record specified by join_recname and its fields.

to_recname

Specify the name of the record to be joined to. This can be a bind variable, a record object, or a record name in the form
recname. You can't specify a RECORD.recname, a record name in quotation marks, or a table name.

correlation_id2

Identify the correlation ID used to relate the record specified by to_recname and its fields.

override_field_list

Specify a list of fields that you do not want used in the join. For example, if fields A, B, and C were common to two records,
and you didn't want to join on C, list C as an override_field.

However, you don't want to perform the join using the DESCR field because it's a long field. Instead use override_field, as shown in the following code:

%Join(COMMON_FIELDS, PSAEAPPLDEFN ABC, PSAESECTDEFN XYZ, DESCR)

This example results in the following being generated:

ABC.AE_APPLID = XYZ.AE_APPLID

You can also specify a value for a field. Suppose you want to join two tables, but not on the field C3. In addition, you would
like to specify a value for C3. Your code could look like the following:

%Join(COMMON_FIELDS, MY_TABLE1 A, MY_TABLE2 B, C3) AND C3 = 'XX'

%KeyEqual

Syntax

%KeyEqual(recname [ correlation_id] )

Description

The %KeyEqual meta-SQL construct expands into a conditional phrase suitable for use in a Where clause.

The conditional phrase consists of a conjunction (AND) of [correlation_id.]keyfieldname = 'keyfieldvalue' phrases for each key field of the given record.

No auto-update processing is done, but other input processing is applied to the values, according to the following:

If the field is a Date, a Time, or a DateTime data type, its value is automatically wrapped in %Datein, %TimeIn, or %DateTimeIn,
respectively.

If a value is a string, its value is automatically wrapped in quotation marks.

If a value is NULL, the "=value" part is replaced with "IS NULL".

Note. This meta-SQL can only be used in PeopleCode programs, not in Application Engine PeopleCode actions. Also, this meta-SQL is
not implemented for COBOL.

Parameters

recname

Specify the name of the record to use for inserting. This can be a bind variable, a record object, or a record name in the
form recname. You cannot specify RECORD.recname, a record name in quotation marks, or a table name.

correlation_id

Identify the single-letter correlation ID to relate the record specified by recname and its fields.

Example

Suppose that the record &REC has three keys: FNUM, FDATE, and FSMART. Here is a code example:

"Delete from TABLE A
where A.FNUM = 27
AND A.FDATE = %Date('1989-11-27')
AND A.FSMART IS NULL"

%KeyEqualNoEffDt

Syntax

%KeyEqualNoEffDt(recname [ correlation_id] )

Description

The %KeyEqualNoEffDt meta-SQL construct expands into a conditional phrase suitable for use in a Where clause.

The conditional phrase consists of a conjunction (AND) of [correlation_id.]keyfieldname = 'keyfieldvalue' phrases for all key fields of the given record, except that it omits any key field named EFFDT.

No auto-update processing is done, but other input processing is applied to the values as follows:

If the field is a Date, a Time, or a DateTime data type, its value is automatically wrapped in %Datein, %TimeIn, or %DateTimeIn,
respectively.

If a value is a string, its value is automatically wrapped in quotation marks.

If a value is NULL, the "=value" part is replaced with "IS NULL."

Note. This meta-SQL can only be used in PeopleCode programs, not in Application Engine PeopleCode actions. Also, this meta-SQL is
not implemented for COBOL.

Parameters

recname

Specify the name of the record to be used for inserting. This can be a bind variable, a record object, or a record name in
the form recname. You can't specify RECORD.recname, a record name in quotation marks, or a table name.

correlation_id

Identify the single-letter correlation ID to relate the record specified by recname and its fields.

Example

The EMPL_CHECKLIST record has three keys: EMPLID, CHECK_SEQ, and EFFDT. Here is a code example:

%Like

The %Like construct expands to look for literal values. This meta-SQL should be used when looking for like values. A percent
sign character (%) is appended to literal.

Note. This meta-SQL is not implemented for COBOL.

If you're using a bind marker (such as ":1") for the literal argument in a SQLExec, you must wrap the SQL string with the
ExpandSqlBinds function. ExpandSqlBinds replaces bind markers with the actual input values.

%Like generates the following:

like 'literal%'

If the literal value contains a backslash character (\) or percent sign (%), then %Like generates the following:

Some platforms require that you use RTRIM to get the correct value. The following characters are wildcards even when preceded
with the backslash (\) escape character:

%

_

Therefore, on some platforms, the literal must end with a percent sign (%) wildcard that isn't preceded by a backslash (\).
Here are some examples:

literal = 'ABC%'

There is no need for RTRIM on any platform.

literal = 'ABC\%'

You need RTRIM on Microsoft SQL Server and DB2.

Using %Like and Trailing Blanks

Not all executions of %Like perform the same. When dealing with trailing blanks, some platforms behave as if there is an implicit
percent sign (%) at the end of the comparison string, while most don't.

In the following example, if the selected column contains the string "ABCD " (with three trailing blanks. The statement
may or may not return any rows:

select * from t1 Where c like 'ABCD'

Therefore, it is always important to explicitly code the percent sign (%) the end of matching strings for columns where you
want to include trailing blanks. The following table shows the use of implicit percent signs with specific databases:

Database

Includes Implicit Percent Sign (%)

PeopleSoft Standard Usage

Yes

DB2/400

No

DB2/MVS

No

DB2/Unix

No

Informix

No

Microsoft SQL Server

Yes

Oracle

No

SQLBase

No

Sybase

Yes

Using %Like and Wildcards

SQL specifies two wildcards that can be used when specifying pattern matching strings for use with the SQL Like predicate.
The underscore is used as a substitution for a single character within a string, and the percent sign represents any number
of character spaces within a string. All supported databases use these characters as wildcards.

Parameters

literal

Specify the value to search for.

%LikeExact

Syntax

%LikeExact(fieldname, "Literal")

Description

The %LikeExact meta-SQL variable expands to look for literal values. Use this variable when exact matches are necessary, taking
into account wildcards in the literal values.

Note. This meta-SQL is not implemented for COBOL.

%LikeExact generates one of the following:

If the literal contains no wildcards:

fieldname = 'literal'

If the literal ends with the '%' wildcard:

fieldname like 'literal' [escape '\']

Some platforms require that you use RTRIM to get the correct value. The following characters are wildcards even when preceded
with the backslash (\) escape character.

%

_

Therefore, on some platforms, the literal must end with a percent sign (%) wildcard that isn't preceded by a backslash (\).
Here are some examples:

literal = 'ABC%'

You do not need RTRIM on any platform.

literal = 'ABC\%'

You need RTRIM on Microsoft SQL Server and DB2.

Considerations Using Bind Markers

If you're using a bind marker (such as ":1") for the literal argument in a SQLExec, you must wrap the SQL string with ExpandSqlBinds.
ExpandSqlBinds replaces bind markers with the actual input values.

%NoUppercase

Syntax

%NoUppercase

Description

When processing a SQL statement, the system automatically casts all field names and possibly record names to uppercase when
processing a SQL statement. When processing records from a third party, fields that are lowercase are cast into uppercase,
which can create a runtime issue on case-sensitive platforms.

To prevent this, use the %NoUppercase meta-SQL statement at the beginning of the SQL statement.

Parameters

None.

Note there are not parameters, as well as no parenthesis, for this meta-SQL.

%NumToChar

Use the %NumToChar construct to transform a numeric value into a character value. Spaces are trimmed from Number.

Parameters

Number

Specify the number to convert to a character value. Signed numbers, as well as decimals, are acceptable.

%OldKeyEqual

Syntax

%OldKeyEqual(recname [correlation_id])

Description

The %OldKeyEqual meta-SQL construct is similar to the %KeyEqual construct, except that it uses the original values of the
record fields, rather than the current values. Since the rules for which values are original and which are current are not
very clear, especially for standalone record objects, avoid using this meta-SQL construct. You should use separate records
to hold previous values. This can make your code clearer and more maintainable.

Note. This meta-SQL construct can only be used in PeopleCode programs, not in Application Engine PeopleCode actions. Also, this
meta-SQL is not implemented for COBOL.

%OPRCLAUSE

The %OPRCLAUSE metavariable is used in the view text of dynamic views. In PeopleTools 6, the %OPRCLAUSE metavariable expanded
in the following manner:

SELECT EMPLID, ABSENCE_TYPE, oprid
FROM PS_ABSENCE_HIST
WHERE %OPRCLAUSE
SELECT EMPLID, ABSENCE_TYPE, OPRID FROM PS_ABSENCE_HIST WHERE ( OPRCLASS ='HRADMIN') AND (EMPLID='8001' AND ABSENCE_TYPE='CNF') ORDER BY EMPLID, ABSENCE_TYPE

In PeopleTools 7, to support the new concept of a specific row-level security class, this metavariable now fills in the Where
clause with the value from PSOPRDEFN.ROWSECCLASS.

%OPRCLAUSE must be either all uppercase or all lowercase.

%OPRCLAUSE translates to OprId or OprClass, following the same rules used for security on search dialog boxes. If OPRID is
in the view, %OPRCLAUSE expands to OPRID = 'current operator'. If OPCLASS is in the view, %OPRCLAUSE expands to OPCLASS =
'current class'.

Example

Here is an example:

SELECT EMPLID, ABSENCE_TYPE, OPRID FROM PS_ABSENCE_HIST WHERE %OPRCLAUSE AND (EMPLID='8001' AND ABSENCE_TYPE='CNF')

This code expands to:

SELECT EMPLID, ABSENCE_TYPE, OPRID FROM PS_ABSENCE_HIST WHERE ( OPRID = 'PTDMO') AND (EMPLID='8001' AND ABSENCE_TYPE='CNF')
ORDER BY EMPLID, ABSENCE_TYPE

Here's another example:

SELECT EMPLID, ABSENCE_TYPE, OPRCLASS FROM PS_ABSENCE_HIST WHERE %OPRCLAUSE AND (EMPLID='8001' AND ABSENCE_TYPE='CNF')

This code expands to:

SELECT EMPLID, ABSENCE_TYPE, OPRID FROM PS_ABSENCE_HIST WHERE ( OPRCLASS = 'ALLPANLS') AND (EMPLID='8001' AND ABSENCE_TYPE='CNF')
ORDER BY EMPLID, ABSENCE_TYPE

%Round

Syntax

%Round(expression, factor)

Description

%Round rounds an expression to a specified scale before or after the decimal point. If factor is a literal, it can be rounded to a negative number.

The following cases are illegal, and may cause incorrect results or runtime SQL errors:

%Round(10.337, 2 + 1) (factor can not be an expression)
%Round(field_c1, field_c2) (factor can not be database columns)

%SQL

Syntax

%SQL(SQLid [, paramlist])

where paramlist is a list of arguments that are used for dynamic substitutions at runtime, in the form:

arg1 [, arg2]. . .

Description

Use the %SQL construct for common SQL fragments that you have already defined and want to reuse, substituting additional values
dynamically. SQLid is the name of a SQL definition created using either PeopleSoft Application Designer or the StoreSQL function.

You can only nest up to 10 %SQL statements at a time.

Note. This meta-SQL construct is not implemented for COBOL. A SQL definition is not the same as the SQL object that is instantiated
from the SQL class at runtime. A SQL definition is created either using PeopleSoft Application Designer at design time, or
using the StoreSQL function. A SQL object is instantiated at runtime from the SQL class, and has methods and properties associated
with it like any other object.

When a specified SQL definition has more than one version, the database type always takes precedence.

If one or more versions of a SQL definition are found for the database type of the current database connection, and if any
of the versions have an effective date less than or equal to the value returned for %AsOfDate, the most recent version is
used.

If no versions are found for the current database type, or if all of the versions have effective dates greater than the value
returned for %AsOfDate, the system looks for an effective version of the SQL definition under the database type Generic.

Application Engine programs use the current date to compare with the effective date, not the date returned by %AsOfDate.

Special SQL Characters

The following meta-SQL meta-variables can be used as part of the %SQL construct to represent special characters as SQL parameters.

Meta-Variable

Description

%Comma

Represents a single comma.

%LeftParen

Allows you to pass a left parenthesis character to a %P() variable, without closing the SQL object.

%RightParen

Allows you to pass a right parenthesis character to a %P() variable, without closing the SQL object.

%Space

Represents a space.

Parameters

SQLid

Specify the name of an existing SQL definition.

paramlist

Specify a list of arguments for dynamic substitutions at runtime. The first argument replaces all occurrences of %P(1) in
the referenced SQL definition, the second argument replaces %P(2), and so forth. You can specify up to 99 arguments.

Note. For PeopleCode, the %P should not be contained in quotation marks. '%P(2)' is considered to be a literal, and so isn't replaced at runtime.

Example

In the following example, the SQL definition MY_SQL was created in PeopleSoft Application Designer to be the following:

%P(1).EFFDT = (SELECT MAX(EFFDT) FROM ...)

In the following example, the %SQL statement is dynamically generated:

UPDATE PS_TEMP
SET ...
WHERE ...
AND %SQL(MY_SQL, PS_TEMP)

The previous example resolves to the following:

UPDATE PS_TEMP
SET ...
WHERE ...
AND PS_TEMP.EFFDT = (SELECT MAX(EFFDT) FROM ...)

%Substring

Note. For the DB2 LUW (DB2/UDB) database, you must ensure that the source_str parameter doesn't resolve to an expression greater than 1000 characters.

Parameters

source_str

Specify the source string.

start

Specify the substring's beginning position. The first character of source_str is position 1.

length

Specify the length of the substring.

%SUBREC

Syntax

%SUBREC(subrec_name, corel_name)

Description

%SUBREC is used only in dynamic view SQL, where it expands to the columns of a subrecord. You can't use this statement in
SQLExec or any other SQL statement.

Note. %SUBREC must be either all uppercase or all lowercase.

Parameters

subrec_name

Specify the name of the subrecord.

corel_name

Specify the correlation name.

Example

Suppose you have a record definition AAA_VW that is a dynamic view, with fields CHR, SUB, and NUM. The field SUB is a subrecord
with fields CHR_SUB, NUM_SUB, and IMG_SUB. The view text for AAA_VW could be:

%Table

The %Table construct returns the SQL table name for the record specified with recname.

For example, %Table(ABSENCE_HIST) returns PS_ABSENCE_HIST.

Note. This meta-SQL is not implemented for COBOL.

If the record is a temporary table and the current process has a temporary table instance number assigned, %Table resolves
to that instance of the temporary table (that is, PS_ABSENCE_HISTInstance Number).

You can override this value with the instance parameter. For example, if you know you want the third instance of a temporary table, you could specify it with %Table(&MYREC, 3). You can use the SetTempTableInstance function to set the instance of a temporary table that is used with %Table.

This construct can be used to specify temporary tables for running parallel Application Engine processes.

Identify the record that the table name is drawn from. This can be a bind variable, a record object, or a record name in the
form recname. You cannot specify RECORD.recname, a record name in quotation marks, or a table name.

%Test

Specify a string that is conditionally added before the expansion of the test string. You cannot use meta-SQL in this parameter.

Test

Specify a meta-SQL string to be expanded.

Suffix

Specify a string that is conditionally added at the end of the test string. You can use meta-SQL in this parameter.

Returns

If the expansion of Test produces only a blank (or empty) string, the entire %Test meta-SQL construct is replaced with an empty string. Otherwise,
the %Test meta-SQL construct is replaced by the prefix, then the expansion of Test,and then the suffix.

Example

The following meta-SQL generates valid SQL even when the given record has no keys:

%SelectAll(:1) %Test(WHERE ,%KeyEqual(:1));

%TextIn

Syntax

%TextIn(BindVariable)

Description

%TextIn construct, when used with a bind variable, allows the insertion and updating of a text string into a LongChar field
(column).

Note. This meta-SQL construct is not implemented for COBOL. This construct is mandatory for any LongChar field insertion or update
to be compatible on all database platforms. If you don't use this meta-SQL wrapper, this type of operation fails on Sybase
and Informix.

%TimeAdd

Syntax

%TimeAdd(datetime, add-minutes)

Description

This construct generates the SQL that adds add-minutes (a positive or negative integer literal or expression, provided that the expression resolves to a data type that can be used
in datetime arithmetic for the given RDBMS) to the provided datetime (which can be a datetime literal or expression).

Note. On some platforms, you can use time-value in place of datetime. However, this can give a SQL error on other platforms (for example, Informix) if the result of the %TimeAdd construct would
result in a new date (for example, 11:59PM + 2 minutes). This meta-SQL construct is not implemented for COBOL.

Parameters

time

Specify a Time or DateTime value to add more time to.

add-minutes

Specify the number of minutes to add to time. This must be a numeric value or an expression that resolves to a numeric value.

Example

SELECT %TimeAdd(%CurrentTimeIn, 60) FROM PS_INSTALLATION

%TimeIn

Syntax

%TimeIn(tm)

Description

%TimeIn expands to platform-specific SQL for a Time value in the Where clause of a SQL Select or Update statement, or when
a time value is passed in an Insert statement.

Restrictions Using COBOL

You can only use string literals when using this construct in COBOL. You cannot use it with bind parameters in COBOL. For
example, the following works in COBOL:

UPDATE PS_PERSONAL_DATA SET LASTUPTM = %TIMEIN('11:59:00:000000')

The following SQL fails:

UPDATE PS_PERSONAL_DATA SET LASTUPTM = %TIMEIN(:1)

Parameters

tm

Specify a Time bind variable or a string literal in the form hh.mm.ss.ssssss.

%TimeNull

Syntax

%TimeNull

Description

Use this meta-SQL to specify a null value for a time field. Only use this meta-SQL in Insert or Update statements. Do not
use this meta-SQL in a Where clause.

Note. This meta-SQL is not implemented for COBOL.

This meta-SQL resolves into a database-specific SQL substring, as shown in the following table:

Database

Resolved Substring

Informix

empty string ('')

DB2

NULLIF(CURRENT TIME, CURRENT TIME)

All others

NULL

Parameters

None.

%TimeOut

Syntax

%TimeOut(time_col)

Description

%TimeOut expands to a platform-specific SQL substring representing time_col in the Select statement of an SQL query.

Parameters

time_col

Specify a time column.

%TimePart

Syntax

%TimePart(DTTM_Column)

Description

%TimePart returns the time portion of the specified datetime column.

Note. This meta-SQL is not implemented for COBOL.

Considerations Using %TimePart

Use %TimeOut meta-SQL when fetching from the database:

%TimeOut(%TimePart(DTTM_COLUMN)) from some_table

If a literal is used as the parameter to %TimePart, it must be wrapped in %DateTimeIn,as shown in the following:

%TrimSubstr

Syntax

%TrimSubstr(source_str, start, length)

Description

%TrimSubstr, like %Substring, expands to a substring of source_str, except that trailing blanks are removed from the substring.

Note. If you trim a string of blanks, an empty string is returned on all database platforms except Oracle, when a Null is returned.
If a Null result is not acceptable, such as when using the result as a value to insert into a non-nullable column, you can
turn the Null into a single blank using the %COALESCE meta-SQL with %TrimSubstr, for example: %COALESCE( %TrimSubstr( <expression>), ' ')

Parameters

source_str

Specify the source string.

start

Specify the substring's beginning position. The first character of source_str is position 1.

%TruncateTable

Syntax

%TruncateTable(table_name)

Description

%TruncateTable deletes all the rows in a table.

Note. You must use a table name, not a record name, with this statement.

On all databases, the use of %TruncateTable causes an implicit commit. The rows deleted by this command, and any other pending
database updates, are all committed. To postpone the commit until subsequent database updates have been successfully completed,
use the SQL statement DELETE FROM table_name or the statement IMPORT REPLACE WITH NULL instead of %TruncateTable(table_name). The advantage of using %TruncateTable is that its execution is faster than either of the SQL statements. %TruncateTable is
often used for removing rows from a work table or a temporary table.

If you're calling %TruncateTable from an Application Engine program step, you should commit after the step that immediately
precedes the step containing the %TruncateTable statement. Also, do not use %TruncateTable on a step that is executed multiple
times within a loop. In general, it's best to use this construct early in your Application Engine program as an initialization
task. In addition, avoid using this meta-SQL when your Application Engine program is started from the CallAppEngine function.

Example

If you use %TruncateTable with %Table, you must specify the full name of the table. For example:

%TruncateTable(%Table(BAS_ELIG_DBGFLD))

The following is a code example:

%TruncateTable(PS_TEMP_TABLE)

%UpdatePairs

Syntax

%UpdatePairs(recname [correlation_id])

Description

The %UpdatePairs construct produces a comma-separated list of fieldname = 'fieldvalue' phrases for each changed field of the given record. Input processing is applied to the values in the following ways:

If the field is a Date, a Time, or a DateTime value, its value is automatically wrapped in %Datein, %TimeIn, or %DateTimeIn,
respectively.

If the field is a string, its value is automatically wrapped in quotes.

If the field has a null value, NULL is the given value.

Note. This meta-SQL construct can only be used in PeopleCode programs, not in Application Engine PeopleCode actions. Also, this
meta-SQL construct is not implemented for COBOL.

Parameters

recname

Specify the name of the record to use for updating. This can be a bind variable, a record object, or a record name in the
form recname. You can't specify RECORD.recname, a record name in quotation marks, or a table name.

correlation_id

Identify the single-letter correlation ID to relate the record specified by recname and its fields.

Example

Suppose that the record &REC has one key: FNUM, and the FCHAR field has changed. Here is an example:

The following example updates all the fields on a base record (&REC) that are not also fields on the related language record
(&REC_RELATED_LANG). It creates a holding record (&REC_TEMP), copies the fields to update from the base record to the holding
record, and then uses the holding record for the update.

%Insert

%SelectAll

%SelectAll is shorthand for selecting all fields in the specified record, wrapping DateTime fields with %DateOut, %TimeOut,
and so on.

The pseudocode looks like this:

Select(AllFields, :num correlation_id) from %Table(:num) prefix

This shortcut is only appropriate if the statement is being used in PeopleCode or PeopleSoft Application Engine to read data
into memory. Dynamic views should retain the internal database formats for DateTime fields.

Using %SelectAll with CreateSQL

You can use %SelectAll with the CreateSQL function without a record object. It must subsequently be executed with the record
object with which you want to do the Select statement. Here is an example:

This shortcut is only appropriate if the statement is being used in PeopleCode or PeopleSoft Application Engine to read data
into memory. Dynamic views should retain the internal database formats for DateTime fields.