View previous topic :: View next topic
|
Author |
Message |
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
Hi,
I have an input indexed sequential file. The records are like
4785 John
8967 Ravi
2513 Amit
6842 Sunil
I want to insert a record say 8219 Vivek between the second and third record.
I believe I have to make use of Access mode as Dynamic and using Start Key statement in my procedure division, but I do not know how exactly I have to code it.
Thanks. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Your record will be inserted in the proper KEY sequence,
after the record with the key lower than YOURKEY
before the record with the key higher than YOURKEY
anyway the record sequence shown does not indicate any proper KEY sequence
please reformulate Your question in a consistent way wit a consistent data sample |
|
Back to top |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
Hi,
I got to know that I have to move part of the value for the key in Start Key = (part of the value of key) i.e. 821 in this case and then do the Read Next.
Please let me know if I am somehow correct.
Thanks. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
it is not clear what You are talking about...
the data sample does not match any key sequence |
|
Back to top |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
Hi,
Do I have to move 2 to Emp-No (If Emp-No is my Key and 2 is the second record) first and then make use of Start Key = Emp-No and then use Read Next followed by Write statement inserting 8219 Vivek after the second record.
Thank. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I want to insert a record say 8219 Vivek between the second and third record. |
This makes no sense based on the data you have provided. If the data key is the numeric field, the sequence will be
Code: |
2513 Amit
4785 John
6842 Sunil
8967 Ravi |
If the data key is the alpha field, the sequence will be
Code: |
2513 Amit
4785 John
8967 Ravi
6842 Sunil
|
So either you have no idea what you're wanting to do, you made up false data that is illogical, or you have not explained your problem adequately to provide an answer.
In COBOL, in general, you can use dynamic access to read the record; if the record is not found then you can write the new one into the file. You do not have to worry about the key sequence because VSAM will maintain that for you. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
please use the proper terms...
indexed sequential ... specify what You mean ( VSAM KSDS most probably )
if not , what else ??
again, please, clarify better Your environment |
|
Back to top |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
Hi Robert,
I understood now what I had to provide earlier. My Data key is Numeric field and would like to insert record between
4785 John
6842 Sunil
The output should be
2513 Amit
4785 John
8219 Vivek
6842 Sunil
8967 Ravi
Thanks. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
If the file is indexed sequential, you have absolutely no control over where the record is inserted. The key determines the location, not you. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
no way to make the gentleman understand |
|
Back to top |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
Hi,
Fine. If I have 5 records in my indexed sequential file and I want to read the records from 3rd record what should be my Start Key command?
Thanks. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
/Rant on
Who ever invented indexed sequential Files will Suicide after looking at this thread..
/Rant off |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
look like we are all losing time...
in a keyed, indexed ... call it any way You want, there is no concept of relative record number
the relative record number does not depend on the sequence of writes/inserts
but on the key sequence
so the content of what You call the third record depends on the keys |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
WOW, and I spent ages in the dark distant past converting ISAM to VSAM.
Are there really sites out there still back in the dark ages and really using ISAM |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
I gave the ts the benefit of doubt...
index sequential ksds do not make any difference , do not have any impact
on the TS misconception, poor understanding of things
ok for a bit of language barrier, but this is too much |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Fine. If I have 5 records in my indexed sequential file and I want to read the records from 3rd record what should be my Start Key command? |
You cannot do this. You can provide a partial key and start reading from that point, but you do not know if the record you retrieve is the first, third, seventy-seventh, or one-million, three hundred eighty-four thousand, nine hundred and seventh record. Indexed sequential means you do not know anything except which sequence the records were stored in. The order added is not maintained and cannot be recovered.
If the file was sequential, the order the records were added in will typically be how they are stored in the file (but not always) -- but for indexed sequential there is no data retained about the sequence of adding. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Select-mf wrote: |
Do I have to move 2 to Emp-No (If Emp-No is my Key and 2 is the second record) first and then make use of Start Key = Emp-No and then use Read Next followed by Write statement inserting 8219 Vivek after the second record. |
WOW!!! Now THAT's programming!!!
Expecting the unexpected:
Just in case you're using a plain sequential file (use of VSAM has not been confirmed yet by Select-mf), that cannot be done.
You'll have to read each record and write it to another file. Insert new records where you want according to whatever logic you apply. |
|
Back to top |
|
|
|