View previous topic :: View next topic
|
Author |
Message |
anilsanda
New User
Joined: 07 Jun 2007 Posts: 15 Location: chennai
|
|
|
|
hi,
i want to know how to add records(updating) to the an existing file.
it will be helpful if anyone quote syntax and some examples. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
To add records, or to update records ?
If you just want to add records then use DISP=MOD as you disposition, but if you want to update in place then that will be DISP=OLD.
If you do want to add records, I would suggest that you write a new file out and use a utility to then merge the existing file and the new file, which will preserve the data integrity of the original file. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Yes this is possible in REXX. For adding records,
1) First u read the file into a stem variable (By doing this all the records will be stored in the stem variable)
2) Get the count of the total records in the file (stem.0)
3) Open a stack and Form a loop to QUEUE the record.
4) Once the last record is reached Queue the record which u want to add.
5) Close the stack and write the queued data to a new file.
If u dont want to write it into a new file then delete the input file after reading the contents to a stem variable.
For updating records, do step 1 - 3 . Search for the record to be updated using POS command and then use substring to update the record. |
|
Back to top |
|
|
anilsanda
New User
Joined: 07 Jun 2007 Posts: 15 Location: chennai
|
|
|
|
could u pls provide me some example ....it will be helpful |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Quote: |
If u dont want to write it into a new file then delete the input file after reading the contents to a stem variable. |
And if your job fails after you have deleted the dataset ???
Also, why bother to read the records only to rewrite them again, why not just MOD the existing dataset, although it's not something I would willingly do. See my last post. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Quote: |
And if your job fails after you have deleted the dataset ??? |
S in that case i would lose my dataset !
Quote: |
why not just MOD the existing dataset, although it's not something I would willingly |
Is there anyway to add a record to a file in REXX without reading the whole file into a stem variable ?
Please clarify |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
DISP=MOD when allocating the file. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Ok ! so to add a record we would use DISP=MOD while allocating the file.
For updating the record we would use DISP=OLD while allocating the file.
Quote: |
Is there anyway to add a record to a file in REXX without reading the whole file into a stem variable ? |
But one has to read the whole file for updating and inserting the record in the file. hope am not wrong ! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you provide the specifics of what you need to do, someone may have a suggestion.
What kind of file are you working with that needs new records added and/or existing records updated? How is the process driven (have you created a screen, does this run in batch, etc).
The more and better info you provide, the better suggestions you will receive. |
|
Back to top |
|
|
|