RPG/400 Help

REDPE (Read Prior Equal)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| REDPE   | Search        | File name,      | Data           |   _ ER BOF    |
| (N)     | argument      | Record name     | structure      |               |
*---------*---------------*-----------------*----------------*---------------*

The REDPE operation retrieves the next prior sequential record from a full procedural file if the key of the record matches the search argument. If the key of the record does not match the search argument, the indicator in positions 58-59 is set on and the record is not returned to the program.

Factor 1, the search argument, is optional and identifies the record to be retrieved. It can be a field name, a literal, a named constant, or a figurative constant. You can also specify a KLIST name in factor 1 for an externally defined file. If factor 1 is left blank and the full key of the next prior record is equal to that of the current record, the next prior record in the file is retrieved. The full key is defined by the record format or file used in factor 2.

Factor 2 must contain the name of the file or record format to be retrieved. A record format name in factor 2 is allowed only with an externally described file (identified by an E in position 19 of the file description specifications). The Result Field can contain the name of a data structure into which the record is read only if the file named in factor 2 is a program described file (identified by an F in position 19 of the file description specifications). See File Operations for a description of the way data is transferred between the file and data structure.

If the file from which you are reading is an update disk file, you can specify an N in position 53 to indicate that no lock should be placed on the record when it is read. See the RPG/400* User's Guide for more information.

You can specify a resulting indicator in positions 56 and 57 to be set on if the operation is not completed successfully. You must specify a resulting indicator positions 58 and 59. The indicator is set on if a record is not found with a key equal to the search argument, or if beginning of file is encountered. If a REDPE operation is not successful, you must reposition the file (for example, by a CHAIN (Random Retrieval from a File) or SETLL (Set Lower Limit) operation).

Note:
If factor 1 equals the key of the current record or if factor 1 is not specified, the key comparison takes place at the Data Management level; otherwise, it takes place within the RPG/400 program. If the file being read is defined as update and the compare is by RPG, a temporary lock on the prior record is requested and the search argument is compared to the key of that record. If the record is already locked, the program must wait until the record is available before obtaining the temporary lock and making the comparison. If the comparison is unequal, the record-not-found indicator is turned on, and the temporary record lock is removed. If no lock (N in position 53) is specified, a temporary lock is not requested.

If factor 1 is specified and one or more key fields in the file being read from are defined with ALTSEQ, ABSVAL, DIGIT, or ZONE, the result of the read operation may differ from that expected. The reason is that the content of the field on which the access path is built may not be the same as the content that the REDPE operation is using for its internal comparison.

A REDPE (with factor 1 specified) that immediately follows an OPEN operation or a BOF condition returns BOF. A REDPE (with no factor 1 specified) that immediately follows an OPEN operation or a BOF condition results in an error condition. The error indicator, if specified, in positions 56 and 57 is set on. The file must be positioned (using CHAIN (Random Retrieval from a File), SETLL (Set Lower Limit), READ (Read a Record), READP (Read Prior Record), or READE (Read Equal Key) (with factor 1 specified) ) prior to issuing a REDPE operation with factor 1 blank. A SETGT operation code should not be used to position the file prior to issuing a REDPE as this results in a record-not-found condition (because the record previous to the current record never has the same key as the current record after a SETGT is issued).

If the key used contains a numeric (packed or zoned) field, the search argument must exactly match the key field. For example, if the physical file uses a packed key of X'123C' for +123. and the search argument is 123, REDPE will use X'123F' and BOF will be returned.

Figure "REDPE Operation" shows an example of the REDPE operation.

REDPE Example

Figure 48. REDPE Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C* With Factor 1 Specified...
C*
C* The previous record is read and the key compared to FIELDA.
C* Indicator 99 is set on if the record's key does not match
C* FIELDA.
C           FIELDA    REDPEFILEA                    99
C*
C* The previous record is read from FILEB and the key compared
C* to FIELDB.  The record is placed in data structure DS1.  If
C* the record key does not match FIELDB, indicator 99 is set on.
C           FIELDB    REDPEFILEB     DS1            99
C*
C* The previous record from record format RECA is read, and
C* the key compared to FIELDC.  Indicator 88 is set on if the
C* operation is not completed successfully, and 99 is set on if
C* the record key does not match FIELDC.
C           FIELDC    REDPERECA                   8899
C*
C* With No Factor 1 Specified...
C*
C* The previous record in the access path is retrieved if its
C* key value equals the key value of the current record.
C* Indicator 99 is set on if the key values are not equal.
C                     REDPEFILEA                    99
C*
C* The previous record is retrieved from FILEB if its key value
C* matches the key value of the record at the current position
C* in the file.  The record is placed in data structure DS1.
C* Indicator 99 is set on if the key values are not equal.
C                     REDPEFILEB     DS1            99
C*
C* The previous record from record format RECA is retrieved if
C* its key value matches the key value of the current record in
C* the access path.  Indicator 88 is set on if the operation is
C* not successful; 99 is set on if the key values are unequal.
C                     REDPERECA                   8899


[ Top of Page | Previous Page | Next Page | Table of Contents ]