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