ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/rfmlcompare.htm

129 lines
7.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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: Using RFML compared to using IBM Toolbox for Java Record classes" />
<meta name="abstract" content="This example illustrates the differences between using RFML and using the IBM Toolbox for Java Record classes." />
<meta name="description" content="This example illustrates the differences between using RFML and using the IBM Toolbox for Java Record classes." />
<meta name="DC.Relation" scheme="URI" content="rfmlmain.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rfmlcompare" />
<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: Using RFML compared to using IBM Toolbox for Java Record classes</title>
</head>
<body id="rfmlcompare"><a name="rfmlcompare"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using RFML compared to using IBM Toolbox for Java Record classes</h1>
<div><p>This example illustrates the differences between using RFML and
using the IBM<sup>®</sup> Toolbox
for Java™ Record
classes. </p>
<div class="section"><p> </p>
</div>
<div class="section"><p>Using the traditional Record classes, you interweave the data
format specifications with the business logic of your application. Adding,
changing, or deleting a field means that you must edit and recompile your Java code.
However, using RFML isolates the data format specifications into RFML source
files that are entirely separate from the business logic. Accommodating field
changes means modifying the RFML file, often without having to change or recompile
your Java application.</p>
</div>
<div class="section"><p> The example assumes that your application deals with customer
records, which you have defined in an <a href="rfmlexqcustcdt.htm#rfmlexqcustcdt">RFML
source file</a> and named qcustcdt.rfml. The source file represents the
fields that compose each customer record.</p>
</div>
<div class="section"><p>The listing below shows how a Java application might interpret a customer
record using the IBM Toolbox for Java Record, RecordFormat, and FieldDescription
classes: </p>
</div>
<div class="section"><div class="p"><pre>// Buffer containing the binary representation of one record of information.
byte[] bytes;
// ... Read the record data into the buffer ...
// Set up a RecordFormat object to represent one customer record.
RecordFormat recFmt1 = new RecordFormat("cusrec");
recFmt1.addFieldDescription(new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6, 0), "cusnum"));
recFmt1.addFieldDescription(new CharacterFieldDescription(new AS400Text(8, 37), "lstnam"));
recFmt1.addFieldDescription(new CharacterFieldDescription(new AS400Text(3, 37), "init"));
recFmt1.addFieldDescription(new CharacterFieldDescription(new AS400Text(13, 37), "street"));
recFmt1.addFieldDescription(new CharacterFieldDescription(new AS400Text(6, 37), "city"));
recFmt1.addFieldDescription(new CharacterFieldDescription(new AS400Text(2, 37), "state"));
recFmt1.addFieldDescription(new ZonedDecimalFieldDescription(new AS400ZonedDecimal(5, 0), "zipcod"));
recFmt1.addFieldDescription(new ZonedDecimalFieldDescription(new AS400ZonedDecimal(4, 0), "cdtlmt"));
recFmt1.addFieldDescription(new ZonedDecimalFieldDescription(new AS400ZonedDecimal(1, 0), "chgcod"));
recFmt1.addFieldDescription(new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6, 2), "baldue"));
recFmt1.addFieldDescription(new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6, 2), "cdtdue"));
// Read the byte buffer into the RecordFormatDocument object.
Record rec1 = new Record(recFmt1, bytes);
// Get the field values.
System.out.println("cusnum: " + rec1.getField("cusnum"));
System.out.println("lstnam: " + rec1.getField("lstnam"));
System.out.println("init: " + rec1.getField("init"));
System.out.println("street: " + rec1.getField("street"));
System.out.println("city: " + rec1.getField("city"));
System.out.println("state: " + rec1.getField("state"));
System.out.println("zipcod: " + rec1.getField("zipcod"));
System.out.println("cdtlmt: " + rec1.getField("cdtlmt"));
System.out.println("chgcod: " + rec1.getField("chgcod"));
System.out.println("baldue: " + rec1.getField("baldue"));
System.out.println("cdtdue: " + rec1.getField("cdtdue"));</pre>
</div>
</div>
<div class="section"><p>By comparison, here is how the same record might be interpreted
using RFML.</p>
</div>
<div class="section"><p>The Java code to interpret the contents of the customer
data record using RFML might look like this: </p>
</div>
<div class="section"><div class="p"><p><tt>    // Buffer containing the binary representation of one record of information.<br />
    byte[] bytes;<br />
<br />
    // ... Read the record data into the buffer ...<br />
<br />
    // Parse the RFML file into a RecordFormatDocument object.<br />
    // The RFML source file is called <a href="rfmlexqcustcdt.htm#rfmlexqcustcdt">qcustcdt.rfml</a>.<br />
    RecordFormatDocument rfml1 = new RecordFormatDocument("qcustcdt");<br />
<br />
    // Read the byte buffer into the RecordFormatDocument object.<br />
    rfml1.setValues("cusrec", bytes);<br />
<br />
    // Get the field values.<br />
    System.out.println("cusnum: " + rfml1.getValue("cusrec.cusnum"));<br />
    System.out.println("lstnam: " + rfml1.getValue("cusrec.lstnam"));<br />
    System.out.println("init:   " + rfml1.getValue("cusrec.init"));<br />
    System.out.println("street: " + rfml1.getValue("cusrec.street"));<br />
    System.out.println("city:   " + rfml1.getValue("cusrec.city"));<br />
    System.out.println("state:  " + rfml1.getValue("cusrec.state"));<br />
    System.out.println("zipcod: " + rfml1.getValue("cusrec.zipcod"));<br />
    System.out.println("cdtlmt: " + rfml1.getValue("cusrec.cdtlmt"));<br />
    System.out.println("chgcod: " + rfml1.getValue("cusrec.chgcod"));<br />
    System.out.println("baldue: " + rfml1.getValue("cusrec.baldue"));<br />
    System.out.println("cdtdue: " + rfml1.getValue("cusrec.cdtdue"));</tt></p>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rfmlmain.htm" title="The Record Format Markup Language (RFML) is an XML extension for specifying record formats.">Record Format Markup Language</a></div>
</div>
</div>
</body>
</html>