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

275 lines
16 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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="Expressions" />
<meta name="abstract" content="This topic discusses the conventions for the expressions specified on the Open Query File (OPNQRYF) command." />
<meta name="description" content="This topic discusses the conventions for the expressions specified on the Open Query File (OPNQRYF) command." />
<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="rbafoexpressions.dita" />
<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>Expressions</title>
</head>
<body id="rbafoexpressions.dita"><a name="rbafoexpressions.dita"><!-- --></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">Expressions</h1>
<div><p>This topic discusses the conventions for the expressions specified
on the Open Query File (OPNQRYF) command.</p>
<div class="section"><p>Expressions specified on the QRYSLT, GRPSLT, and MAPFLD parameters
are similar to expressions specified on other control language (CL) command
parameters. Logical, relational, numeric, and string operations are performed
by using combinations of field values and constants. Symbolic and named operators
are supported, as well as many built-in functions, and parentheses are used
to control the order of evaluation.</p>
<div class="p">There are also differences in the
expressions specified on OPNQRYF parameters and on other CL command parameters.
Listed here are the ways that expressions on the QRYSLT, GRPSLT,
and MAPFLD parameters differ from normal CL expressions:<ul><li>The expression string must be enclosed in apostrophes if it contains embedded
blanks or special characters.</li>
<li>The following differences affect numeric and string literals: <ul><li>Character string constants are quoted by using single quotation marks
or quotation marks.</li>
<li>The leading and trailing zeros of a numeric constant are significant parts
of its attributes.</li>
<li>Floating-point constants (including the special values *INF and *NEGINF)
are used in expressions.</li>
</ul>
</li>
<li>The following differences contrast CL variables with database fields: <ul><li>No prefixed ampersand (&amp;) is used in database field names.</li>
<li>Qualified field names are supported.</li>
<li>No 'logical' field type exists for database fields.</li>
<li>Many additional data types are supported for database fields.</li>
</ul>
</li>
<li>The following CL operators are not supported on the OPNQRYF command: <ul><li>*BCAT or | &gt;</li>
<li>*TCAT or | &lt;</li>
</ul>
</li>
<li>The following additional operators are supported beyond CL support: <ul><li>// for remainder</li>
<li>** for exponentiation</li>
<li>*CT for 'contains' (character scan)</li>
<li>*XOR or &amp;&amp; for 'logical exclusive or'</li>
</ul>
</li>
<li>The following differences affect built-in function support: <ul><li>The %SWITCH built-in function is not supported.</li>
<li>Many additional built-in functions are supported.</li>
<li>Nested built-in functions and expressions for built-in function arguments
(such as '%LOG(%SIN(x))') generally are allowed.</li>
<li>To support expressions as built-in function arguments, any argument that
is a signed numeric value or an expression (for example, '%MIN(3 (-2) x (y+4))')
must be enclosed in parentheses.</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="section"><div class="p">The following table shows the priority of all operators that are
used for expressions on the QRYSLT, GRPSLT, or MAPFLD parameters. Only operators
listed for priorities 1 through 5, excluding the *NOT and operators, are allowed
in an expression specified on the MAPFLD parameter:
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="border" border="1" rules="all"><thead align="left"><tr valign="bottom"><th valign="bottom" width="17.17171717171717%" id="d0e78"> Priority</th>
<th valign="bottom" width="82.82828282828282%" id="d0e80"> Operators</th>
</tr>
</thead>
<tbody><tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 1</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> +, - (when used for signed numeric values), *NOT, ¬</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 2</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> **</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 3</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> *, / ,// (a / must have a space before the / and/or
after the /)</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 4</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> +, - (when used between two operands)</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 5</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> *CAT, | |</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 6</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> *GT, *LT, *EQ, *GE, *LE, *NE, *NG, *NL, *CT, &gt;, &lt;,
=, &gt;=, &lt;=, ¬=, ¬&gt;, ¬&lt;</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 7</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> *AND, &amp;</td>
</tr>
<tr><td valign="top" width="17.17171717171717%" headers="d0e78 "> 8</td>
<td valign="top" width="82.82828282828282%" headers="d0e80 "> *OR, *XOR, |, &amp;&amp;</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Except for operators ¬ and *NOT, the operators for priorities
1 through 4 are numeric operators, which require numeric operands. The operators
for priority 5 are string operators, which require operands to be either character
or DBCS strings. Priority 6 operators are called relational operators, which
require at least one operand that is a field name or a numeric or string expression
(not a constant). The operators for priorities 7 and 8, plus the ¬ and *NOT
operators (priority 1), are logical operators. The operands in a logical expression
are relations (constructed by using a relational operator with appropriate
operands) and other logical expressions.</p>
</div>
<div class="section"><p>The operands in a string expression, including string operands
for a built-in function, are a combination of character fields and DBCS fields
and constants. If both operands of such an expression are DBCS-only fields
or constants, the final result from evaluation of the expression is a DBCS-only
field value. If the operands are a combination of DBCS or character fields
or constants, the result is a DBCS-open field value. When DBCS fields are
concatenated, the extraneous shift-in and shift-out characters between the
fields are removed.</p>
<p>The result produced by a + or - sign prefixed operator
has the same attributes as the operand, unless the operand of a - sign prefixed
operator is a *BIN2, in which case the result is a *BIN4. The result of an
** operator (exponentiation) is a double-precision floating-point number (*FLT8).
For other numeric operators that require two operands, if either operand is
a floating-point number, the result is a double-precision floating point number
(*FLT8). If both operands are fixed-point numbers, the system uses the information
in the following table to determine the number of total and fractional digits
required to produce a packed decimal (*DEC) result. If both operands are zero-precision
binary fields and/or integer constants, the result is a *BIN4, unless the
operator is a "/". In that case, the result is the same as for a fixed-point
result. If the total number of digits required exceeds 31, the number of fraction
digits is reduced enough to enable calculation of the result with a total
of 31 digits. If some fraction digits are dropped and the attributes of the
end result of the computation (the attributes specified on the MAPFLD parameter
for the field) require greater precision than that of the intermediate result,
a warning message is sent to indicate that some precision was lost in evaluating
the expression.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr valign="bottom"><th valign="bottom" id="d0e137">Operation</th>
<th valign="bottom" id="d0e139">Result (Total Digits)</th>
<th valign="bottom" id="d0e141">Result (Fractional Digits)</th>
</tr>
</thead>
<tbody><tr><td valign="top" headers="d0e137 ">+</td>
<td valign="top" headers="d0e139 ">MAX(d1-f1, d2-f2)+MAX(f1,f2)+1</td>
<td valign="top" headers="d0e141 ">MAX(f1, f2)</td>
</tr>
<tr><td valign="top" headers="d0e137 ">_</td>
<td valign="top" headers="d0e139 ">MAX (d1-f1, d2-f2)+MAX (f1,f2)+1</td>
<td valign="top" headers="d0e141 ">MAX(f1, f2)</td>
</tr>
<tr><td valign="top" headers="d0e137 ">*</td>
<td valign="top" headers="d0e139 ">d1+d2</td>
<td valign="top" headers="d0e141 ">f1+f2</td>
</tr>
<tr><td valign="top" headers="d0e137 ">/</td>
<td valign="top" headers="d0e139 ">31</td>
<td valign="top" headers="d0e141 ">31-(d1-f1+f2)</td>
</tr>
<tr><td valign="top" headers="d0e137 ">//</td>
<td valign="top" headers="d0e139 ">MIN(d1-f1,d2-f2)+MAX(f1,f2)</td>
<td valign="top" headers="d0e141 ">MAX(f1,f2)</td>
</tr>
<tr><td colspan="3" valign="top" headers="d0e137 d0e139 d0e141 ">Legend:<dl><dt class="dlterm">d1</dt>
<dd>Total digits in operand 1</dd>
<dt class="dlterm">f1</dt>
<dd>Fractional digits in operand 1</dd>
<dt class="dlterm">d2</dt>
<dd>Total digits in operand 2</dd>
<dt class="dlterm">f2</dt>
<dd>Fractional digits in operand 2</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><p>When a numeric or string expression is specified on the MAPFLD
parameter, the attributes of the final result are used in one of the two ways.
They are either used directly for the field value (if field-type *CALC is
specified and the field is not contained in the prototype record format identified
on the FORMAT parameter), or the final result is changed to match the attributes
specified on the MAPFLD parameter or contained in the field definition in
the record format identified by the FORMAT parameter.</p>
<p>Both operands
of a relational operator can be constants. The fields, constants, or expressions
specified as operands on the left and right side of a relational operator
must be of the same type, either numeric or string. Any combination of character
and DBCS field operands are allowed except that a character field cannot be
related to a DBCS-only field.</p>
<p>There are two types of DBCS constants:
DBCS-only and DBCS-open. A DBCS-only constant has only DBCS data between its
single quotation marks. This data must be enclosed in SO/SI characters. A
DBCS-open constant has a mixture of DBCS and alphameric data. An SO character
(HEX 0E) indicates the start of a group of DBCS characters and an SI character
(HEX 0F) follows the last double-byte character of the group.</p>
<p>If a numeric
or string expression appears as a complex selection operand on the QRYSLT
or GRPSLT parameter, the attributes of the final result of the expression
used for the selection operand are changed to match the other relational operand.</p>
<p>It
is not necessary for operands of a relational operator to have identical attributes,
but numeric operands cannot be mixed with character operands. If the operands
do not have identical attributes, the system changes them to identical attributes
(except for the *CT operator, where the character string operands might be
of different lengths), before performing the operation. This change uses packed
decimal format if both operands are fixed-point numeric operands, or floating-point
format if either operand is a floating-point number. The changes for fixed-point
numeric operands align their decimal points and pad them with zeros. Numeric
type changes 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 operands are changed by padding the shorter operand with blanks.</p>
<p>The
*CT operator performs a scan of the character field or string expression (except
for expressions made up of a single character string literal) that must be
specified as the left side of the relation, in order to determine if it contains
the character string, field, or expression value specified as the right side
of the relation. The second operand (the search value) must be no longer than
the first operand (the base string).</p>
<div class="p">If the string is found, the relation
is satisfied and the result is a logical value of 'true'; otherwise, the result
is a logical 'false' value. The following example illustrates this process: <ul><li>Field BASEFLD contains the value 'THIS IS A TEST'.</li>
<li>Field TESTFLD contains the value 'TE'.</li>
</ul>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr valign="bottom"><th valign="bottom" width="71.7948717948718%" id="d0e229">Expression</th>
<th valign="bottom" width="28.205128205128204%" id="d0e231">Result</th>
</tr>
</thead>
<tbody><tr><td valign="top" width="71.7948717948718%" headers="d0e229 ">'BASEFLD *CT ''IS A'''</td>
<td valign="top" width="28.205128205128204%" headers="d0e231 ">True </td>
</tr>
<tr><td valign="top" width="71.7948717948718%" headers="d0e229 ">'BASEFLD *CT TESTFLD</td>
<td valign="top" width="28.205128205128204%" headers="d0e231 ">True</td>
</tr>
<tr><td valign="top" width="71.7948717948718%" headers="d0e229 ">'BASEFLD *CT ''X'''</td>
<td valign="top" width="28.205128205128204%" headers="d0e231 ">False</td>
</tr>
<tr><td valign="top" width="71.7948717948718%" headers="d0e229 ">'BASEFLD *CT TESTFLD | | ''Z'''</td>
<td valign="top" width="28.205128205128204%" headers="d0e231 ">False</td>
</tr>
<tr><td valign="top" width="71.7948717948718%" headers="d0e229 ">'BASEFLD | | ''ABC'' *CT ''TAB'''</td>
<td valign="top" width="28.205128205128204%" headers="d0e231 ">True</td>
</tr>
</tbody>
</table>
</div>
</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>