Ü READPE (N | E) (Read Prior Equal)
§ READPE
moves the pointer to the previous record and reads the record and again moves
the pointer to next previous position and read the same matching record for
factor-1.
§ Factor-1
is used to place the search argument which can be the key, relative record
number or field value or named constant or figurative constant used to retrieve
the record.
§ READPE
is best used when there can be more than one record found. For example, you can
find multiple customer orders in your system for one unique customer in reverse
order while CHAIN is best used to locate a unique record (like a customer
record).
§ Using
READPE, we can read all the records which match the records corresponding to
search argument in factor-1. If there are no records with the specified
criteria then the pointer will be set to BOF.
§ To
handle READPE exceptions (file status codes greater than 1000), either the
operation code extender 'E' or an error indicator at LO level can be used.
§ If
the data-structure is specified in result field then the result of the
operation is filled in the data structure.
§ The
Equal Indicator gets turned-on if the EOF condition is met else it will be off.
Instead of using this indicator we can also go for %EOF().
Factor 1
|
Op-code
|
Factor 2
|
Result Field
|
Resulting Indicators
HI LO EQ
|
Search argument
|
READPE(N|E)
|
File or record format name
|
Data structure to hold the result
|
|
Error
|
Beginning of file condition indicator
|
Example
To read a file in reverse order for a particular key value
ACCSUBPF = Physical file
used
ORG CODE ACC NUMBER CURRENCY ACCOUNT MNG COUNTRY PARTY
000001 190 A00000000001 EUR DFJASHN NKDAHFJ P00000000001
000002 191 A00000000002 USD DAJFK DAJH P00000000001
000003 192 A00000000003 TRY DAHB BJDKFA P00000000001
000004 193 A00000000004 USD KIRAN NDKAL P00000000001
000005 194 A00000000005 KWR DANK NKD P00000000001
000006 195 A00000000006 TRY APPRINA SOUTN P00000000001
000007 195 A00000000007 USD SONATNA SOUTN P00000000001
****** ******** End of report ********
Columns . . . : 6 80 Browse AMITCC/QRPGLESRC
SEU==> OP_READPE
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 FACCSUBPF IF E K DISK 130211
0002.00 C 'P00000000001'SETGT ACCSUBPF 130211
0003.00 C 'P00000000001'READPE ACCSUBPF 130211
0004.00 C DOW NOT %EOF() 130211
0005.00 C ACC DSPLY 130211
0006.00 C READPE ACCSUBPF 130211
0007.00 C ENDDO 130211
0008.00 C SETON LR 130211
****************** End of data *******************************************************
OUTPUT
A00000000007
A00000000006
A00000000005
A00000000004
A00000000003
A00000000002
A00000000001