RPG/400 Help

READP (Read Prior Record)

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

The READP operation reads the prior record from a full procedural file (identified by an F in position 16 of the file description specifications).

Factor 2 must contain the name of a file or record format to be read. A record format name in factor 2 is allowed only with an externally described file. If a record format name is specified in factor 2, the record retrieved is the first prior record of the specified type. Intervening records are bypassed.

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 how data is transferred between the file and data structure.

If a READP operation is successful, the file is positioned at the next record that satisfies the read. If a READP 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). You can specify an indicator in positions 56 and 57 to be set on if the READP operation is not completed successfully.

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 must specify an indicator in positions 58 and 59 to be set on when no prior records exist in the file (beginning of file condition). If the file is not repositioned after this indicator is set on, the indicator is set for every subsequent READP operation to the file.

You must be reposition the file after the indicator is set on to process any further successful sequential operation (for example, READ (Read a Record)) to the file.

Figure "READP Operation" shows READP operations with a file name and record format name specified in factor 2.

READP Examples

Figure 47. READP Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  The READP operation reads the prior record from FILEA.
C*  Indicator 71 is set on if beginning of file is encountered.
C*  When indicator 71 is set on, the program branches to the
C*  label BOF specified in the GOTO operation.
C                     READPFILEA                    71 BOF
C   71                GOTO BOF                         BEG OF FILE
C*
C*  The READP operation reads the next prior record of the type
C*  REC1 from an externally described file.  (REC1 is a record
C*  format name.)  Indicator 72 is set on if beginning of file is
C*  encountered during processing of the READP operation.  When
C*  indicator 72 is set on, the program branches to the label BOF
C*  specified in the GOTO operation.
C                     READPREC1                     7272 = BOF
C   72                GOTO BOF
C*
C           BOF       TAG


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