FILE ACCESS


File access within RPG programs is consistent with each type of file. All RPG database file-operation codes function identically on physical, logical, and join-logical files. The only exception to this is when a file has been defined to the operating system as read-only. In this situation, output operations aren't allowed.

When a file is defined to a program as a keyed file (i.e., the letter K is specified in column 31 of the file specification), RPG processes the file by the file's access path. When a file is defined as a sequential file (i.e., column 31 contains a blank), RPG processes the file's records in the order in which they appear in the file.

When a file is defined as a keyed file to the RPG program, the operations that retrieve records from a file can access those records randomly through the access path. With some operations, the record's data is copied to the input (buffer) area for the file, while others simply reposition the file cursor. Table 11.10 lists the effect of the file operations on a database file when the operation is successful.

Table 11.10: Cursor Positioning after Successful Operation

Op Code

Data Returned

Record Status

Cursor Positioning

CHAIN

Yes

Locked

To record

DELETE

No

Deleted

To no record

EXCEPT

No

Released

To same record

FEOD

No

Released

To no record

OPEN

No

None

Beginning of file

READ

Yes

Locked

To record

READE

Yes

Locked

To record

READP

Yes

Locked

To record

READPE

Yes

Locked

To record

SETGT

No

Released

After record

SETLL

No

Released

Before record

UNLOCK

No

Released

To same record

UPDATE

No

Released

To same record

WRITE

No

Released

To same record

When any operation causes the file cursor to be positioned to the record or before the record, a subsequent READ or READE operation retrieves the next record in the file. A subsequent READP or READPE retrieves the prior record in the file. Additionally, if the N (no lock) operation extender is used with any of the input operations, no record lock is applied to the retrieved record.

Read Equal Key Anomaly

The READE (Read Next Record with Equal Key) and READPE (Read Prior Record with Equal Key) operations can cause record-lock contention under the following conditions:

  • When the operation reads a record, the record is reviewed for the equal-key condition. If the key value for the record doesn't match the value in factor 1, the record is released, and data is never copied to the input (buffer) area.

  • During the review of the key value for the record, the record is locked based on the conditions specified for the file on the file specification.

  • If the record is already locked by another application, the READE or READPE operation waits for the record to be released for a time specified by the file's description. This wait period is specified external to the RPG program.

  • When the wait-time expires, the RPG exception/error handling routine receives control unless resulting indicator 2 is specified. If resulting indicator 2 is specified, it is set on. To avoid the record lock, the N operation extender (NO LOCK) can be used. Specify READE(N) or READPE(N) to avoid placing the lock on the database record.

Tables 11.11 through 11.26 list the position of the file cursor after the specified operation code has been performed successfully.

Table 11.11: CHAIN Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

The file PARTMAST is used in these examples. It contains the key field PART (part number). Only the key field is depicted in the figures. Prior to each operation, the record containing the part number 5738SS1 has been successfully retrieved with the CHAIN operation. Tables 11.11 through 11.26 diagram what happens to the file cursor and the part number record after the specified operation has been performed.

Table 11.12: DELETE Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

. . .

84VETTE

*END

*NORECORD

Table 11.13: EXCEPT (to Add) Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.14: EXCEPT (to Delete) Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

. . .

84VETTE

*END

*NORECORD

Table 11.15: EXCEPT (to Release) Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.16: EXCEPT (to Update) Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.17: FEOD Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.18: OPEN Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

. . .

84VETTE

*END

*NORECORD

Table 11.19: READ Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.20: READE Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.21: READP Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.22: READPE Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.23: SETGT Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.24: SETLL Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.25: UPDATE Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD

Table 11.26: WRITE Operation

File Cursor Position

Part (Index) Number

*START

LBY17YR

Q385381

5738SS1

84VETTE

*END

*NORECORD




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net