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

109 lines
6.1 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="Example 1: Define fields derived from existing field definitions" />
<meta name="abstract" content="This example shows the use of derived fields." />
<meta name="description" content="This example shows the use of derived fields." />
<meta name="DC.Relation" scheme="URI" content="rbafofdefd.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="rbafofdefdex1" />
<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 1: Define fields derived from existing field definitions</title>
</head>
<body id="rbafofdefdex1"><a name="rbafofdefdex1"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example 1: Define fields derived from existing field definitions</h1>
<div><p>This example shows the use of derived fields.</p>
<div class="section"><p>Assume that you have the <em>Price</em> and <em>Qty</em> fields in
the record format. You can multiply one field by the other by using the Open
Query File (OPNQRYF) command to create the derived <em>Exten</em> field. You
want FILEA to be processed, and you have already created FILEAA. Assume that
the record formats for the files contain the following fields:</p>
</div>
<table cellpadding="4" cellspacing="0" border="1" class="tableborder"><tr><td>
<table cellpadding="4" cellspacing="0" summary="" width="100%" border="0"><thead align="left"><tr><th align="left" valign="bottom" width="50%" id="d0e30">FILEA</th>
<th align="left" valign="bottom" width="50%" id="d0e32">FILEAA</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="50%" headers="d0e30 ">Order</td>
<td align="left" valign="top" width="50%" headers="d0e32 ">Order</td>
</tr>
<tr><td align="left" valign="top" width="50%" headers="d0e30 ">Item</td>
<td align="left" valign="top" width="50%" headers="d0e32 ">Item</td>
</tr>
<tr><td align="left" valign="top" width="50%" headers="d0e30 ">Qty</td>
<td align="left" valign="top" width="50%" headers="d0e32 ">Exten</td>
</tr>
<tr><td align="left" valign="top" width="50%" headers="d0e30 ">Price</td>
<td align="left" valign="top" width="50%" headers="d0e32 ">Brfdsc</td>
</tr>
<tr><td align="left" valign="top" width="50%" headers="d0e30 ">Descrp</td>
<td valign="top" width="50%" headers="d0e32 ">&nbsp;</td>
</tr>
</tbody>
</table>
</td></tr></table>
<div class="section"><p>The <em>Exten</em> field is a mapped field. Its value is determined
by multiplying <em>Qty</em> times <em>Price</em>. It is not necessary to have
either the <em>Qty</em> or <em>Price</em> field in the new format, but they can
exist in that format, too, if you want. The <em>Brfdsc</em> field is a brief
description of the <em>Descrp</em> field (it uses the first 10 characters).</p>
</div>
<div class="section"><div class="p">Assume that you have specified PGMF to process the
new format. To create this program, use FILEAA as the file to read. You can
specify: <pre>OVRDBF FILE(FILEAA) TOFILE(FILEA) SHARE(*YES)
OPNQRYF FILE(FILEA) FORMAT(FILEAA) +
MAPFLD((EXTEN 'PRICE * QTY') +
(BRFDSC 'DESCRP'))
CALL PGM(PGMF) /* Created using file FILEAA as input */
CLOF OPNID(FILEA)
DLTOVR FILE(FILEAA)</pre>
</div>
</div>
<div class="section"><p>Notice that the attributes of the <em>Exten</em> field are those
defined in the record format for FILEAA. If the value calculated for the field
is too large, an exception is sent to the program.</p>
</div>
<div class="section"><p>It is not necessary to use the substring function to map to the <em>Brfdsc</em> field
if you only want the characters from the beginning of the field. The length
of the <em>Brfdsc</em> field is defined in the FILEAA record format.</p>
</div>
<div class="section"><div class="p">All fields in the format specified on the FORMAT parameter must
be described on the OPNQRYF command. That is, all fields in the output format
must either exist in one of the record formats for the files specified on
the FILE parameter or be defined on the MAPFLD parameter. If you have fields
in the format on the FORMAT parameter that your program does not use, you
can use the MAPFLD parameter to place zeros or blanks in the fields. Assume
the <em>Fldc</em> field is a character field and the <em>Fldn</em> field is a
numeric field in the output format, and you are using neither value in your
program. You can avoid an error on the OPNQRYF command by specifying: <pre>MAPFLD((FLDC ' " " ')(FLDN 0))</pre>
</div>
</div>
<div class="section"><p>Notice quotation marks enclose a blank value. By using a constant
for the definition of an unused field, you avoid having to create a unique
format for each use of the OPNQRYF command.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafofdefd.htm" title="Listed here are the operations allowed by defining fields derived from existing field definitions.">Define fields derived from existing field definitions</a></div>
</div>
</div>
</body>
</html>