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
 

 

Sorting KSDS in alternate index

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Wed Apr 09, 2008 6:06 pm    Post subject: Sorting KSDS in alternate index
Reply with quote

Hi,

Please let me know if following requirement is possible using VSAM.

I have a KSDS file which is orted and loaded uv=nder the key feilds. The same VSAM has an alternate index defined. Is it possible to sort the VSAM using the alternate index key fields.
Back to top
View user's profile Send private message

superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Wed Apr 09, 2008 6:12 pm    Post subject: Reply to: Sorting KSDS in alternate index
Reply with quote

Can we presume that the sorted output will be a non-KSDS VSAM dataset, or a QSAM dataset, since, of course, KSDS requires that the primary keys be kept in ascending sorted order?

If so, then the answer is definitely yes.
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Wed Apr 09, 2008 6:37 pm    Post subject:
Reply with quote

If I make it a non-KSDS VSAM dataset, or a QSAM dataset, will I be still able to use the alternate index.

The reason is because I need to read the data set in the order of alternate index. But record are non-unique under alternate index and that is why I'm using a different key as primary
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Wed Apr 09, 2008 7:00 pm    Post subject:
Reply with quote

Quote:
The reason is because I need to read the data set in the order of alternate index.

This is possible without sorting original VSAM file also. Just read the file using alternate index..
Why do you want to sort it again?
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Wed Apr 09, 2008 7:34 pm    Post subject:
Reply with quote

Hi,

Please validate if my understanding is right.

The KSDS is a follows.

11111 ZZZZ 70
22222 YYYY 40
33333 ZZZZ 90
44444 XXXX 10
55555 ZZZZ 80

Consider first column is my key second row is my alternate indexd and third row is an amount field which I will use for reading in the descending order.

I need to read the records in following order one by one and write it into an output file.

44444 XXXX 10
22222 YYYY 40
33333 ZZZZ 90
55555 ZZZZ 80
11111 ZZZZ 70
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Apr 09, 2008 9:34 pm    Post subject:
Reply with quote

Hello Abin,

Please review your last post. I believe it needs a bit of work here:
Quote:
Consider first column is my key second row is my alternate indexd and third row is an amount field which I will use for reading in the descending order.
Should the "row"s be "column"s? Do you want the amount field to be read descending? The example does not show the amount descending.

Depending on the requirement definition (once it is clarified), there may be different suggestions on how to get the output you want.
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Wed Apr 09, 2008 10:27 pm    Post subject:
Reply with quote

Quote:
Should the "row"s be "column"s? Do you want the amount field to be read descending? The example does not show the amount descending.


Sorry it was a typo I meant column. In the input for key 1111 the amount field(third column) was in order 70, 90, 80. In out put I need it as 90. 80. 70.
I need the records to be read in the descending order of amount under each key.

Hope my requirement is clear.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 10, 2008 12:11 am    Post subject:
Reply with quote

Hello Abin,

Quote:
The example does not show the amount descending.
My bad, i just didn't read far enough. . . icon_redface.gif

What you want could easily be done using cobol with an internal sort or possibly with your sort product.

Please let me know if you would like to have your topic moved to one of those forum sections.
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Apr 10, 2008 12:15 am    Post subject:
Reply with quote

Actually I thought of internal sort. but I 'm afraid of memory that application program can avail of, becaues the LRECL of record is going to be 5000 bytes. And, I'm not sure about the number of records. May vary between 1 to 100.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 10, 2008 12:19 am    Post subject:
Reply with quote

Hello Abin,

The size of your data should not be a problem - go for it icon_smile.gif
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Apr 10, 2008 12:27 am    Post subject:
Reply with quote

I'll try it, but could there be a better solution, or is this the better solution.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 10, 2008 12:42 am    Post subject:
Reply with quote

Hello,

Quote:
is this the better solution
For the amount of data you have to work with and what you need to do, i believe this is a very good solution.

Using code and an internal sort will also give you considerable flexibility should the requirement definition "grow".

Also, do keep in mind that all of the bytes in every record may not need to be sorted - only those that are needed to get the required output.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Apr 10, 2008 1:50 am    Post subject: Re: Sorting KSDS in alternate index
Reply with quote

abin wrote:
I have a KSDS file which is orted and loaded uv=nder the key feilds. The same VSAM has an alternate index defined. Is it possible to sort the VSAM using the alternate index key fields.
Abin,

I do not understand what the final output you want the alternate index sorted for.
A second file?
Just as input to a program?
A keyed VSAM file?
Where will the sorted output go next?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 10, 2008 2:16 am    Post subject:
Reply with quote

Hello,

The final output has little to do with the alternate index (if i understand correctly). The goal is to produce the sample output in this "format/sequence" -

Code:

      Ascen Desc
44444 XXXX  10
22222 YYYY  40
33333 ZZZZ  90
55555 ZZZZ  80
11111 ZZZZ  70


again if i understand correctly.
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Apr 10, 2008 2:48 pm    Post subject:
Reply with quote

Quote:
again if i understand correctly.

Yes that is correct. And I hope this can be achived using alternate index and internal sort. I'm developing the codecurrently.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 10, 2008 7:45 pm    Post subject:
Reply with quote

Hello,

If you use the internal sort, you don't really need to do anything specific for the alternate index (unless there is more to the requirement than has been posted so far). For your purpose, it is just another field and the sort "key" would be 2 fields - one ascending, the other descending.
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Apr 10, 2008 7:49 pm    Post subject:
Reply with quote

So, can we create alternative index in half of the keys as asending and other half as descending, then it is grea.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 10, 2008 8:42 pm    Post subject:
Reply with quote

Hello,

I believe you misunderstand. There is no need for "alternate key" definition/processing. The ascending/descending will be handled by the internal sort.

You will define an SD similar to:
Code:

01  SORT-REC.
    05 SORT-KEY-ASC  PIC X(5).
    05 SORT-KEY-DESC PIC 99.
    05 Other fields as needed. . .
then in the PROCEDURE division
    SORT SORT-FILE ON ASCENDING SORT-KEY-ASC
                      DESCENDING SORT-KEY-DESC
         INPUT PROCEDURE. . .
         OUTPUT PROCEDURE. . .
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Apr 10, 2008 8:51 pm    Post subject:
Reply with quote

Ok, I was planning to do sorting logically, any way I'll try it.
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 -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Efficient sorting chandracdac DFSORT/ICETOOL 5 Sat Oct 22, 2016 3:23 am
No new posts Stripping and Sorting of VB file G SRINIVASA RAO SYNCSORT 5 Wed Sep 14, 2016 1:34 pm
No new posts DFSORT sorting only specific records akodakka DFSORT/ICETOOL 4 Thu Aug 04, 2016 11:24 am
No new posts Several errors during building altern... Andi1982 JCL & VSAM 11 Wed Jul 06, 2016 7:39 pm
No new posts Drop building Alternate Index for a p... bhavin.mehta JCL & VSAM 6 Mon Jul 04, 2016 3:47 pm


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