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

Sorting KSDS in alternate index


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
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
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

Global Moderator


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

PostPosted: Wed Apr 09, 2008 6:12 pm
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
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: 691
Location: Earth

PostPosted: Wed Apr 09, 2008 7:00 pm
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
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

Moderator Emeritus


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

PostPosted: Wed Apr 09, 2008 9:34 pm
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 10, 2008 12:11 am
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 10, 2008 12:19 am
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 10, 2008 12:42 am
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: 2146
Location: At my coffee table

PostPosted: Thu Apr 10, 2008 1:50 am
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

Moderator Emeritus


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

PostPosted: Thu Apr 10, 2008 2:16 am
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 10, 2008 7:45 pm
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 10, 2008 8:42 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts COBOL sorting, with input GDG base COBOL Programming 7
No new posts Sorting Date Field DFSORT/ICETOOL 4
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Cobol file using index COBOL Programming 2
Search our Forums:

Back to Top