READPE
Estimated reading time: 4 minutes
Reads the next prior sequential record from a full procedural file that has the same search argument.
READPE
From (File Name | Format Name)
Key (<u>*CURRENT</u> | KeyList Name | Character Expression)
Access (<u>*DFT</u> | *NOLOCK)
Err (*EXTENDED | Indicator Variable)
Bof (Indicator Variable)
Eof (Indicator Variable)
IntoDS (Data structure)
Parameters
From
Required. Must contain a file name or a record format name.
Key
Optional. Determines the key in which to search the file by. Refer to %KDS to use this built-in function to establish search arguments (Key) for Data Structures.
Access
Optional. Determines if records are locked.
- *DFT – (Default) If the parameter is not given, the default record locking behavior is taken. This means, if File is specified as INPUT, all records are read without locks and the extender must be blank. If File is specified as UPDATE, all records are locked if blank.
- *NOLOCK – If this option is specified, then in no case will the record be locked when the READPE operation is successful. The file specified in From is positioned so a subsequent read operation retrieves the next sequential record following the retrieved record.
Err
Optional. Determines what the runtime will do if an error occurs while executing this command. The following rules apply:
- Err (Indicator Variable) - The specified Indicator is set if an error occurred.
- Err (*EXTENDED) - a program status flag is set whose status can be checked using the %ERROR built-in function or the Files’ IsError property
- If the Err keyword is not given and an error occurs, a runtime exception will be thrown.
If the file is a multiformat file accessed by RRN, you cannot perform the operation using the file Name, you must use the format name.
Bof
Optional. The Bof indicator will be set if the Beginning-Of-File was reached.
Eof
Optional. Use the Eof (End-of-File) indicator, the %EOF function, or the Files’ IsEof property to determine if the End-Of-File was reached while executing the command.
If any other error occurs, the error indicator will be set. The End of File indicator is also set when no more records exist with the same search argument.
IntoDs
Optional. The name of the data structure to read from. The data structure must be of the same type and size that the file is expecting, or a runtime error will occur.
Remarks
If the READ operation is successful, the file is positioned at the record prior to the one just read.
Example
/* With Key specified, the ReadPE operation retrieves the previous record from the file CustMast and compares its key
to the search argument, CustNumb. Indicator 55 is set on if CustNumb is not equal to the key of the record read or if
beginning of file is encountered. Indicator 99 is turned on if any error occurred during ReadPE operation. */
ReadPE CustMast CustNumb Bof(*In55) Err (*In99)
If *In55 = *On
Exsr BeginningOfFile
Endif
If *In99
Exsr ErrorOnRead
Endif
/* With Key specified, the ReadPE operation retrieves the previous record of the type CustRecd from an externally described
file and compares the key of the record read to the search argument, CustNumb (CustRecd is a record format name).
Indicator 55 is set on if CustNumb is not equal to the key of the record read or if Beginning-of-File is encountered.
Indicator 99 is turned on if any error occurred during ReadPE operation. The record is also unlocked after the read for an
update described file. */
ReadPE CustRecd CustNumb Access(*noLock) Bof(*In61) Err (*In99)
If *In61 = *On
Exsr BeginningOfFile
Endif
If *In99
Exsr ErrorOnRead
Endif
/* With no Key specified, the ReadPE operation retrieves the previous record in the access path from the file CustMast
if the key value is equal to the key value of the record at the current cursor position. If the key values are not
equal, indicator 55 is set on. Indicator 55 is also set on if the beginning of file is reached. Indicator 99 is turned
on if any error occurred during the ReadPE operation. */
ReadPE CustMast Bof(*In55) Err (*In99)
If *In55 = *On
Exsr BeginningOfFile
Endif
If *In99
Exsr ErrorOnRead
Endif
/* With no Key specified, the ReadPE operation retrieves the previous record in the access path from the file CustMast
if the key value equals the key value of the record at the current position. CustRecd is a record format name.
Indicator 61 is set on if the key values are unequal. Indicator 61 is also set on if the Beginning-of-File is reached.
Indicator 99 is turned on if any error occurred during ReadPE operation. The record is also unlocked after the read for
an update described file. */
ReadPE CustRecd Access(*noLock) Bof(*In61) Err (*In99)
If *In61 = *On
Exsr BeginningOfFile
Endif
If *In99
Exsr ErrorOnRead
Endif