iSeriesPython

File400 Module

The File400 class is in the __builtins__ module.
Use this class for record level access and file information.

File400(Filename[mode, options, lib, mbr, qry])
Returns a new File400 Object.

Filename must exist. Mode None(default) does not open the file,
Use mode 'r' for reading , 'a' for appending
and 'r+' for read, update and append.

The options should be a string with this format: 'arrseq=Y, secure=Y'.
Options:
arrseq - Arrival sequence. (Y, N(default))
blkrcd - Performs record blocking. (Y, N(default))
ccsid - Specifies the CCSID. Default is 0 (the job CCSID is used.)
commit - Open under commitment control. (Y, N(default)).
secure - Secure from overrides. (Y, N(default)).

You can specify the library, special values are *LIBL(default) and *CURLIB.
You can also specify the member, special value are *FIRST(default).
The qry keyword is a wrapper for the opnqryf command.

File400 has the following methods:

open(Filename[mode[keywords]])
Opens the file. The mode can be 'r' for reading (default),
'a' for appending and 'r+' for read, update and append.

The keywords should be a string with this format: 'arrseq=Y, secure=Y'.
Keywords:
arrseq - Arrival sequence. (Y, N(default))
blkrcd - Performs record blocking. (Y, N(default))
ccsid - Specifies the CCSID. Default is 0 (the job CCSID is used.)
commit - Open under commitment control. (Y, N(default)).
secure - Secure from overrides. (Y, N(default)).

close()
Close the file.

posb(key)
Positions before the first record that has a key equal to the specified key.
The key value can be a number that says number of keyfields from the key buffer,
or it can be a sequence of key values.
Returns 1 if key is found, 0 otherwise.

posa(key)
Positions after the last record that has a key equal to the specified key.
The key value can be a number that says number of keyfields from the key buffer,
or it can be a sequence of key values. No return value.

posf()
Positions before the first record.

posl()
Positions after the last record.

readrrn(rrn[lock])
Read by relative record number.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readn([lock])
Read next record.
Returns error code, 0 - found, 1 - not found.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readp([lock])
Read previous record.
Returns error code, 0 - found, 1 - not found.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readf([lock])
Read first record.
Returns error code, 0 - found, 1 - not found.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readl([lock])
Read last record.
Returns error code, 0 - found, 1 - not found.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readeq(key[lock])
Read first record equal with the specified key.
Returns error code, 0 - found, 1 - not found.
The key value can be a number that says number of keyfields
to use from the key buffer, or it can be a sequence of key values.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readne(key[lock])
Read next record if equal with the specified key.
Returns error code, 0 - found, 1 - not found.
The key should normally be a number that says number of keyfields
to use from the key buffer, or it can be a sequence of key values.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

readpe(key[lock])
Read previous record if equal with the specified key.
Returns error code, 0 - found, 1 - not found.
The key should normally be a number that says number of keyfields
to use from the key buffer, or it can be a sequence of key values.
Lock (for mode 'r+'). 1 - lock(default) 0 - no lock.

write()
Appends the buffer to the file.

update()
Updates the currently locked record with the content of the buffer.

rlsLock()
Releases the lock on the currently locked record.

clear()
Clear the record buffer.
Numeric fields to zero and char/dbcs to blank.

get([sequence/value])
Returns field values.
f.get() - Get list of all values.
f.get('CUSNO') - Value of the field CUSNO. Same as f['CUSNO'], or f._CUSNO
f.get(0) - Value of the first field. Same as f[0]
f.get(('CUSNO','NAME')) - Returns list of values.
f.get((0,1)) - Returns list of values.

getKey([sequence/value])
Returns the key value.
f.getKey() - Get list of key values.
f.getKey('cusno') - Value of the key field cusno.
f.getKey(0) - Value of the first key field.
f.getKey(('cusno','name')) - Returns list of values.
f.getKey((0,1)) - Returns list of values.

getRrn()
Returns the current record number.

isOpen()
Returns 1 if file is open otherwise 0.

mode()
Returns open mode (r, a, r+).

recordSize()
Returns the record size in bytes.

fileName()
Returns file name.

libName()
Returns library name.

mbrName()
Returns name of current member (can be *first).

mbrList()
Returns tuple of member names.
Member can be generic (use an asterisk).

fieldCount()
Returns number of fields.

fieldList()
Returns a tuple of field names.

fieldDesc(Field)
Returns description for field.
Field can be both number and name.

fieldSize(Field)
Returns field size in bytes.
Field can be both number and name.

fieldType(Field)
Returns field type.
Field can be both number and name.

keyCount()
Returns number of key fields.

keyList()
Returns tuple of key field names.

clear()
Clear the record buffer.
Numeric fields to zero and char/dbcs to blank.

getRecord()
Returns a Record400 object with a copy of the current buffer value.

set(Field, Value)
Put value from Field into the buffer.
Field can be both number and name.
Same as f['CUSNO'] = 123, f[0] = 123, f._CUSNO = 123

setKey(Sequence)
Updates the key buffer with key values.
Sequence should be a tuple or list with keyvalues.

setRecord(Record)
Put values from record object to record buffer.

The Record400 object is returned from File400.getRecord().
You don't need this object for normal read an update.
Examples will follow.

Record400 has the following methods:

getFile()
Return the File400 object where this record came from.

refresh()
Update Record with the current values in the file record buffer.

get([sequence/value])
Returns field values.
r.get() - Get list of all values.
r.get('CUSNO') - Value of the field CUSNO. Same as r['CUSNO'], or r._CUSNO
r.get(0) - Value of the first field. Same as r[0]
r.get(('CUSNO','NAME')) - Returns list of values.
r.get((0,1)) - Returns list of values.

getRrn()
Returns record number.

set(Field, Value)
Put value from Field into the record.
Field can be both number and name.
Same as r['CUSNO'] = 123, r[0] = 123, r._CUSNO = 123

getBuffer()
Get the raw value of buffer as a String.

setBuffer()
Copy the value of string to the internal record buffer.
Use this with caution.

Examples:

Open a customer file sorted by department.
Add all records for a department into a list.
f = File400('CUST','r')
f.posb(('001'))
records = []
while not f.readne(1):
    records.append(f.getRecord())
f.close()
for r in records:
   print r._DEPT, r._CUSNO

Use qry but not record.
f = File400('CUST','r',qry='qryslt('DEPT = 001')')
while not f.readn():
   print f['DEPT'], f['CUSNO']

The format of the *lda is defined with the file LDADEF. Read the *lda value into a record for easier access.
import os400
lda = File400('LDADEF').getRecord()
lda.setBuffer(os400.rtvdtaara('*LDA','',1000))