Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to insert a record in between two records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Mon Jun 08, 2009 6:40 pm    Post subject: How to insert a record in between two records
Reply with quote

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
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Jun 08, 2009 6:46 pm    Post subject: Reply to: How to insert a record in between two records
Reply with quote

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
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Mon Jun 08, 2009 6:46 pm    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Jun 08, 2009 6:47 pm    Post subject: Reply to: How to insert a record in between two records
Reply with quote

it is not clear what You are talking about...
the data sample does not match any key sequence
Back to top
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Mon Jun 08, 2009 6:54 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Mon Jun 08, 2009 6:59 pm    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Jun 08, 2009 7:01 pm    Post subject: Reply to: How to insert a record in between two records
Reply with quote

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
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Mon Jun 08, 2009 7:05 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Mon Jun 08, 2009 7:10 pm    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Jun 08, 2009 7:12 pm    Post subject: Reply to: How to insert a record in between two records
Reply with quote

no way to make the gentleman understand icon_cool.gif icon_evil.gif icon_cool.gif
Back to top
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Mon Jun 08, 2009 7:14 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Jun 08, 2009 7:16 pm    Post subject:
Reply with quote

/Rant on
Who ever invented indexed sequential Files will Suicide after looking at this thread..
/Rant off
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Jun 08, 2009 7:19 pm    Post subject: Reply to: How to insert a record in between two records
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon Jun 08, 2009 7:20 pm    Post subject:
Reply with quote

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 icon_confused.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon Jun 08, 2009 7:21 pm    Post subject: Reply to: How to insert a record in between two records
Reply with quote

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 icon_evil.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Mon Jun 08, 2009 8:59 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1218
Location: Israel

PostPosted: Tue Jun 09, 2009 2:37 am    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us