Updating Record Key



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Updating Record Key

Postby crazycobol » Thu Sep 15, 2011 12:52 am

Hello everyone. Just a quick question. How do you update the "record key"

Lets say I have a record key that is 20007000 and I want to change that record key to 200080000.

I have tried to do a rewrite however you can not do a rewrite on the record key.

How do I go about updating the record key? is it possible or do I have to delete the entire record and write another record with the correct record key.


The file structure goes something like this:

FD FILE

01 REC

05 KEY
10 CKEY PIC X(8).

05 DATA


Any help is greatly appreciated.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Updating Record Key

 

Re: Updating Record Key

Postby crazycobol » Thu Sep 15, 2011 1:06 am

the record key is for Primary Record Key just in case there was any confusion.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Updating Record Key

Postby dick scherrer » Thu Sep 15, 2011 1:13 am

Hello,

Suggest you add the record with the new key and then delete the record with the old key - in that order. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Updating Record Key

Postby crazycobol » Thu Sep 15, 2011 1:38 am

Thank you Dick for the reply.

Do I do the following:

move 200080000 to ckey.

write rec.

Then I do:

if ckey equal 20007000
then delete rec.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Updating Record Key

Postby BillyBoyo » Thu Sep 15, 2011 1:57 am

crazycobol wrote:Thank you Dick for the reply.

Do I do the following:

move 200080000 to ckey.

write rec.

Then I do:

if ckey equal 20007000
then delete rec.



Mmmm... by then, ckey won't be 20007000(0) any longer.

Really, how you have to do it depends on what is driving your progam.

You don't really "change a key" on a file. You do delete the old key, and add the new key.

How do you know you need to change the key? That provides your method. If you are identifying someone from solely the file itself, then conside what Dick has suggested.

If you have some sort of transaction file, exactly what do you have?

So, how do you know the key has changed.... ?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Updating Record Key

Postby crazycobol » Thu Sep 15, 2011 2:33 am

The file is a dat file that store records. The primary key is used to identified the record. So currently the record in the file has 20007000 as the primary key and then after it has data. The next record would be 20009000 along with data behind it.

so it look like this:

20007000abcdefgdddd
20009000abcdefffffdd


I would like to change the 20007000 record to look like this:

20008000abcdefgdddd

keeping the data intact.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Updating Record Key

Postby BillyBoyo » Thu Sep 15, 2011 3:52 am

Is there only the one record to change (=add/delete)?

If so, read with the key the record you want to delete. Keep a copy of the key value in WS. Change the key in the file area to what you want it to be. Do the write to add the recored. Re-read the original record using the key saved in WS. Delete that record. Issue some nice messages so that you know what the program has done.

If there are more than one you need to do, I'd make a flat file with the old/new keys and drive the update from that. Same sort of processing thereafter.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Updating Record Key

Postby crazycobol » Thu Sep 15, 2011 5:29 am

BillyBoyo wrote:Is there only the one record to change (=add/delete)?

If so, read with the key the record you want to delete. Keep a copy of the key value in WS. Change the key in the file area to what you want it to be. Do the write to add the recored. Re-read the original record using the key saved in WS. Delete that record. Issue some nice messages so that you know what the program has done.

If there are more than one you need to do, I'd make a flat file with the old/new keys and drive the update from that. Same sort of processing thereafter.


great. Yes it is only one record to change. I will give it a shot tomorrow. Thank you again for your help. Very much appreciated.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Re: Updating Record Key

Postby BillyBoyo » Thu Sep 15, 2011 4:51 pm

No problem. Thanks for the thanks, which is shared amongst us. Let us know how it goes.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Updating Record Key

Postby crazycobol » Sat Oct 01, 2011 3:31 am

sorry for the late response. It works. :)
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post