MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sort a VSAM file in descending order to create new VSAM file

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL)
View previous topic :: View next topic  
Author Message
aniscorp
Beginner


Joined: 24 Apr 2006
Posts: 14
Topics: 3

PostPosted: Mon Apr 24, 2006 3:18 am    Post subject: Sort a VSAM file in descending order to create new VSAM file Reply with 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:
I tried doing same with File Aid, but it gives VSAM open error.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Apr 24, 2006 5:04 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
aniscorp
Beginner


Joined: 24 Apr 2006
Posts: 14
Topics: 3

PostPosted: Mon Apr 24, 2006 6:13 am    Post subject: Reply with quote

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


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Mon Apr 24, 2006 7:13 am    Post subject: Reply with quote

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


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Apr 24, 2006 8:28 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Apr 24, 2006 10:45 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
aniscorp
Beginner


Joined: 24 Apr 2006
Posts: 14
Topics: 3

PostPosted: Tue Apr 25, 2006 12:41 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group