View previous topic :: View next topic |
Author |
Message |
aniscorp Beginner
Joined: 24 Apr 2006 Posts: 14 Topics: 3
|
Posted: Mon Apr 24, 2006 3:18 am Post subject: Sort a VSAM file in descending order to create new VSAM file |
|
|
Iam unable to create a new VSAM file in descending order of the key.
It gives me return code of 12 and message shown is:
**RECORD OUT OF SEQUENCE - KEY FOLLOWS:
I tried doing same with File Aid, but it gives VSAM open error. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Apr 24, 2006 5:04 am Post subject: |
|
|
aniscorp,
First copy the vsam file to temp dataset and then sort on the temp dataset in descending order.
another option is to use COPYBACK feature of file-aid which will copy the results backwards. Since your input cluster is sorted on the key sequence, using COPYBACK feature will give you the results in the descending sequence of the key.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
aniscorp Beginner
Joined: 24 Apr 2006 Posts: 14 Topics: 3
|
Posted: Mon Apr 24, 2006 6:13 am Post subject: |
|
|
Hi Kolusu,
I had tried the first option of sorting the VSAM file in descending order, but the sortout is a flat file. Then I did a REPRO to copy this sorted file to another VSAM file, but it gave me Out of sequence error, whereas the records are in sequence of descending order.
Can you please let me know how to use the COPYBACK feature of FileAid.
If possible can you share the JCL for the same.
Thanks
Aniscorp |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Mon Apr 24, 2006 7:13 am Post subject: |
|
|
Kolusu,
Quote: |
First copy the vsam file to temp dataset and then sort on the temp dataset in descending order.
|
How will this work ? Aniscorp, wants to rearrange the key field in descending order and create a new vsam file with the same field as key. But, VSAM always arranges the key field in ascending order.
Aniscorp,
You cannot create a new vsam file and have the key field itself in descending order. Instead, you can introduce a new key field which is in ascending order by itself but it rearranges the data in descending order of old key.
For example: you can create another key (using sort or some utility) which is of same length as original key and whose value is computed as shown below.
Code: |
New key = Max value of original key - original key value of that record
|
For example, if you have a numeric key field which can have a max value of 9(5) i.e 99999 then new key = 99999 - original key. This will rearrange the file in reverse order.
Hope this helps,
Thanks,
Phantom |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Apr 24, 2006 8:28 am Post subject: |
|
|
Quote: |
How will this work ? Aniscorp, wants to rearrange the key field in descending order and create a new vsam file with the same field as key. But, VSAM always arranges the key field in ascending order.
|
Phantom,
I did not see anywhere aniscorp mentioned he wants to create a vsam cluster with a descending key sequence. He needs flat file with descending key sequence.
aniscorp,
Here is an example JCL using COPYBACK function
Code: |
//STEP0100 EXEC PGM=FILEAID
//SYSPRINT DD SYSOUT=*
//SYSLIST DD SYSOUT=*
//DD01 DD DSN=YOUR VSAM CLUSTER,
// DISP=SHR
//DD01O DD DSN=YOUR FLAT FILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(X,Y),RLSE)
//SYSIN DD *
$$DD01 COPYBACK OUT=0
/*
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Frank Yaeger Sort Forum Moderator

Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
|
Posted: Mon Apr 24, 2006 10:45 am Post subject: |
|
|
Quote: | I did not see anywhere aniscorp mentioned he wants to create a vsam cluster with a descending key sequence. |
I took the first sentence of the first post to mean that:
Quote: | Iam unable to create a new VSAM file in descending order of the key.
It gives me return code of 12 and message shown is:
**RECORD OUT OF SEQUENCE - KEY FOLLOWS: |
Note the word "new". I believe Phantom's interpretation and answer is correct - VSAM files must be in binary ascending key order. _________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort |
|
Back to top |
|
 |
aniscorp Beginner
Joined: 24 Apr 2006 Posts: 14 Topics: 3
|
Posted: Tue Apr 25, 2006 12:41 am Post subject: |
|
|
Kolusu,
Phantom's interpretation is correct and Thanks Frank for clarifying the same.
Phantom,
Thank you very much, I would implement the concept of new key suggested by you. And thanks for reminding me that the VSAM would not arrange key in descending order.
And thanks everyone for replying to my query and helping me out with solutions.
Regards
Aniscorp |
|
Back to top |
|
 |
|
|