The built-in functions listed here are supported for the expression used to define a derived field on the MAPFLD parameter or a complex selection operand specified on the QRYSLT or GRPSLT parameter.
A numeric argument is a numeric field, a numeric constant or a numeric expression. A string argument is a character field, a character string literal, or a string expression. Unless otherwise noted, all built-in functions allow expressions, including other built-in functions, to be used as arguments.
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a packed decimal number (*DEC) with 8 digits and 0 precision (date duration), 6 digits and 0 precision (time duration), or 20 digits and 6 precision (timestamp duration).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
%AND accepts two or more character or hexadecimal string arguments and returns a string that is the bit-wise 'AND' (logical and) of the arguments. This function takes the first argument string, ANDs it with the next string, and continues to AND each successive argument with the previous result. If an argument is encountered that is shorter than the previous result, it is padded on the right with blanks. The returned value is a string of type *HEX with the same length as the longest argument. If any of the arguments are variable-length, the maximum length is used as the length of the argument.
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
%AVG is an aggregate function that is used for a nongrouping field in a query that uses the grouping function.
If the format is not specified, the job default format is used.
Example:
OPNQRYF FILE(library/file) GRPFLD(charfld) GRPSLT('charfld = %CHAR(timefld "USA")')
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
%COUNT does not support any arguments. It returns the count of the number of records contained in the group of records defined on the GRPFLD parameter. The returned value is a 4-byte binary number (*BIN4) with 10 total decimal digits and no fraction digits. %COUNT is an aggregate function that applies only to a query that uses the grouping function.
%CURDATE does not support any arguments. It obtains the current date based on a reading of the time-of-day clock. The returned value is of type *DATE. The format and separator are derived from the job attributes.
%CURSERVER does not support any arguments. If only non-distributed files are specified then it obtains the current server name (or RDB name) of the local system. If distributed files are specified then it obtains the current server name (or RDB name) of the COORDINATOR node. The returned value is of type variable-length character (*VCHAR) with a maximum length of 18.
%CURTIME does not support any arguments. It obtains the current time based on a reading of the time-of-day clock. The returned value is of type *TIME. The format and separator are derived from the job attributes.
%CURTIMESTP does not support any arguments. It obtains the current timestamp based on a reading of the time-of-day clock. The returned value is of type *TIMESTP. The format and separator will be derived from the job attributes.
%CURTIMEZONE does not support any arguments. It obtains the current time zone. The returned value is a packed decimal number (*DEC) with 6 digits and 0 precision.
OPNQRYF FILE(library/file) QRYSLT(('%DATE(tstampfld) = "1989-10-23"'))
A numeric field argument must be defined as packed decimal (*DEC) with 8 digits and 0 precision for date duration or packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must have 8 digits followed by a decimal point, or 14 digits followed by a decimal point and 6 digits.
%DAYS accepts a date/time argument and returns an integer representation of the date. The date/time argument can be a date or timestamp field, a character or hexadecimal field containing the external form of a date, or a date literal. The returned value is of type *BIN4.
%DIGITS accepts a numeric argument and returns a character representation of its numeric value, not including the sign or a decimal point. The result is tagged with the CCSID of the current job. For example, %DIGITS (-1.5) returns the character string 15. The numeric argument must not be a floating point number.
This built-in function is allowed to stand by itself in the mapped-field-definition of the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a date or timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
This built-in function is allowed to stand by itself in the mapped-field-definition on the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a time or timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
This built-in function is allowed to stand by itself in the mapped-field-definition on the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
This built-in function is allowed to stand by itself in the mapped-field-definition on the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a time or timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
This built-in function is allowed to stand by itself in the mapped-field-definition on the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a date or timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
This built-in function is allowed to stand by itself in the mapped-field-definition on the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a time or timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
This built-in function is allowed to stand by itself in the mapped-field-definition value on the MAPFLD parameter, and is allowed as part of an arithmetic (addition or subtraction) expression with a date or timestamp field on the QRYSLT, GRPSLT, or MAPFLD parameters.
OPNQRYF FILE((library/file)) QRYSLT('startfld > %CURDATE + oneyear *AND endfld < %CURDATE + %DURYEAR(2)') MAPFLD((oneyear '%DURYEAR(1)'))
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
A valid expression cannot include aggregate functions such as %COUNT, %AVG, %MIN, %MAX, %SUM, and %STDDEV as operands to %HASH.
Use the %HASH function to determine what the partitions are if the partitioning key is composed of EMPNO and LASTNAME. The following example returns the partition number for every row in EMPLOYEE.
OPNQRYF FILE((CORPDATA/EMPLOYEE)) FORMAT(FNAME) MAPFLD((HASH '%HASH((1/EMPNO) (1/LN))'))
%HEX accepts an argument and returns the hexadecimal equivalent of the argument's value. The hexadecimal argument can be of any type. The returned value is of type *CHAR, and is tagged with the CCSID of the current job.
A numeric field argument must be defined as packed decimal (*DEC) with 6 digits and 0 precision for time duration or packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must have 6 digits followed by a decimal point, or 14 digits followed by a decimal point and 6 digits.
Example: OPNQRYF FILE(library/file) QRYSLT(('%HOUR(timefld2) = 12'))
OPNQRYF FILE(library/file) QRYSLT('%LEN(varlenfld) <= 30') Argument Type Result Length in Bytes -------------------- ---------------------- Character 1-32766 Hex 1-32766 DBCS-only 4-32766 DBCS-either 4-32766 DBCS-open 4-32766 DBCS-graphic 1-16383 Variable Character 0-32740 Variable Hex 0-32740 Variable DBCS-only 0-32740 Variable DBCS-either 0-32740 Variable DBCS-open 0-32740 Variable DBCS-graphic 0-16370 Date 4 Time 3 Timestamp 10 Binary *BIN4 2 Binary *BIN8 4 Floating point *FLT4 4 Floating point *FLT8 8 Packed decimal (p,s) INTEGER(p/2)+1, (1-16) Zoned decimal (p,s) p (1-31) -------------------------------------------- p=precision, s=scale
%LEN Statement Field Data Result -------------- ------------ ------ %LEN(fixed10) '1234567890' 10 %LEN(fixed10) '12345' 10 %LEN(var10) '1234567890' 10 %LEN(var10) '12345' 5 %LEN(var10) '12345 ' 7 %LEN(var10) '' 0
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
If only one argument is specified, this function returns the maximum value of its argument for the group of records defined on the GRPFLD parameter, and the returned value has the same attributes as the argument. If no records are selected, the result is the null value. If the single argument is a date duration, time duration, or timestamp duration, then the returned value is a packed decimal number (*DEC) with 8 digits and 0 precision (date duration), 6 digits and 0 precision (time duration), or 20 digits and 6 precision (timestamp duration). When a single argument is used, it must be a field name or an expression (not a literal). %MAX with only one argument is an aggregate function that is used for a nongrouping field in a query that uses the grouping function.
If multiple arguments are specified, %MAX returns the maximum value of all the arguments. All arguments must be either character-string, DBCS-string, numeric, or date/time values. This function calculates the maximum value of the first two arguments, and then continues to determine the maximum value of the previous result and the next successive argument. The final result is determined according to the following value conversion rules.
If an argument has different attributes than the previous result, the two values are converted to identical attributes and the operation continues. This conversion uses packed decimal if both values are fixed-point numeric values, or floating-point if either value is floating-point. The conversion for fixed-point numeric values aligns the decimal points and pads the values with zeros. Numeric type changes might truncate fractional digits if more than 31 total digits are required for fixed-point numbers, or drop some of the least significant digits if more than 15 total digits are required for floating-point numbers. Character values are changed by padding the shorter field with blanks.
%MICSEC accepts a date/time argument and returns the microsecond part of the value. The date/time argument can be a timestamp (field or literal), a timestamp duration (field or literal), a character field that contains the external form of a timestamp, or a numeric field or literal. The returned value is of type *BIN4. A numeric field argument must be defined as packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must be 14 digits followed by a decimal point and 6 digits.
If only one argument is specified, this function returns the minimum value of its argument for the group of records defined on the GRPFLD parameter, and the returned value has the same attributes as the argument. If no records are selected, the result is the null value. If the single argument is a date duration, time duration, or timestamp duration, then the returned value is a packed decimal number (*DEC) with 8 digits and 0 precision (date duration), 6 digits and 0 precision (time duration), or 20 digits and 6 precision (timestamp duration). When a single argument is used, it must be a field name or an expression (not a literal). %MIN with only one argument is an aggregate function that is used for a nongrouping field in a query that uses the grouping function.
If multiple arguments are specified, %MIN returns the minimum value of all the arguments. All arguments must be either character-string, DBCS-string, numeric, or date/time values. This function calculates the minimum value of the first two arguments, and then continues to determine the minimum value of the previous result and the next successive argument. The final result is determined by the value change rules described below.
If an argument has different attributes than the previous one, the two values are changed to identical attributes and the operation continues. This change uses packed decimal numbers if both values are fixed-point numeric values, or floating-point numbers if either value is a floating-point number. The change for fixed-point numeric values aligns the decimal points and pads with zeros. Numeric type change might truncate fractional digits if more than 31 total digits are required for fixed-point numbers, or might drop some of the least significant digits if more than 15 total digits are required for floating-point numbers. Character values are changed by padding the shorter field with blanks.
A numeric field argument must be defined as packed decimal (*DEC) with 6 digits and 0 precision for time duration or packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must have 6 digits followed by a decimal point, or 14 digits followed by a decimal point and 6 digits.
A numeric field argument must be defined as packed decimal (*DEC) with 8 digits and 0 precision for date duration or packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must have 8 digits followed by a decimal point, or 14 digits followed by a decimal point and 6 digits.
Find the node name for every record of the EMPLOYEE table.
OPNQRYF FILE((CORPDATA/EMPLOYEE)) FORMAT(FNAME) MAPFLD((NODENAME '%NODENAME(1)'))
Join the EMPLOYEE and DEPARTMENT tables, select the employee number (EMPNO) and determine the node from which each record involved in the join originated.
OPNQRYF FILE((CORPDATA/EMPLOYEE) (CORPDATA/DEPARTMENT)) FORMAT(FNAME) JFLD((EMPLOYEE/DEPTNO DEPARTMENT/DEPTNO *EQ)) MAPFLD((EMPNO 'EMPLOYEE/EMPNO') (NODENAME1 '%NODENAME(1)') (NODENAME1 '%NODENAME(2)'))
Join the EMPLOYEE and DEPARTMENT tables, select all records of the result where the records of the two tables are on the same node.
OPNQRYF FILE((CORPDATA/EMPLOYEE) (CORPDATA/DEPARTMENT)) FORMAT(FNAME) JFLD((1/NODENAME1 2/NODENAME2 *EQ)) MAPFLD((NODENAME1 '%NODENAME(1)') (NODENAME2 '%NODENAME(2)'))
If the argument identifies a non-distributed file, the value zero is returned.
For OPNQRYF the node number from the secondary file where the outer or exception join is performed will be returned.
If CORPDATA.EMPLOYEE is a distributed file, then the node number for each record and the employee name will returned.
OPNQRYF FILE((CORPDATA/EMPLOYEE)) FORMAT(FNAME) MAPFLD((NODENAME '%NODENUMBER(1)') (LNAME '1/LASTNAME'))
OPNQRYF FILE(library/file) QRYSLT('%NONNULL(fld1 fld2 0) > 0')
The above example selects records from the file where either field FLD1 or field FLD2 contains a non-null value that is greater than zero. If both FLD1 and FLD2 were null, the %NONNULL function specified in this example would return '0' because of the constant '0' passed as the third argument. If any field is DBCS-graphic, all fields must be DBCS-graphic.
%NOT accepts a character or hexadecimal string argument and returns a string that is the bit-wise 'NOT' (logical not) of the argument. The returned value is a string of type *HEX with the same length as the argument.
%OR accepts two or more character-string arguments and returns a string that is the bit-wise 'OR' (logical inclusive or) of the arguments. This function takes the first argument string, ORs it with the next string, and then continues to OR each successive argument with the previous result. If an argument is encountered that is shorter than the previous result, it is padded with blanks. The final result is a string with the same length as the longest argument. If any of the arguments are variable-length, the maximum length is used as the length of the argument.
If the argument identifies a non-distributed file then a value of zero will be returned.
Find the PARTITION number for every row of the EMPLOYEE table. This can be used to determine if there is data skew.
OPNQRYF FILE((CORPDATA/EMPLOYEE)) FORMAT(FNAME) MAPFLD((PART1 '%PARTITION(1)'))
Select the employee number (EMPNO) from the EMPLOYEE table for all records where the partition number is equal to 100.
OPNQRYF FILE((EMPLOYEE)) QRYSLT('%PARTITION(1) *EQ 100')
Join the EMPLOYEE and DEPARTMENT tables, select all records of the result where the records of the two tables have the same partition number
OPNQRYF FILE((CORPDATA/EMPLOYEE) (CORPDATA/DEPARTMENT)) FORMAT(FNAME) JFLD((1/PART1 2/PART2 *EQ)) MAPFLD((PART1 '%PARTITION(1)') (PART2 '%PARTITION(2)'))
A numeric field argument must be defined as packed decimal (*DEC) with 6 digits and 0 precision for time duration or packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must have 6 digits followed by a decimal point, or 14 digits followed by a decimal point and 6 digits.
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
Single-byte substringing is done when these functions (%SST and %SUBSTRING) are used for DBCS data. The shift-out and shift-in characters might be lost, which produces unusual results. The result of the DBCS substring operation is the DBCS-open type.
The string argument can be a fixed- or variable-length character, hexadecimal, DBCS, or graphic field or an expression which evaluates to a fixed- or variable-length character, hexadecimal, DBCS, or graphic string.
The values derived from expressions for the second and third arguments must be valid integers. The second argument must have a value between 1 and the length attribute (or maximum length of a variable-length field) of the first argument, and the third argument must have a value between 1 and the length attribute (or maximum length of a variable-length field) of the first argument.
If an argument is DBCS-graphic, the second and third arguments must also be specified as DBCS-graphic characters, not bytes.
If an expression is given for the second or third arguments, the expression must be enclosed in parentheses.
If the expressions evaluate to variable-length results, no validation of the range of these expressions is guaranteed and errors might occur during input/output processing.
The maximum value allowed for the third argument (length) is 32766 except for DBCS-graphic, which is 16383. However, if the third operand is represented by an expression, this causes the result to be variable-length. Thus, the value of the expression cannot exceed 32740 except for DBCS-graphic, which cannot exceed 16370.
OPNQRYF FILE(library/file) QRYSLT('field1 = %SST(field2 (numfld1+3) (numfld1+numfld2))')
The string argument can be a literal, a fixed or variable-length character, hexadecimal, DBCS, or graphic field, or an expression which evaluates to a fixed- or variable-length character, hexadecimal, DBCS, or graphic string.
The strip character must be a single character, enclosed in apostrophes, with a data type compatible to the source string. The default is a single SBCS space for character data, DBCS-open, and DBCS-either, a single DBCS space for DBCS-only data, and a single graphic space for graphic data.
The default strip function is *BOTH.
OPNQRYF FILE(library/file) QRYSLT('%STRIP(fld '.' *TRAIL) = 'Mr')
%SUBSTRING performs the same operation as %SST. See the %SST description for more information.
%SUM is an aggregate function that is used for a nongrouping field in a query that uses the grouping function.
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The return value is a double-precision floating-point number (*FLT8).
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. Arguments of these types can be specified either as fields or literal values. The returned value is a double-precision floating-point number (*FLT8).
%TIME accepts a date/time argument and returns a time. The date/time argument can be a time or timestamp field, a character or hexadecimal field containing the external form of a time, or a time literal. The returned value is of type *TIME.
The returned value is of type *TIMESTP.
OPNQRYF FILE(library/file) QRYSLT('field = %USER')
The following argument types are treated as numeric values: date duration, time duration, and timestamp duration. If no records are selected, the result is the null value. Otherwise, the returned value is a double-precision floating-point number (*FLT8). %VAR is an aggregate function that is used for a nongrouping field in a query that uses the grouping function.
The second argument must be a simple or qualified table object name. If no library name is specified, *LIBL is used to find the table.
%XOR accepts two or more character-string arguments and returns a string that is the bit-wise 'XOR' (logical exclusive or) of the arguments. This function takes the first argument string, XORs it with the next string, and then continues to XOR each successive argument with the previous result. If an argument is encountered that is longer than the previous result, the previous result is padded with blanks before the XOR operation. If any of the arguments is variable-length, the maximum length is used as the length of the argument. The final result is a string of type *HEX with the same length as the longest argument.
A numeric field argument must be defined as packed decimal (*DEC) with 8 digits and 0 precision for date duration or packed decimal (*DEC) with 20 digits and 6 precision for timestamp duration. A numeric constant argument must have 8 digits followed by a decimal point, or 14 digits followed by a decimal point and 6 digits.