 |
forum.vmspython.org Forum system
|
View previous topic :: View next topic |
Author |
Message |
jescab
Joined: 28 Jan 2008 Posts: 254
|
Posted: Mon Oct 12, 2015 1:40 pm Post subject: RMS examples. |
|
|
Hi.
Wasn't there once some examples on how to use the RMS interface on
page http://www.vmspython.org/doku.php?id=pythonexamples ?
I need to write some records to an indexed RMS files.
I have successfully written routines that *reads* from RMS
files sequentially, but now have to insert a number of records
in an file.
I have a record and file definition like below, but I do not get it
how to populate a record to be used with the "put()" function...
Code: |
MEF340Rec = Struct("MEF340Rec",
String("PRODNR", 10),
String("LAND", 4),
String("ARTNR", 10),
String("RIKTNR", 2),
String("ANTAL", 4),
String("PROCIND", 1),
String("FACKNR", 2),
String("FILLER", 9))
class MEF340(IndexedFile):
Name = 'ME340A.IDX'
def __init__(self):
IndexedFile.__init__(self, MEF340.Name, MEF340Rec)
def primary_keynum(self):
return 0 |
The values comes from an Rdb SELECT statement that are
iterated through the result from a rdb.fetchall(). No problems
there, I have the values, but don't know how to get them into RMS.
I guess I have to use the record definition above in some way and
populate the PRODNR (and so on) fields. Then call put() with that
records as a parameter...
Can one just "put" records and RMS will handle the index update?
Or do I have to define the actual indexes also? I'm not interested
in searching using the indexes, just inserting a few 100s new records.
I already know that they are not violating the index...
So, what is the easiest way to write a record to an RMS file from Python?
Thanks, Jan-Erik. |
|
Back to top |
|
 |
jescab
Joined: 28 Jan 2008 Posts: 254
|
Posted: Mon Oct 12, 2015 10:04 pm Post subject: |
|
|
Update...
I thought about the download I made of the sources for PythonVMS
a few days ago, and took a look, and there was 3-4 test*.py files
that seems to answer my questions. I think that test1b.py has
what I need. I'll try that "Container()" function and fil in the
data got from the Rdb query...
Code: |
import struct
from vms.rmsdef import RMS__SUC, RMS__RNF, RMS__OK_DUP
from vms.fabdef import FAB_M_PUT, FAB_M_GET, FAB_M_DEL, FAB_M_UPD, \
FAB_M_SHRPUT, FAB_M_SHRGET, FAB_M_SHRDEL, FAB_M_SHRUPD
from vms.rms.IndexedFile import IndexedFile
from construct import *
TestRec = Struct("TestRec", String("f1", 5), SLInt32("f2"), String("f3", 11))
class TestFile(IndexedFile):
Name = 'test.dat'
def __init__(self):
IndexedFile.__init__(self, TestFile.Name, TestRec)
...
...
...
if __name__=='__main__':
f = TestFile()
print
print 'Reset file'
f.reset()
print
print 'Insert a few records'
rec = Container(f1 = 'AA5AA', f2 = 5, f3 = '1234567890A')
f.put(rec)
rec = Container(f1 = 'BB2BB', f2 = 2, f3 = '1234567890B')
f.put(rec)
...
...
... |
|
|
Back to top |
|
 |
jescab
Joined: 28 Jan 2008 Posts: 254
|
Posted: Tue Oct 13, 2015 9:27 am Post subject: |
|
|
Follow-up...
Worked just OK. The RMS file was updated yesterday
according to the costumer requirements...  |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 625
|
Posted: Wed Oct 14, 2015 8:39 am Post subject: |
|
|
Excellent!
Thanks for sharing your example.
JF |
|
Back to top |
|
 |
jescab
Joined: 28 Jan 2008 Posts: 254
|
Posted: Thu Oct 15, 2015 5:52 pm Post subject: |
|
|
Hi.
> ...your example.
The code in the first post was mine.
The code in the second post is from the source code distribution...  |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|