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:
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!