View previous topic :: View next topic
|
Author |
Message |
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Abin,
Quote: |
The example does not show the amount descending. |
My bad, i just didn't read far enough. . .
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Abin,
The size of your data should not be a problem - go for it |
|
Back to top |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
I'll try it, but could there be a better solution, or is this the better solution. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
Ok, I was planning to do sorting logically, any way I'll try it. |
|
Back to top |
|
|
|