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

183 lines
8.9 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="Creating and deleting files and members" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<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="rlacrt" />
<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>Creating and deleting files and members</title>
</head>
<body id="rlacrt"><a name="rlacrt"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Creating and deleting files and members</h1>
<div><p></p>
<div class="section"><p>Physical files on the server are <a href="javadoc/com/ibm/as400/access/AS400File.html#CREATE(INT, JAVA.LANG.STRING, JAVA.LANG.STRING)"> created</a> by specifying a record length,
an existing server data description specifications (DDS) source file, or a
RecordFormat object.</p>
</div>
<div class="section"><p>When you create a file and specify a record length, a data file
or a source file can be created. The method sets the record format for the
object. Do not call the setRecordFormat() method for the object.</p>
</div>
<div class="section"><p>A data file has one field. The field name is the name of the file,
the field type is of type character, and the field length is the length that
is specified on the create method.</p>
</div>
<div class="section"><p>A source file has three fields:</p>
</div>
<div class="section"><ul><li>Field SRCSEQ is ZONED DECIMAL (6,2)</li>
<li>Field SRCDAT is ZONED DECIMAL (6,0)</li>
<li>SRCDTA is a character field with a length that is the length specified
on the create method minus 12</li>
</ul>
</div>
<div class="section"><p>The following examples show how to create files and members.</p>
</div>
<div class="section"><p><strong>Example 1:</strong> To create a data file with a 128-byte record:</p>
</div>
<div class="section"><div class="p"><pre> // Create an AS400 object, the file
// will be created on this server.
AS400 sys = new AS400("mySystem.myCompany.com");
// Create a file object that represents the file
SequentialFile newFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR");
// Create the file
newFile.create(128, "*DATA", "Data file with a 128 byte record");
// Open the file for writing only.
// Note: The record format for the file
// has already been set by create()
newFile.open(AS400File.WRITE_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
// Write a record to the file. Because the record
// format was set on the create(), getRecordFormat()
// can be called to get a record properly formatted
// for this file.
Record writeRec = newFile.getRecordFormat().getNewRecord();
writeRec.setField(0, "Record one");
newFile.write(writeRec);
....
// Close the file since I am done using it
newFile.close();
// Disconnect since I am done using
// record-level access
sys.disconnectService(AS400.RECORDACCESS);</pre>
</div>
</div>
<div class="section"><p><strong>Example 2:</strong> When creating a file specifying an existing
DDS source file, the DDS source file is specified on the create() method.
The record format for the file must be set using the <a href="javadoc/com/ibm/as400/access/AS400File.html#GETRECORDFORMAT()"> setRecordFormat()</a> method before the file
can be opened. For example:</p>
</div>
<div class="section"><div class="p"><pre> // Create an AS400 object, the
// file will be created on this server.
AS400 sys = new AS400("mySystem.myCompany.com");
// Create QSYSObjectPathName objects for
// both the new file and the DDS file.
QSYSObjectPathName file = new QSYSObjectPathName("MYLIB", "MYFILE", "FILE", "MBR");
QSYSObjectPathName ddsFile = new QSYSObjectPathName("MYLIB", "DDSFILE", "FILE", "MBR");
// Create a file object that represents the file
SequentialFile newFile = new SequentialFile(sys, file);
// Create the file
newFile.create(ddsFile, "File created using DDSFile description");
// Set the record format for the file
// by retrieving it from the server.
newFile.setRecordFormat(new AS400FileRecordDescription(sys,
newFile.getPath()).retrieveRecordFormat()[0]);
// Open the file for writing
newFile.open(AS400File.WRITE_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
// Write a record to the file. The getRecordFormat()
// method followed by the getNewRecord() method is used to get
// a default record for the file.
Record writeRec = newFile.getRecordFormat().getNewRecord();
newFile.write(writeRec);
....
// Close the file since I am done using it
newFile.close();
// Disconnect since I am done using
// record-level access
sys.disconnectService(AS400.RECORDACCESS);</pre>
</div>
</div>
<div class="section"><p><strong>Example 3:</strong> When creating a file specifying a RecordFormat
object, the RecordFormat object is specified on the create() method. The method
sets the record format for the object. The setRecordFormat() method must not
be called for the object.</p>
</div>
<div class="section"><div class="p"><pre> // Create an AS400 object, the file will be created
// on this server.
AS400 sys = new AS400("mySystem.myCompany.com");
// Create a file object that represents the file
SequentialFile newFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR");
// Retrieve the record format from an existing file
RecordFormat recordFormat = new AS400FileRecordDescription(sys,
"/QSYS.LIB/MYLIB.LIB/EXISTING.FILE/MBR1.MBR").retrieveRecordFormat()[0];
// Create the file
newFile.create(recordFormat, "File created using record format object");
// Open the file for writing only.
// Note: The record format for the file
// has already been set by create()
newFile.open(AS400File.WRITE_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
// Write a record to the file. The recordFormat
// object is used to get a default record
// properly formatted for the file.
Record writeRec = recordFormat.getNewRecord();
newFile.write(writeRec);
....
// Close the file since I am done using it
newFile.close();
// Disconnect since I am done using
// record-level access
sys.disconnectService(AS400.RECORDACCESS);</pre>
</div>
</div>
<div class="section"><p>When deleting files and members, use these methods:</p>
</div>
<div class="section"><ul><li>Use the <a href="javadoc/com/ibm/as400/access/AS400File.html#DELETE()">delete()</a> method to delete server files and
all of their members.</li>
<li>Use the <a href="javadoc/com/ibm/as400/access/AS400File.html#DELETEMEMBER()"> deleteMember()</a> method to delete just one
member of a file.</li>
</ul>
</div>
<div class="section"><p>Use the <a href="javadoc/com/ibm/as400/access/AS400File.html#ADDPHYSICALFILEMEMBER(JAVA.LANG.STRING, JAVA.LANG.STRING)"> addPhysicalFileMember()</a> method to add members
to a file.</p>
</div>
</div>
</body>
</html>