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

125 lines
7.1 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="Example 8: Select records using the Open Query File (OPNQRYF) command" />
<meta name="abstract" content="This example shows the wildcard function of the Open Query File (OPNQRYF) command." />
<meta name="description" content="This example shows the wildcard function of the Open Query File (OPNQRYF) command." />
<meta name="DC.Relation" scheme="URI" content="rbafodynsrsex.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafoappdbcs.htm" />
<meta name="DC.Relation" scheme="URI" content="../rbam6/rbam6clmain.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="rbafodynsrex8" />
<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>Example 8: Select records using the Open Query File (OPNQRYF) command</title>
</head>
<body id="rbafodynsrex8"><a name="rbafodynsrex8"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example 8: Select records using the Open Query File (OPNQRYF) command</h1>
<div><p>This example shows the <span class="q">"wildcard"</span> function of the Open Query
File (OPNQRYF) command.</p>
<div class="section"><div class="p">Assume that you have a packed decimal <em>Date</em> field in the
format MMDDYY and you want to select the records for March 1988. To do this,
you can specify: <pre>OVRDBF FILE(FILEA) SHARE(*YES)
OPNQRYF FILE(FILEA) +
QRYSLT('%DIGITS(DATE) *EQ %WLDCRD("03__88")')
CALL PGM(PGMC)
CLOF OPNID(FILEA)
DLTOVR FILE(FILEA)</pre>
</div>
</div>
<div class="section"><p>Note that the only time the MAPFLD parameter is needed to define
a database field for the result of the %DIGITS function is when the result
needs to be used with a function that only supports a simple field name (not
a function or expression) as an argument. The %WLDCRD operation has no such
restriction on the operand that appears before the *EQ operator.</p>
</div>
<div class="section"><p>Note that although the field in the database is in numeric form,
quotation marks surround the literal to make its definition the same as the <em>Char6</em> field.
The wildcard function is not supported for DATE, TIME, or TIMESTAMP data types.</p>
</div>
<div class="section"><p>The %WLDCRD function lets you select any records that match your
selection values, in which the underline (_) will match any single character
value. The two underline characters in Example 8 allow any day in the month
of March to be selected. The %WLDCRD function also allows you to name the
wild card character (underline is the default).</p>
</div>
<div class="section"><div class="p">The wild card function supports two different forms: <ul><li>A fixed-position wild card as shown in the previous example in which the
underline (or your designated character) matches any single character as in
this example: <pre>QRYSLT('FLDA *EQ %WLDCRD("A_C")')</pre>
<p>This
compares successfully to ABC, ACC, ADC, AxC, and so on. In this example, the
field being analyzed only compares correctly if it is exactly 3 characters
in length. If the field is longer than 3 characters, you also need the second
form of wild card support.</p>
</li>
<li>A variable-position wild card matches any zero or more characters. The
Open Query File (OPNQRYF) command uses an asterisk (*) for this type of wild
card variable character or you can specify your own character. An asterisk
is used in this example: <pre>QRYSLT('FLDB *EQ %WLDCRD("A*C*") ')</pre>
<p>This
compares successfully to AC, ABC, AxC, ABCD, AxxxxxxxC, and so on. The asterisk
causes the command to ignore any intervening characters if they exist. Notice
that in this example the asterisk is specified both before and after the character
or characters that can appear later in the field. If the asterisk is omitted
from the end of the search argument, it causes a selection only if the field
ends with the character C.</p>
<p>You must specify an asterisk at the start
of the wild card string if you want to select records where the remainder
of the pattern starts anywhere in the field. Similarly, the pattern string
must end with an asterisk if you want to select records where the remainder
of the pattern ends anywhere in the field.</p>
<div class="p">For example, you can specify: <pre>QRYSLT('FLDB *EQ %WLDCRD("*ABC*DEF*") ')</pre>
</div>
<p>You get a match on ABCDEF, ABCxDEF, ABCxDEFx, ABCxxxxxxDEF, ABCxxxDEFxxx,
xABCDEF, xABCxDEFx, and so on.</p>
</li>
</ul>
</div>
</div>
<div class="section"><div class="p">You can combine the two wildcard functions as shown in this example: <pre>QRYSLT('FLDB *EQ %WLDCRD("ABC_*DEF*") ')</pre>
</div>
</div>
<div class="section"><p>You get a match on ABCxDEF, ABCxxxxxxDEF, ABCxxxDEFxxx, and so
on. The underline forces at least one character to appear between the ABC
and DEF (for example, ABCDEF would not match).</p>
</div>
<div class="section"><div class="p">Assume that you have a <em>Name</em> field that contains: <ul><li>JOHNS</li>
<li>JOHNS SMITH</li>
<li>JOHNSON</li>
<li>JOHNSTON</li>
</ul>
You only gets the first record if you specify:<pre>QRYSLT('NAME *EQ "JOHNS"')</pre>
</div>
</div>
<div class="section"><div class="p">You would not select the other records because a comparison is
made with blanks added to the value you specified. The way to select all four
names is to specify: <pre>QRYSLT('NAME *EQ %WLDCRD("JOHNS*")')</pre>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafodynsrsex.htm" title="These topics provide examples of selecting records using the Open Query File (OPNQRYF) command.">Select records using the Open Query File (OPNQRYF) command</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rbafoappdbcs.htm" title="These topics describe double-byte character set (DBCS) considerations as they apply to the database on the iSeries system.">Double-byte character set considerations</a></div>
<div><a href="../rbam6/rbam6clmain.htm">Control language (CL)</a></div>
</div>
</div>
</body>
</html>