how to use a periodic descriptor for a logical read of an ADABAS file? as the periodic fields are not allowed to be ued with read but it has been defined as a descriptor for the adabas file
Try coding a FIND statement instead.
First, Aseem, you are correct, you cannot do a READ IN LOGICAL SEQUENCE by a field within a periodic group that is a descriptor.
Why are you not allowed to do this? One reason might be the repetitive read performance problem. Suppose I have a descriptor field in a Periodic Group that has credit card names in order by frequency of use.
One record might have MASTER, MASTER, VISA, MASTER.
In the associator there are tables that functionally (not physically) look like:
CC(1) = MASTER CC(2) = MASTER CC(3) = MASTER CC(4) = MASTER etc.
Thus, I would read the record above three times for MASTER and once for VISA.
By way of contrast, if CC was a Multiple valued field, we would only read the record twice, once for each unique value. This is because there would only be one table in the associator for CC = MASTER.
Some alternatives:
- SORT
You could utilize SORT (Natural’s or a totally separate SORT).
The following is just pseudo Natural code:
READ FILE IN physical sequence
move isn to #isn
for #loop = 1 to ccredit-card
move credit-card (#loop) to #cc
end-all
sort by #cc #isn using keys
You would read the above record once in the first loop, and create four spin off records (one for each MASTER and one for VISA).
When the spin off records come back, since you sorted by isn within value, the three spin off records for MASTER are contiguous, and you can code the second part of the sort loop such that you only read this record once for MASTER, not three times.
I have not played with this for awhile, but it may be you could have coded SORT BY #CC USING #ISN and accomplished the same thing. I believe this is true, but the above approach will definitely work.
- MU field
Without knowing your data I do not know if this is viable, but any field within a Periodic Group can be turned into a multiple valued field. HOWEVER, the program then becomes responsible for maintaining positionality (which is the major difference between a field within a PE and an MU). This could be quite messy, again, depending on your data.
However, if you go this route, you can now do a READ in logical sequence.
WARNING
Whichever route you go, please remember that when you end up reading a record for processing, you will have to “look” for all occurences of a specific value. Thus, if you converted to an MU field and you read a record that had values AMEX MASTER VISA AMEX ; it might be important for you to identify both AMEX’s, not just one.
steve
Hi Steve , One more thing is that the record for that periodic field is having same value in all occurence(wonder who put in that data) , so i need to use the very first value .The major problem is the frequency of this program run is supposedly on minutes basis(BATCH) and I am not able to figure out a performance friendly solution for it so that with the very first value of the occurence i could READ the file and compute the result.
take a look at using the HISTOGRAM command on the PE descriptor. Each value for a PE occurrence is returned as a separate value, with *NUMBER telling you how many there are and *ISN giving the occurrence of the PE for that value.
Thus, a READ LOGICAL can be emulated by using the HISTOGRAM and a FIND - use a FIND on AT START/IF BREAK of the descriptor to return the records for each unique value, or, if the index contains meaning, FIND on the specific PE occurrence you need.