IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to insert a record in between two records


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jun 08, 2009 6:46 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jun 08, 2009 6:47 pm
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 08, 2009 6:59 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jun 08, 2009 7:01 pm
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 08, 2009 7:10 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jun 08, 2009 7:12 pm
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
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

Superior Member


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

PostPosted: Mon Jun 08, 2009 7:16 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jun 08, 2009 7:19 pm
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: 8797
Location: Welsh Wales

PostPosted: Mon Jun 08, 2009 7:20 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jun 08, 2009 7:21 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 08, 2009 8:59 pm
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: 1353
Location: Israel

PostPosted: Tue Jun 09, 2009 2:37 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top