Page 1 of 1

Reading n records from a file

PostPosted: Wed Jun 02, 2010 12:01 am
by umeshunni
Hello,

I was given a case study which is as follows:

There is a KSDS file which has the Employee Name as the primary index (say for example).
There are records with Employee names ranging from A to Z. We have to read only the last 5 records from the file that has the first name starting with say ‘U’.

More precisely: Suppose the records from the KSDS file are as follows:
AEMP1…
AEMP2…
.
.
UEMP1…
UEMP2…
.
.
UEMP15…
.
.
ZEMP1
.
.
Here in the example, we have 15 records having the Primary field starting with ‘U’.
So, as per the requirement, we have to only read the records from “UEMP11” thru “UEMP15”.
Other facts about the file are we do not know the full key…moreover names starting with U are not the last set of records in the file…

As per my answer:
Since the “U” records are not the last set then moving high values and setting the browse operation to the end followed by READPREV 5 times will not serve the purpose.

Using Partial key technique and the START verb, reach out to the first record with initial as “U”. Perform READNEXT until all the records starting with “U” are read (by keeping a tab on the primary field). Now we will be on the next record greater than “U” and so by performing a READPREV we should be on the last record with “U” (UEMP15 in this case). Then performing the READPREV for 5 times we should be able to read the last 5 records as per the requirement.

Although this method sounds a bit tedious, I am pretty sure there should be some other simpler way! I would be glad if anyone could think of a better approach to achieve the desired results and share it here.

Let me know if any kind of clarification/information is required.

Thanks in advance! :)
Umesh

Re: Reading n records from a file

PostPosted: Wed Jun 02, 2010 12:11 am
by Robert Sample
I assume you're talking about CICS, although you did not specify:
Move HIGH-VALUES to the key.
Move 'U' to the first character of the key (reference modification works well for this, or an array redefinition will also do it).
Do the START
Do the READNEXT.
Do six READPREV to get the five records.

If you do a STARTBR followed by READPREV, the value in the key variable must match an existing key in the file.

Re: Reading n records from a file

PostPosted: Wed Jun 02, 2010 8:40 am
by umeshunni
Robert, thanks for your prompt response! :)

So as per my understanding of your approach, since we are first moving HIGH-VALUES to the key and then the 'U' to the first character of the key, am I correct in saying that the START verb using the above formed key will point to the last 'U' record in the file. From the example that i had stated, it means the START will point to the "UEMP15" record!

And proceeding ahead with the READNEXT and READPREV it will fetch me the records:
UEMP15, UEMP14, UEMP13, UEMP12 and UEMP11 in the stated order.

Thanks once again,
Umesh