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

111 lines
6.1 KiB
HTML
Raw 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="Example 2: Select records using the Open Query File (OPNQRYF) command" />
<meta name="abstract" content="This example shows how to select records with a specific date value using the Open Query File (OPNQRYF) command." />
<meta name="description" content="This example shows how to select records with a specific date value using the Open Query File (OPNQRYF) command." />
<meta name="DC.Relation" scheme="URI" content="rbafodynsrsex.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="rbafodynsrex2" />
<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 2: Select records using the Open Query File (OPNQRYF) command</title>
</head>
<body id="rbafodynsrex2"><a name="rbafodynsrex2"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example 2: Select records using the Open Query File (OPNQRYF) command</h1>
<div><p>This example shows how to select records with a specific date value
using the Open Query File (OPNQRYF) command.</p>
<div class="section"><div class="p">Assume that you want to process all records in which the <em>Date</em> field
in the record is the same as the current date. Also assume that the <em>Date</em> field
is in the same format as the system date. In a control language (CL) program,
you can specify: <pre>DCL VAR(&amp;CURDAT); TYPE(*CHAR) LEN(6)
RTVSYSVAL SYSVAL(QDATE) RTNVAR(&amp;CURDAT);
OVRDBF FILE(FILEA) SHARE(*YES)
OPNQRYF FILE(FILEA) QRYSLT('"' *CAT &amp;CURDAT *CAT '" *EQ DATE')
CALL PGM(PGMB)
CLOF OPNID(FILEA)
DLTOVR FILE(FILEA)</pre>
</div>
</div>
<div class="section"><p>A CL variable is assigned with a leading ampersand (&amp;) and
is not enclosed in single quotation marks. The whole expression is enclosed
in single quotation marks. The CAT operators and CL variable are enclosed
in both single quotation marks and quotation marks.</p>
</div>
<div class="section"><p>It is important to know whether the data in the database is defined
as character, date, time, timestamp, or numeric. In the preceding example,
the <em>Date</em> field is assumed to be character.</p>
</div>
<div class="section"><div class="p">If the <em>DATE</em> field is defined as date data type, the preceding
example can be specified as: <pre>OVRDBF FILE(FILEA) SHARE(*YES)
OPNQRYF FILE(FILEA) QRYSLT('%CURDATE *EQ DATE')
CALL PGM(PGMB)
CLOF OPENID(FILEA)
DLTOVR FILE(FILEA)</pre>
<div class="note"><span class="notetitle">Note:</span> The date field does not have to have the
same format as the system date.</div>
You can also specify the example as: <pre>DCL VAR(&amp;CVTDAT); TYPE(*CHAR) LEN(6)
DCL VAR(&amp;CURDAT); TYPE(*CHAR) LEN(8)
RTVSYSVAL SYSVAL(QDATE) RTNVAR(&amp;CVTDAT);
CVTDAT DATE(&amp;CVTDAT); TOVAR(&amp;CURDAT); TOSEP(/)
OVRDBF FILE(FILEA) SHARE(*YES)
OPNQRYF FILE(FILEA)
QRYSLT('"' *CAT &amp;CURDAT *CAT '" *EQ DATE')
CALL PGM(PGMB)
CLOF OPNID (FILEA)
DLTOVR FILE(FILEA)</pre>
</div>
</div>
<div class="section"><div class="p">This is where <em>DATE</em> has a date data type in FILEA, the job
default date format is MMDDYY, and the job default date separator is the slash
(/). <div class="note"><span class="notetitle">Note:</span> For any character representation of a date in one of the following
formats, MMDDYY, DDMMYY, YYMMDD, or Julian, the job default date format and
separator must be the same to be recognized.</div>
</div>
</div>
<div class="section"><div class="p">If, instead, you were using a constant, the QRYSLT would be specified
as follows: <pre>QRYSLT('"12/31/87" *EQ DATE')</pre>
The job default
date format must be MMDDYY and the job default separator must be the slash
(/).</div>
</div>
<div class="section"><div class="p">If a numeric field exists in the database and you want to compare
it to a variable, only a character variable can be used. For example, to select
all records where a packed <em>Date</em> field is greater than a variable, you
must ensure that the variable is in character form. Normally, this means
that before the OPNQRYF command, you use the Change Variable (CHGVAR) command
to change the variable from a decimal field to a character field. The CHGVAR
command would be specified as follows: <pre>CHGVAR VAR(&amp;CHARVAR); VALUE('123188')</pre>
</div>
</div>
<div class="section"><div class="p">The QRYSLT parameter would be specified as follows (see the difference
from the preceding examples): <pre>QRYSLT(&amp;CHARVAR *CAT ' *GT DATE')</pre>
</div>
</div>
<div class="section"><div class="p">If, instead, you were using a constant, the QRYSLT statement would
be specified as follows: <pre>QRYSLT('123187 *GT DATE')</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>
</body>
</html>