| View previous topic :: View next topic |
| Author |
Message |
sunkusiva Beginner
Joined: 04 Apr 2006 Posts: 8 Topics: 1
|
Posted: Wed Aug 30, 2006 7:16 pm Post subject: Read the occurences in Reverse order |
|
|
I have a requirement where in I need to read latest 10 Records from a Child Segment. Each record is inserted to Last of this Child Segment.So latest mean, I need to read Last 10 records.
There is a Seq# (Key field) which will get incremented by each insert, But there is other pgm which deletes some Seq#s. Bottomline, I have Seq#s which are in ascending order and need not be consecutive.
Is there any way that gets me last 10 Records. Basically, I need to read the segments in reverse order.
Approach#1
I can read all the occurences from beginning, store it in to a table once counter reaches 10 flush the first one...sort the result. But the occurences for child segment are huge in number, and this approach costs me a lot to read 99% of segs which I don't want.
Approach#2
1. Get the Last Seq# by using SSA
2. Get the one prior to Last by SSA (Say it fetched me 00123 in Step 1).
| Code: | | CHLDSEG *L-(SEQNO LT00123) |
Repeat the Step 2 for 9 times replacing the SEQNO Value obtained in earlier Get.
Which one will be better approach?
If I use Command code 'L' does IMS internally Read all and get me last record? (If so my first approach will be better considering performance).
What is the best way? Any new approach also welcome.
Thanks
Siva. |
|
| Back to top |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Thu Aug 31, 2006 7:58 am Post subject: |
|
|
| Execute the *L to get the last SEQNO, subtract 9, execute an GN on this new SEQNO then issue GN for the rest of the segments. |
|
| Back to top |
|
 |
sunkusiva Beginner
Joined: 04 Apr 2006 Posts: 8 Topics: 1
|
Posted: Thu Aug 31, 2006 5:19 pm Post subject: |
|
|
Bithead,
Thank you.
Problem here is my Seq#s need not be consecutive.
| Quote: | Bottomline, I have Seq#s which are in ascending order and need not be consecutive.
|
This avoids me to use the suggested approach.
Thanks
Siva. |
|
| Back to top |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Thu Aug 31, 2006 6:17 pm Post subject: |
|
|
| Then you will need to start at the first occurrance then read sequentially to the end, saving the last 10. If you use the LT (less than), you will get any occurrance that matches, which would probably be the first. |
|
| Back to top |
|
 |
|
|
|