On 25-May-2010 01:31, Gangasani, Bhargava wrote:
Using CLP I can read a specific RRN/ Key record using below code.
DCLF Z5PFILEP
OVRDBF FILE(Z5PFILEP) TOFILE(Z5PFILEP) +
POSITION(*RRN 4) SHARE(*NO)
RCVF
Question is: I can place my pointer at *END of file as
OVRDBF FILE(Z5PFILEP) TOFILE(Z5PFILEP) +
POSITION(*END) SHARE(*NO)
But How I can read the previous record. That is the Last record
of the file.
If the open can be shared, then write an RPG program that opens a
program described file named THELASTROW for input only BLOCK(*NO),
positions to *END using SETLL, reads previous twice, then returns
without closing the file; also having coded for the special cases of
less than three rows, to effect position at *START for one row, and
effect read on the first row for when there are two rows. In the CLP:
<code>
dclf Z5PFILEP
ovrdbf Z5PFILEP TOFILE(Z5PFILEP) share(*yes) seqonly(*no) /* +
// POSITION() optional; allow RPG to position */
ovrdbf TheLastRow TOFILE(Z5PFILEP) share(*yes) lvlchk(*no) /* +
// Not an actual file, just a name for RPG to declare */
rcvf /* CL opens shared lets RPG position w/ shared ODP */
monmsg cpf0864 exec(goto nodata) /* handle empty file in CL */
call RPGpgmNm /* RPG shares open, positions, leaves open */
rcvf /* read last record */
dostuff: /* CL has data from last row with the last row */
/* do whatever with data from last row, then optionally: */
rcvf /* get CL to close A; assuming no new rows added */
monmsg cpf0864 exec(rcvmsg pgmq(*same) msgtype(*excp) rmv(*YES))
rclrsc /* Effect RPG close; better: use USROPN in RPG, */
/* and code a special invocation to effect CLOSE */
Regards, Chuck