This section describes the meta-SQL constructs, functions, and meta-variables you can use in Application Engine.
本节描述可以在Application Engine中使用的元SQL构造、函数和元变量。
Note: The SQL Editor does not validate all of the meta-SQL constructs, such as %Bind and %Select. Messages might appear stating that these constructs are invalid.
附注:SQL编辑器不验证所有元SQL构造,如%Bind和%Select。可能会出现消息,指出这些构造无效。
Syntax
%Abs(x)
Description
Use the %Abs meta-SQL construct to return a decimal value equal to the absolute value of a number x.
使用%Abs meta-SQL构造函数返回一个十进制值,该值等于数字x的绝对值。
Note: This meta-SQL construct is not implemented for COBOL.
注意:这个元SQL构造不是为COBOL实现的。
Example
SELECT INVENTORY_CODE FROM INVENTORY_TABLE WHERE %ABS(NEW_AMOUNT - OLD_AMOUNT) > SO⇒ ME_ALLOWED_VALUE
Description
Use the %AeProgram meta-variable to specify a quoted string containing the currently running Application Engine program name.
使用%AeProgram元变量指定包含当前运行的应用程序引擎程序名称的带引号的字符串。
Description
Use the %AeSection meta-variable to specify a quoted string containing the currently running Application Engine section name.
使用%AeSection元变量指定包含当前运行的应用程序引擎节名称的带引号的字符串。
Description
Use the %AeStep meta-variable to specify a quoted string containing the currently running Application Engine Step name.
使用%AeStep元变量指定包含当前运行的应用程序引擎步骤名称的带引号的字符串。
Description
Use the %AsOfDate meta-variable to specify a quoted string containing the as of date used for the current process.
使用%AsOfDate元变量指定一个带引号的字符串,该字符串包含当前进程使用的截止日期。
Description
Use the %AsOfDateOvr meta-variable only as a parameter of the %ExecuteEdits function to override the default use of the system date with the value of a field on a joined record.
仅将%AsOfDateOvr元变量用作%ExecuteEdits函数的参数,以覆盖对已联接记录上的字段值使用系统日期的默认情况。
Related Links
相关链接
%Table
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.
任何使用COBOL语言函数执行的内存排序都是在当前用于COBOL处理的字符集中作为二进制排序执行的,并且不一定与数据库响应Order By子句返回的排序顺序相匹配。如果要求数据库返回使用其编码的二进制排序的数据,而不是默认的语言上正确的排序,您必须在二进制排序很重要的Where或Order By子句中的每个列周围使用%BINARYSORT meta-SQL函数。
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.
但是,对于z/OS实现,请记住,这种二进制排序只有在运行z/OS服务器的COBOL程序时才有效。例如,COBOL中产生的二进制排序不同于数据库产生的二进制排序,因为数据库是用扩展二进制编码的十进制交换码(EBCDIC)编码的,而客户端是基于ASCII的编码。因此,%BINARYSORT只应在不使用RemoteCall函数运行的COBOL程序中使用,在这种程序中,z/OS平台不作为RemoteCall服务器受到支持。
When running against non-z/OS systems, %BINARYSORT can be used in both RemoteCall and nonRemoteCall programs.
在非z/OS系统上运行时,%BINARYSORT可以在RemoteCall和非RemoteCall程序中使用。
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.
附注:在Where and Order By子句中使用%BINARYSORT否定任何索引的使用,因为大多数数据库不能使用索引进行功能比较。(例如,WHERE%BINARYSORT(列)>"X")。仅当需要对SQL语句结果和COBOL内存顺序进行排序时才使用此语法。
Parameters
Parameter |
Description |
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)
Related Links
RemoteCall
“Understanding COBOL in a Unicode Environment” (Global Technology)
相关链接RemoteCall“在Unicode环境中理解COBOL”(全球技术)
Syntax
%Bind([recordname.]fieldname [,
NOQUOTES][, NOWRAP][, STATIC])
Description
Use the %Bind construct to retrieve a field value from a state record. You can use %Bind anywhere in a SQL statement. When run, %Bind returns the value of the state record field identified within its parentheses.
使用%BIND构造从状态记录检索字段值。您可以在SQL语句中的任何位置使用%Bind。运行时,%Bind返回圆括号内标识的状态记录字段的值。
Notes About %Bind
关于%Bind
Typically, when you use %Bind to provide a value for a field or a Where condition, the type of field in the state record that you reference with %Bind must match the field type of the corresponding database field used in the SQL statement.
通常,当使用%Bind为字段或Where条件提供值时,使用%Bind引用的状态记录中的字段类型必须与SQL语句中使用的相应数据库字段的字段类型匹配。
On most platforms, you cannot use a literal to populate a Long Varchar field. You should use the %Bind(recordname.fieldname) construct.
在大多数平台上,不能使用文字填充Long Varchar字段。您应该使用%Bind(记录名.字段名)构造。
In the case of an external call to a section in another program, if the called program has its own default state record defined, then Application Engine uses that default state record to resolve the %Bind(fieldname). Otherwise, the called program inherits the default state record of the calling program.
在外部调用另一个程序中的节的情况下,如果被调用的程序定义了自己的默认状态记录,则应用程序引擎使用该默认状态记录来解析%Bind(fieldname)。否则,被调用的程序将继承调用程序的默认状态记录。
All fields referenced by a %Select construct must be defined in the associated state record.
必须在关联的状态记录中定义%Select构造引用的所有字段。
You must use the Date, Time, and DateTime output wrappers in the Select list that populates the state record fields to ensure compatibility across all supported database platforms.
必须使用填充状态记录字段的Select列表中的Date、Time和DateTime输出包装,以确保在所有受支持的数据库平台之间的兼容性。
For example:
举个例子:
%Select(date_end)
SELECT %DateOut(date_end )
FROM PS_EXAMPLE
INSERT INTO PS_EXAMPLE
VALUES(%Bind(date_end))
Bind Variables and Date Wraps
绑定变量和日期包装
The behavior of bind variables within Application Engine PeopleCode and normal PeopleCode is the same.
应用程序引擎PeopleCode和普通PeopleCode中绑定变量的行为是相同的。
If you compare Application Engine SQL to PeopleCode (of any type), then the system processes bind variables differently.
如果您将Application Engine SQL与PeopleCode(任何类型)进行比较,则系统进程绑定变量的方式不同。
If you use the following approach:
如果您使用以下方法:
AND TL_EMPL_DATA1.EFFDT <= %P(1))
Then in PeopleCode you issue
然后在PeopleCode中发布
%SQL(MY_SQL, %DateIn(:1))
which assumes that you referenced the literal as a bind variable.
它假定您将文本作为绑定变量引用。
Or in Application Engine SQL, you issue
或在应用程序引擎SQL中,您发出
%SQL(MY_SQL, %Bind(date_field))
%SQL(MY_SQL, %Bind(date_field, NOWRAP))
Parameters
Parameter |
Description |
Recordname |
The name of a state record. If you do not specify a particular state record, Application Engine uses the default state record to resolve the %Bind (fieldname). |
Fieldname |
The field defined in the state record. |
NOQUOTES |
If the field specified is a character field, its value is automatically enclosed in quotes unless you use the NOQUOTES parameter. Use NOQUOTES to include a dynamic table and field name reference, even an entire SQL statement or clause, in an Application Engine SQL action. |
NOWRAP |
If the field is of type Date, Time, or DateTime, the system automatically wraps its value in %DateIn or %DateOut, unless you use the NOWRAP parameter. Therefore, if the state record field is populated correctly, you do not need to be concerned with the inbound references, although you can suppress the inbound wrapping with the NOWRAP modifier inside the %Bind. Furthermore, Application Engine skips the inbound wrapper if the %Bind (date) is in the select field list of another %Select statement. This is because the bind value is already in the outbound format, and the system selects it into another state record field in memory. In this circumstance there is no need for either an outbound wrapper or an inbound wrapper. For example, First SQL action: %Select(date_end) SELECT %DateOut(date_end ) FROM PS_GREG Second SQL action: INSERT INTO ps_greg VALUES(%Bind(date_end)) |
STATIC |
The STATIC parameter enables you to include a hard-coded value in a reused statement. For %Bind instances that contain dynamic SQL, this parameter must be used in conjunction with the NOQUOTES parameter for proper execution of a reused statement. |
Example
UPDATE PS_REQ_HDR
SET IN_PROCESS_FLG = %Bind(MY_AET.IN_PROCESS_FLG),
PROCESS_INSTANCE = %Bind(PROCESS_INSTANCE)
WHERE IN_PROCESS_FLG = ‘N’
AND BUSINESS_UNIT || REQ_ID
IN (SELECT BUSINESS_UNIT ||REQ_ID
FROM PS_PO_REQRCON_WK1
WHERE PROCESS_INSTANCE = %Bind(PROCESS_INSTANCE))
In the previous example, %Bind (PROCESS_INSTANCE) assigns the value of the field PROCESS_INSTANCE in the default state record to the PROCESS_INSTANCE field in table PS_REQ_HDR.
在前面的示例中,%Bind(PROCESS_INSTANCE)将默认状态记录中字段PROCESS_INSTANCE的值分配给tablePS_REQ_HDR中的PROCESS_INSTANCE字段。
The %Bind construct is also used in a Where clause to identify rows in the table
PS_PO_REQRCON_WK1, in which the value of PROCESS_INSTANCE equals the value of PROCESS_INSTANCE in the default state record.
Bind构造也用于Where子句中,以标识表PS_PO_REQRCON_WK1中的行,其中PROCESS_INSTANCE的值等于默认状态记录中的PROCESS_INSTANCE的值。
Syntax
%Cast(source_expr, source_type, target_type[, precision[.scale]])
Description
Use the %Cast meta-SQL function to convert a PeopleSoft data type to a Character data type. A database-generated error is returned if the function attempts to make an invalid conversion. %Cast can be used wherever %DateOut, %TimeOut, %DateTimeOut, %CurrentDateOut, %CurrentTimeOut, %CurrentDateTimeOut, and %NumToChar functions can be used.
使用%Cast元SQL函数将PeopleSoft数据类型转换为Character数据类型。如果函数试图进行无效转换,则返回数据库生成的错误。%可以在任何可以使用%DateOut、%TimeOut、%Date TimeOut、%Current DateOut、%Current Date TimeOut和%NumToChar函数的地方使用强制转换。
Note: %NumToChar will preserve all trailing zeroes. Therefore, use the scale parameter of %Cast to specify the number of trailing zeroes.
注意:%NumToChar将保留所有尾随的零。因此,使用%Cast的比例参数来指定尾随零的数量。
On some platforms the meta-SQL functions %DateOut, %TimeOut, %DateTimeOut, %CurrentDateOut, %CurrentTimeOut and %CurrentDateTimeOut don’t return a Character value. On other platforms, these functions return a Character string only in certain cases. %Cast returns a Character value on all supported platforms.
在某些平台上,元SQL函数%DateOut、%TimeOut、%Date TimeOut、%Current DateOut、%Current TimeOut和%Current Date TimeOut不返回字符值。在其他平台上,这些函数只在某些情况下返回字符串。%Cast在所有受支持的平台上返回一个字符值。
Use %Cast only in the Select portion of query. Do not use it in a Where clause or in Insert or Update statements.
仅在查询的“选择”部分使用%Cast。不要在Where子句或Insert或Update语句中使用它。
Parameters
Parameter |
Description |
source_expr |
Specify the input expression in the form of a Number, Long Character, Date, Time, or DateTime column name or as a %CurrentDateOut, %CurrentTimeOut, or %CurrentDateTimeOut meta-SQL variable. This parameter is not case sensitive. |
source_type |
Specify the source data type. Valid data types are Number, Long, Date, Time, and DateTime. This parameter is not case sensitive. |
target_type |
Currently the only target type supported is Character. |
precision.scale |
The precision.scale parameter is currently supported on DB2 for z/OS only and with a source type of Number. While this parameter can be supplied on other platforms, it is ignored. This parameter is optional. The scale parameter is an optional part of this parameter. Therefore, the expression precision.0 is equivalent to precision. |
Syntax
%ClearCursor({program,section,step,action | ALL})
Description
Use the %ClearCursor function to recompile a reused statement and reset any STATIC %Bind variables.
使用%ClearCursor函数重新编译一个重用语句并重置所有STATIC%Bind变量。
When you use the %ClearCursor function, remember that:
当您使用%ClearCursor函数时,请记住:
Parameters
Parameter |
Description |
program |
Specify the name of the Application Engine program containing the reused statement you want to recompile. |
section |
Specify the name of the section containing the reused statement you want to recompile. |
step |
Specify the name of the step containing the reused statement you want to recompile. |
action |
Specify one of the following values:
|
ALL |
Clear all cursors in the current Application Engine program. |
Syntax
%COALESCE(expr1, expr2, ...)
Description
Use the %COALESCE function to return the first non-null argument provided to the function.
使用%COALESCE函数返回提供给该函数的第一个非空参数。
Note: This meta-SQL function is not implemented for COBOL.
附注:这个元SQL函数不是为COBOL实现的。
Parameters
Parameter |
Description |
expr1. . .exprn |
Specify the expressions to check. Note: You cannot specify bind parameters using these expressions. |
Note: %COALESCE has been deprecated but remains for backward compatibility only. Use your database's native COALESCE function instead.
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.
下面的示例使用PRODUCT_INFO表组织产品的清仓销售。所有产品都有10%的折扣。如果没有标价,则销售价格为最低价。如果没有最低价,销售价格为10。
SELECT product_id, list_price, min_price, %COALESCE(0.9*list_price, min_price, 10) ⇒
"Sale"
from PRODUCT_INFO where SUPPLIER_ID = 6009;
Description
Use the %Comma meta-variable to specify a comma. This meta-variable is useful when you must use a comma but commas are not allowed because of parsing rules. For example, you might use this metavariable if you want to pass a comma as a parameter to the %SQL meta-SQL function.
使用%Comma元变量指定逗号。这个元变量在必须使用逗号但由于解析规则不允许使用逗号时非常有用。例如,如果希望将逗号作为参数传递给%SQL元SQL函数,则可以使用此元变量。
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 SQL Server it's replaced with a +, and on Oracle it’s replaced with ||.
在运行时,%Concat meta-SQL变量被替换为适用于所使用的关系数据库管理系统(RDBMS)的字符串连接操作符。例如,在 DB2 上,% Concat 元- SQL 变量替换为 CONCAT ,在 SQL Server 上替换为+,在 Oracle 中替换为||。
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.
支持meta-SQL变量的限制与执行meta-SQL的RDBMS的本机串联操作符相同。例如,某些平台允许您将字符串与数值连接起来;而其他平台则将此标记为错误。PeopleTools不尝试检查或转换任何一个操作数的数据类型。
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.
附注:COBOL中没有concat,但是可以将DYN-STMT-CONCAT字段串成动态COBOL字符串,以解析为特定于平台的连接操作符。
Example
Example 1:
SELECT LAST_NAME %Concat ',' %Concat FIRST_NAME FROM PS_EMPLOYEE
Example 2:
SELECT PORTAL_NAME
, PORTAL_LABEL
, %TrimSubstr(PORTAL_OBJNAME,1,30) %Concat ':' %Concat %TrimSubstr(PORTAL_NAME,1,3⇒
0)
FROM PSPRSMDEFN
WHERE PORTAL_PRNTOBJNAME = 'CO_NAVIGATION_COLLECTIONS'
AND PORTAL_REFTYPE = 'F'
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.
CurrentDateIn meta-SQL变量扩展为特定于平台的SQL子字符串,表示SQL Select或Update语句的Where子句中的当前日期,或者在Insert语句中传递当前日期时表示当前日期。
Description
The %CurrentDateOut meta-SQL variable expands to platform-specific SQL for the current date in the Select clause of a SQL query.
CurrentDateOut meta-SQL变量在SQL查询的Select子句中展开为当前日期的特定于平台的SQL。
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.
CurrentDateTimeIn meta-SQL变量扩展为特定于平台的SQL子字符串,表示SQL Select或Update语句的Where子句中的当前日期时间,或者在Insert语句中传递当前日期时间时表示当前日期时间。
Description
The %CurrentDateTimeOut meta-SQL variable expands to platform-specific SQL for the current datetime in the Select clause of a SQL query.
CurrentDateTimeOut元SQL变量在SQL查询的Select子句中展开为当前日期时间的特定于平台的SQL。
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.
CurrentTimeIn meta-SQL变量扩展为特定于平台的SQL子字符串,表示SQL Select或Update语句的Where子句中的当前时间,或者在Insert语句中传递当前时间时的时间。
Description
The %CurrentTimeOut meta-SQL variable expands to platform-specific SQL for the current time in the Select clause of a SQL query.
CurrentTimeOut元SQL变量在SQL查询的Select子句中展开为当前时间的特定于平台的SQL。
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.
DateAdd meta-SQL函数通过将add_days添加到date_from返回一个日期。add_days变量可以是负的。
Example
SQLExec("SELECT %DateAdd(%DateIn('2002-02-02'), 12) from %SelectDummyTable", &add);
WinMessage(&add);
Syntax
%DateDiff(date_from, date_to)
Description
The %DateDiff meta-SQL function returns an integer representing the difference between two dates in number of days. For example: diff = date_to - date_from
%DateDiff元SQL函数返回一个整数,表示两个日期之间的天数差。例如: diff = date to - date from
Example
%DateDiff(%DateIn('1966-06-30'), %DateIn('1997-01-01'))
%DateDiff( date1_column, date2_column)
%DateDiff( %DateAdd(date1_column, 30), date2_column)
The following usage is illegal (always use %Datein for inputting date literals):
以下用法是非法的(总是使用%Datein输入日期文字):
%DateDiff('1996-06-30', '1997-01-01') /* should use %DateIn for inputting date lite⇒ rals */
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.
DateIn元SQL变量扩展为日期的特定于平台的SQL语法。只要在Select或Update语句的Where子句的比较中使用日期文本或Date绑定变量,或者在Insert语句中传递Date值,请使用%DateIn。
Restrictions Using COBOL
使用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:
在COBOL中使用此构造时,只能使用字符串文字。您不能将它与COBOL中的绑定参数一起使用。例如,以下代码在COBOL中运行:
UPDATE PS_PERSONAL_DATA SET LASTUPDT = %DATEIN('2002-12-11')
The following SQL fails:
以下SQL失败:
UPDATE PS_PERSONAL_DATA SET LASTUPDT = %DATEIN(:1)
Parameters
Parameter |
Description |
dt |
Specify either a Date value or a date literal in YYYY-MM-DD format. |
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.
使用%DateNull meta-SQL变量为Date字段指定空值。仅在插入或更新子句中使用此元SQL。不要在Where子句中使用这个元SQL。
Note: This meta-SQL variable is not implemented for COBOL.
注意:这个元SQL变量不是为COBOL实现的。
This meta-SQL resolves into a database-specific SQL substring, as shown in the following table:
Database |
Resolved Substring |
DB2 |
NULLIF(CURRENT DATE, CURRENT DATE) |
All others |
NULL |
Parameters None.
Syntax
%DateOut(dt)
Description
The %DateOut meta-SQL variable expands to either a platform-specific SQL substring or datetime value, depending on the database platform, representing a datetime column in the Select clause of a SQL query
DateOut meta-SQL变量根据数据库平台展开为平台特定的SQL子字符串或datetime值,表示SQL查询的Select子句中的datetime列
Parameters
Parameter |
Description |
dt |
Specify dt as a date column. 将dt指定为日期列。 Note: You cannot specify a literal value for dt. Code such as %DateOut('1900-01-01') is not allowed. 注意:您不能为dt指定文本值。不允许使用诸如%DateOut(‘1900-01-01’)之类的代码。 |
Syntax
%DatePart(DTTM_Column)
Description
The %DatePart meta-SQL variable returns the date portion of the specified DateTime column.
DatePart meta-SQL变量返回指定的DateTime列的日期部分。
Note: This meta-SQL variable is not implemented for COBOL.
注意:这个元SQL变量不是为COBOL实现的。
Considerations using %DatePart
使用%DatePart的注意事项
Use %DateOut meta-SQL when fetching values, as in the following example:
获取值时使用%DateOut meta-SQL,如以下示例所示:
%DateOut(%DatePart(DTTM_COLUMN)) from some_table
If a literal is used as the parameter to %DatePart, it must be wrapped in %DateTimeIn:
如果文本用作%DatePart的参数,则必须将其包装在%DateTimeIn中:
insert into some_table values(%DatePart(%DateTimeIn('2001-01-01-12.34.56.789012')))
Parameters
Parameter |
Description |
DTTM_Column |
Specify the datetime column from which you want to return the date. |