ibm-information-center/dist/eclipse/plugins/i5OS.ic.dbp_5.4.0.1/rbafobif.htm

839 lines
47 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Built-in functions" />
<meta name="abstract" content="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." />
<meta name="description" content="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." />
<meta name="DC.Relation" scheme="URI" content="rbafoopnqf.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafobif" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Built-in functions</title>
</head>
<body id="rbafobif"><a name="rbafobif"><!-- --></a>
<img src="./delta.gif" alt="Start of change" /><!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Built-in functions</h1>
<div><p>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.</p>
<div class="section"><p>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.</p>
<div class="p">For
a field that appears in the record format identified by the FORMAT parameter,
and that is also defined by an expression on the MAPFLD parameter, the expression
result is calculated by using the attributes described in the following paragraphs.
Then the resultant value is mapped to match the attributes of the field.<dl><dt class="dlterm">%ABSVAL (numeric-argument)</dt>
<dd>%ABSVAL accepts a numeric argument and returns the absolute value of the
argument. The returned value has the same attributes as the argument, unless
the argument is a *BIN2, in which case the returned value is a *BIN4.<p>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).</p>
</dd>
<dt class="dlterm">%ACOS (numeric-argument)</dt>
<dd>%ACOS accepts a numeric argument and returns the arc cosine of the argument,
in radians. %ACOS and %COS are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%AND (string-argument ...)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%ANTILOG (numeric-argument)</dt>
<dd>%ANTILOG accepts a numeric argument and returns the antilogarithm (base
10) of the argument. %ANTILOG and %LOG are inverse operations.<p>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).</p>
</dd>
<dt class="dlterm">%ASIN (numeric-argument)</dt>
<dd>%ASIN accepts a numeric argument and returns the arc sine of the argument,
in radians. %ASIN and %SIN are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%ATAN (numeric-argument)</dt>
<dd>%ATAN accepts a numeric argument and returns the arc tangent of the argument,
in radians. %ATAN and %TAN are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%ATANH (numeric-argument)</dt>
<dd>%ATANH accepts a numeric argument and returns the hyperbolic arc tangent
of the argument, in radians. %ATANH and %TANH are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%AVG (numeric-argument)</dt>
<dd>%AVG accepts a numeric argument and returns the average value of its argument
for the group of records defined on the GRPFLD parameter. The argument must
be a field name or an expression (not a literal). <div class="p">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,<ul><li>If the argument is fixed-point, the result is a packed decimal number
(*DEC) with 31 total digits and the same number of integer digits as the argument.</li>
<li>If the argument is floating-point, the result is a double-precision floating-point
number (*FLT8).</li>
<li>If the argument is date duration, time duration, or timestamp duration,
the returned value is a packed decimal number (*DEC) with 31 digits and 0
precision (date duration), 31 digits and 0 precision (time duration), or 31
digits and 6 precision (timestamp duration).</li>
</ul>
</div>
<p>%AVG is an aggregate function that is used for a nongrouping field
in a query that uses the grouping function.</p>
</dd>
<dt class="dlterm">%CHAR (date/time-argument date/time-format)</dt>
<dd>%CHAR accepts a date/time argument and date/time format and returns the
character representation of the argument using the specified format. The date/time
argument can be a date, time, or timestamp field. The returned value is of
type *CHAR and is tagged with the CCSID of the current job. <div class="p">The date/time
format is optional. If specified, it must be one of the following formats:<dl><dt class="dlterm">EUR</dt>
<dd>European format</dd>
<dt class="dlterm">ISO</dt>
<dd>International Standards Organization format</dd>
<dt class="dlterm">JIS</dt>
<dd>Japanese Industrial Standard format</dd>
<dt class="dlterm">USA</dt>
<dd>United States format</dd>
</dl>
</div>
<p>If the format is not specified, the job default format
is used.</p>
<p>Example:</p>
<pre>OPNQRYF
FILE(library/file)
GRPFLD(charfld)
GRPSLT('charfld = %CHAR(timefld "USA")')</pre>
</dd>
<dt class="dlterm">%COS (numeric-argument)</dt>
<dd>%COS accepts a numeric argument and returns the cosine of the argument.
The argument must be specified in radians. %COS and %ACOS are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%COSH (numeric-argument)</dt>
<dd>%COSH accepts a numeric argument and returns the hyperbolic cosine of
the argument. The argument must be specified in radians. <p>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).</p>
</dd>
<dt class="dlterm">%COT (numeric-argument)</dt>
<dd>%COT accepts a numeric argument and returns the cotangent of the argument.
The argument must be specified in radians.<p>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).</p>
</dd>
<dt class="dlterm">%COUNT</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%CURDATE</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%CURSERVER</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%CURTIME</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%CURTIMESTP</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%CURTIMEZONE</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%DATE (date/time-argument)</dt>
<dd>%DATE accepts a date/time argument and returns a date. The date/time argument
can be a date or timestamp field, a character or hexadecimal field containing
the external form of a date, a date literal, or a numeric field or literal
value in the range 1 - 3,652,059. The returned value is of type *DATE. <div class="p">Example:<pre> OPNQRYF
FILE(library/file)
QRYSLT(('%DATE(tstampfld) =
"1989-10-23"'))</pre>
</div>
</dd>
<dt class="dlterm">%DAY (date/time-argument)</dt>
<dd>%DAY accepts a date/time argument and returns the day part of the value.
The date/time argument can be a date or timestamp field, a date duration or
timestamp duration (field or literal), or a numeric field or literal. The
returned value is of type *BIN4. <p>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.</p>
</dd>
<dt class="dlterm">%DAYS (date/time-argument)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%DIGITS (numeric-argument)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%DURDAY (integer-argument)</dt>
<dd>%DURDAY accepts an integer argument and returns a labeled duration of
days. The integer argument for this function can be a numeric expression,
a field, or a literal. <p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
</dd>
<dt class="dlterm">%DURHOUR (integer-argument)</dt>
<dd>%DURHOUR accepts an integer argument and returns a labeled duration of
hours. The integer argument for this function can be a numeric expression,
a field, or a literal. <p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
</dd>
<dt class="dlterm">%DURMICSEC (integer-argument)</dt>
<dd>%DURMICSEC accepts an integer argument and returns a labeled duration
of microseconds. The integer argument for this function can be a numeric expression,
a field, or a literal.<p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
</dd>
<dt class="dlterm">%DURMINUTE (integer-argument)</dt>
<dd>%DURMINUTE accepts an integer argument and returns a labeled duration
of minutes. The integer argument for this function can be a numeric expression,
a field, or a literal. <p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
</dd>
<dt class="dlterm">%DURMONTH (integer-argument)</dt>
<dd>%DURMONTH accepts an integer argument and returns a labeled duration of
months. The integer argument for this function can be a numeric expression,
a field, or a literal. <p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
</dd>
<dt class="dlterm">%DURSEC (integer-argument)</dt>
<dd>%DURSEC accepts an integer argument and returns a labeled duration of
seconds. The integer argument for this function can be a numeric expression,
a field, or a literal. <p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
</dd>
<dt class="dlterm">%DURYEAR (integer-argument)</dt>
<dd>%DURYEAR accepts an integer argument and returns a labeled duration of
years. The integer argument for this function can be a numeric expression,
a field, or a literal. <p>This built-in function is allowed to stand by itself
in the <em>mapped-field-definition</em> 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.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((library/file))
QRYSLT('startfld &gt; %CURDATE + oneyear *AND
endfld &lt; %CURDATE + %DURYEAR(2)')
MAPFLD((oneyear '%DURYEAR(1)'))</pre>
</div>
</dd>
<dt class="dlterm">%EXP (numeric-argument)</dt>
<dd>%EXP accepts a numeric argument and returns a value that is the base of
the natural logarithm (e) raised to a power specified by the argument. %EXP
and %LN are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%HASH (expression-argument)</dt>
<dd>%HASH accepts a valid expression and returns a 4-byte binary number (*BIN4)
with 10 total decimal digits and no fraction digits. The returned value will
be the partition number of the record selected. <p>A valid expression cannot
include aggregate functions such as %COUNT, %AVG, %MIN, %MAX, %SUM, and %STDDEV
as operands to %HASH.</p>
<p>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.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((CORPDATA/EMPLOYEE))
FORMAT(FNAME)
MAPFLD((HASH '%HASH((1/EMPNO) (1/LN))'))</pre>
</div>
</dd>
<dt class="dlterm">%HEX (hexadecimal-argument)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%HOUR (date/time-argument)</dt>
<dd>%HOUR accepts a date/time argument and returns the hour part of the value.
The date/time argument can be a time or timestamp field, a time duration or
timestamp duration (either field or literal), or a numeric field or literal.
The returned value is of type *BIN4. <p>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.</p>
<div class="p">Example:<pre>Example:
OPNQRYF
FILE(library/file)
QRYSLT(('%HOUR(timefld2) = 12'))</pre>
</div>
</dd>
<dt class="dlterm">%LEN (length-argument)</dt>
<dd>%LEN accepts one argument and returns the number of bytes used to represent
the value unless the value is a graphic field type. If the value is a graphic
field type, the number of graphic characters is returned. The length argument
can be of any type. The returned value is of type *BIN4. <div class="p">Example:<pre>OPNQRYF
FILE(library/file)
QRYSLT('%LEN(varlenfld) &lt;= 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</pre>
</div>
<div class="p">String notes: The %LEN function returns the length of the
value as it is stored in the data space.<ul><li>For fixed-length fields, the length is always the same as the declared
size of the field, not the length of the actual data in the field.</li>
<li>For variable-length fields, the length is the length of the actual data
in the field, including trailing blanks.</li>
</ul>
</div>
<div class="p">For example, assume FIXED10 is a *CHAR(10) field, and VAR10 is
a *VCHAR(10) field. The following example shows results of the %LEN function:<pre>%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</pre>
</div>
</dd>
<dt class="dlterm">%LN (numeric-argument)</dt>
<dd>%LN accepts a numeric argument and returns the natural logarithm of the
argument. %LN and %EXP are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%LOG (numeric-argument)</dt>
<dd>%LOG accepts a numeric argument and returns the common logarithm (base
10) of the argument. %LOG and %ANTILOG are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%MAX (numeric-or-string-or-date/time-argument ...)</dt>
<dd>%MAX accepts one or more character-string, DBCS-string, numeric, or date/time
arguments, and returns the largest value from the list. Date/time arguments
are arguments of type *DATE, *TIME, or *TIMESTP, or arguments that are date,
time, or timestamp durations. String arguments must be no longer than 256
bytes. <p>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.</p>
<p>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.</p>
<p>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.</p>
</dd>
<dt class="dlterm">%MICSEC (date/time-argument)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%MIN (numeric-or-string-or-date/time-argument ...)</dt>
<dd>%MIN accepts one or more character-string, DBCS-string, numeric, or date/time
arguments, and returns the smallest value from the list. Date/time arguments
are arguments of type *DATE, *TIME, or *TIMESTP, or arguments that are date,
time, or timestamp durations. String arguments must be no longer than 256
bytes. <p>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.</p>
<p>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.</p>
<p>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.</p>
</dd>
<dt class="dlterm">%MINUTE (date/time-argument)</dt>
<dd>%MINUTE accepts a date/time argument and returns the minute part of the
value. The date/time argument can be a time or timestamp field, a time duration
or timestamp duration (either field or literal), or a numeric field or literal.
The returned value is of type *BIN4. <p>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.</p>
</dd>
<dt class="dlterm">%MONTH (date/time-argument)</dt>
<dd>%MONTH accepts a date/time argument and returns the month part of the
value. The date/time argument can be a date or timestamp field, a date duration
or timestamp duration (field or literal), or a numeric field or literal. The
returned value is of type *BIN4. <p>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.</p>
</dd>
<dt class="dlterm">%NODENAME (integer-argument)</dt>
<dd>%NODENAME accepts an integer-argument which is used to identify a file
that has been specified on the FILE parameter. The argument must be greater
than 0 and less than or equal to the number of files specified on the file
parameter. The %NODENAME function returns the RDB name for the record retrieved.
The returned value is of type *VCHAR of length 18.<p>Find the node name for
every record of the EMPLOYEE table.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((CORPDATA/EMPLOYEE))
FORMAT(FNAME)
MAPFLD((NODENAME '%NODENAME(1)'))</pre>
</div>
<p>Join the EMPLOYEE
and DEPARTMENT tables, select the employee number (EMPNO) and determine the
node from which each record involved in the join originated.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((CORPDATA/EMPLOYEE) (CORPDATA/DEPARTMENT))
FORMAT(FNAME)
JFLD((EMPLOYEE/DEPTNO DEPARTMENT/DEPTNO *EQ))
MAPFLD((EMPNO 'EMPLOYEE/EMPNO')
(NODENAME1 '%NODENAME(1)')
(NODENAME1 '%NODENAME(2)'))</pre>
</div>
<p>Join the EMPLOYEE and
DEPARTMENT tables, select all records of the result where the records of the
two tables are on the same node.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((CORPDATA/EMPLOYEE) (CORPDATA/DEPARTMENT))
FORMAT(FNAME)
JFLD((1/NODENAME1 2/NODENAME2 *EQ))
MAPFLD((NODENAME1 '%NODENAME(1)')
(NODENAME2 '%NODENAME(2)'))</pre>
</div>
</dd>
<dt class="dlterm">%NODENUMBER (integer-argument)</dt>
<dd>%NODENUMBER accepts an integer-argument which is used to identify a file
that has been specified on the FILE parameter. The argument must be greater
than zero and less than or equal to the number of files specified on the file
parameter. The %NODENUMBER function returns a 4-byte binary number (*BIN4)
with 10 total decimal digits and no fraction digits. The returned value will
be the node number of the record selected. <p>If the argument identifies a
non-distributed file, the value zero is returned.</p>
<p>For OPNQRYF the node
number from the secondary file where the outer or exception join is performed
will be returned.</p>
<p>If CORPDATA.EMPLOYEE is a distributed file, then the
node number for each record and the employee name will returned.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((CORPDATA/EMPLOYEE))
FORMAT(FNAME)
MAPFLD((NODENAME '%NODENUMBER(1)')
(LNAME '1/LASTNAME'))</pre>
</div>
</dd>
<dt class="dlterm">%NONNULL (argument ...)</dt>
<dd>%NONNULL accepts a list of two or more arguments and returns the first
non-null value from the list. The items in the argument list can be fields
or literal values of any type. The type of the returned value is that of the
item selected from the list.<div class="p">Example:<pre>OPNQRYF
FILE(library/file)
QRYSLT('%NONNULL(fld1 fld2 0) &gt; 0')</pre>
</div>
<p>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.</p>
</dd>
<dt class="dlterm">%NOT (string-argument)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%OR (string-argument ...)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%PARTITION (integer-argument)</dt>
<dd>%PARTITION accepts an integer-argument which is used to identify a file
that has been specified on the FILE parameter. The argument must be greater
than 0 and less than or equal to the number of files specified on the file
parameter. The partition function returns a 4-byte binary number (*BIN4) with
10 total decimal digits and no fraction digits. The returned value will be
the partition number of the record. <p>If the argument identifies a non-distributed
file then a value of zero will be returned.</p>
<p>Find the PARTITION number
for every row of the EMPLOYEE table. This can be used to determine if there
is data skew.</p>
<div class="p">Example:<pre>OPNQRYF FILE((CORPDATA/EMPLOYEE))
FORMAT(FNAME)
MAPFLD((PART1 '%PARTITION(1)'))</pre>
</div>
<p>Select the employee
number (EMPNO) from the EMPLOYEE table for all records where the partition
number is equal to 100.</p>
<div class="p">Example:<pre>OPNQRYF
FILE((EMPLOYEE))
QRYSLT('%PARTITION(1) *EQ 100')</pre>
</div>
<p>Join the EMPLOYEE and
DEPARTMENT tables, select all records of the result where the records of the
two tables have the same partition number</p>
<div class="p">Example:<pre>OPNQRYF
FILE((CORPDATA/EMPLOYEE) (CORPDATA/DEPARTMENT))
FORMAT(FNAME)
JFLD((1/PART1 2/PART2 *EQ))
MAPFLD((PART1 '%PARTITION(1)')
(PART2 '%PARTITION(2)'))</pre>
</div>
</dd>
<dt class="dlterm">%SECOND (date/time-argument)</dt>
<dd>%SECOND accepts a date/time argument and returns the seconds part of the
value. The date/time argument can be a time or timestamp field, a time duration
or timestamp duration (either field or literal), or a numeric field or literal.
The returned value is of type *BIN4. <p>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.</p>
</dd>
<dt class="dlterm">%SIN (numeric-argument)</dt>
<dd>%SIN accepts a numeric argument and returns the sine of the argument.
The argument must be specified in radians. %SIN and %ASIN are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%SINH (numeric-argument)</dt>
<dd>%SINH accepts a numeric argument and returns the hyperbolic sine of the
argument. The argument must be specified in radians. <p>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).</p>
</dd>
<dt class="dlterm">%SQRT (numeric-argument)</dt>
<dd>%SQRT accepts a numeric argument and returns the square root of the argument. <p>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).</p>
</dd>
<dt class="dlterm">%SST (string-argument start-position-expression &lt;length-expression&gt;)</dt>
<dd>%SST and %SUBSTRING accept a character, hexadecimal, DBCS, or graphic
string, a starting position expression, and an optional length expression
as arguments. They return a substring of the string argument that is of the
same type and CCSID as the string argument and has length equal to the value
specified by the length-expression.<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>If an argument
is DBCS-graphic, the second and third arguments must also be specified as
DBCS-graphic characters, not bytes.</p>
<p>If an expression is given for the
second or third arguments, the expression must be enclosed in parentheses.</p>
<p>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.</p>
<p>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.</p>
<div class="p">The user can omit the third argument. If
the third argument is not specified and the first argument is:<ul><li>fixed-length, the default value for the third argument is LENGTH(argument_1)
- value_for_argument_2 + 1</li>
<li>variable-length, the default value for the third argument is the maximum
of 0 and LENGTH(argument_1) - value_for_argument_2 + 1</li>
<li>variable-length with a length less than the value for argument_2, the
default value for the third argument is zero and the result is the empty string.</li>
</ul>
</div>
<div class="p">Example:<pre>OPNQRYF
FILE(library/file)
QRYSLT('field1 =
%SST(field2 (numfld1+3)
(numfld1+numfld2))')</pre>
</div>
</dd>
<dt class="dlterm">%STDDEV (numeric-argument)</dt>
<dd>%STRIP accepts a character-, DBCS-, or graphic- string argument, an optional
strip character, and an optional strip function as arguments. It returns a
result string with the strip character removed from the string argument as
specified by the strip function. <p>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.</p>
<p>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.</p>
<div class="p">The strip function can be one
of three functions:<dl><dt class="dlterm">*LEAD</dt>
<dd>Remove leading strip character(s)</dd>
<dt class="dlterm">*TRAIL</dt>
<dd>Remove trailing strip character(s)</dd>
<dt class="dlterm">*BOTH</dt>
<dd>Remove both leading and trailing strip character(s)</dd>
</dl>
</div>
<p>The default strip function is *BOTH.</p>
<div class="p">Example:<pre>OPNQRYF
FILE(library/file)
QRYSLT('%STRIP(fld '.' *TRAIL) = 'Mr')</pre>
</div>
</dd>
<dt class="dlterm">%SUBSTRING (string-field-name start-position length)</dt>
<dd><p>%SUBSTRING performs the same operation as %SST. See the %SST description
for more information.</p>
</dd>
<dt class="dlterm">%SUM (numeric-argument)</dt>
<dd>%SUM accepts a numeric argument and returns the sum of all the values
for its argument in the group of records defined on the GRPFLD parameter and
must be enclosed in parentheses. The argument must be a field name or an expression
(not a literal).<div class="p">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,<ul><li>If the argument is floating-point number, the returned value is a double-precision
floating-point number (*FLT8).</li>
<li>If the argument is a binary number with zero-precision, the returned value
is *BIN4.</li>
<li>If the argument is a binary number with nonzero precision or a fixed-point
number, the returned value is a packed decimal number (*DEC) with 31 total
digits and as many fractional digits as the argument.</li>
<li>If the argument is of type date duration, time duration, or timestamp
duration, the returned value is a double-precision floating-point number (*FLT8).</li>
</ul>
</div>
<p>%SUM is an aggregate function that is used for a nongrouping field
in a query that uses the grouping function.</p>
</dd>
<dt class="dlterm">%TAN (numeric-argument)</dt>
<dd>%TAN accepts a numeric argument and returns the tangent of the argument.
The argument must be specified in radians. %TAN and %ATAN are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%TANH (numeric-argument)</dt>
<dd>%TAN accepts a numeric argument and returns the hyperbolic tangent of
the argument. The argument must be specified in radians. %TANH and %ATANH
are inverse operations. <p>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).</p>
</dd>
<dt class="dlterm">%TIME (date/time-argument)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%TIMESTP (date/time-argument date/time-argument)</dt>
<dd>%TIMESTP accepts one or two date/time arguments and returns a timestamp. <ul><li>If only one date/time argument is specified, it must be a timestamp (field
or literal), or a character or hexadecimal field containing the external form
of a timestamp.</li>
<li>If both arguments are specified, <ol><li>The first date/time argument must be a date (field or literal), or a character
or hexadecimal field containing the external form of a date.</li>
<li>The second date/time argument must be a time (field or literal), or a
character or hexadecimal field containing the external form of a time.</li>
</ol>
</li>
</ul>
<p>The returned value is of type *TIMESTP.</p>
</dd>
<dt class="dlterm">%USER</dt>
<dd>%USER does not support any arguments. It returns the user profile name
of the job in which the query is running. The returned value is of type variable-length
character (*VCHAR) with a maximum length of 18. <div class="p">Example:<pre>OPNQRYF
FILE(library/file)
QRYSLT('field = %USER')</pre>
</div>
</dd>
<dt class="dlterm">%VAR (numeric-argument)</dt>
<dd>%VAR accepts a numeric argument and returns the variance of its argument
for the group of records defined by the GRPFLD parameter. The argument must
be a field name or an expression (not a literal). <p>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.</p>
</dd>
<dt class="dlterm">%XLATE (string-argument qualified-table)</dt>
<dd>%XLATE accepts a character-string argument and the name of a table object
(*TBL), and returns a string that is the value of the first argument translated
by using the contents of the table. The returned value is a string with the
same length and CCSID as the first argument. <p>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.</p>
</dd>
<dt class="dlterm">%XOR (string-argument...)</dt>
<dd><p>%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.</p>
</dd>
<dt class="dlterm">%YEAR</dt>
<dd>%YEAR accepts a date/time argument and returns the year part of the value.
The date/time argument can be a date or timestamp field, a date duration or
timestamp duration (field or literal), or a numeric field or literal. The
returned value is of type *BIN4.<p>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.</p>
</dd>
</dl>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafoopnqf.htm" title="The Open Query File (OPNQRYF) command is a control language (CL) command that allows you to perform many data processing functions on database files. These topics discuss how to create a query using the OPNQRYF command, how to specify parameters for its major functions, and how to use it with your high-level language program.">Use Open Query File (OPNQRYF) command</a></div>
</div>
</div>
<img src="./deltaend.gif" alt="End of change" /></body>
</html>