While reading a adabas file, i get my records as below:
STATUS DATE TIME IND
A 20061102 030347 A
A 20061102 030347 D
A 20061102 030347 R
Z 20061102 023837 A
Z 20061102 024929 A
Z 20061102 023837 D
Z 20061102 024929 D
Z 20061102 023837 R
Z 20061102 024929 R
Could anyone please suggest the best way to fetch the most recent records out of these for IND = A,D,R
i would like to sort this on Date and time and get 3 latest records one each for A,D,R
like here
A 20061102 030347 A
A 20061102 030347 D
A 20061102 030347 R
Incase ‘A’ status record werenot there and my Read gives below ,
Z 20061102 023837 A
Z 20061102 024929 A
Z 20061102 023837 D
Z 20061102 024929 D
Z 20061102 023837 R
Z 20061102 024929 R
I would have liked the sort results to be
Z 20061102 024929 A
Z 20061102 024929 D
Z 20061102 024929 R
based on what you have described here, I would probably set up a superdescriptior on IND, Date, Time and Status. Use 3 READ DESCENDING statements (one for each IND) (either 3 READ statements in the program or one READ statement inside a FOR loop to start the loop with each IND value).
I assumed that the “in case A status record is not there” would be a daily thing - records for the “A” or “Z” status may or may not occur on any given day.
In the read loop, store the youngest record you found for each IND value. A status ‘Z’ can only overwrite a status ‘Z’ but not a status ‘A’ value. Sorting is not necessary as you already read all records.
Could you please tell the same with ex.I am afraid i didnot understand your reply well.Thankyou.How do i store the youngest record .
Do you mean something like this.
If ind=‘Z’
f on-line-date GT on-line-date-temp or
(on-line-date EQ on-line-date-temp and
on-line-time gt on-line-time-temp)
where temp would contain the last rec read date and time for IND = ‘z’?
What is not clear from your question is the role of “Status” in determining the most recent record. Suppose you had:
Z 20061102 023837 A
A 20061101 024929 A
Based on just date and time, the first record is the most recent. However, the second record is an “A” while the first record is a “Z”. Is the Status field relevant for determining “most recent”?
Regardless of the answer above, you will want to have three IF tests for each record. Logically they would be:
READ record
process record...
IF current record IND = 'A'
IF current record date-time older than newest-a
escape top
else
move current record isn and date-time to newest-a
escape top
end-if
and you would have the same sort of code for D and R.