Is it possible to get the position of the pointer reading through a Physical File in RPGLE?
That way I can store that position and get back to it later?
Is it possible to get the position of the pointer reading through a Physical File in RPGLE?
That way I can store that position and get back to it later?
You're looking for the relative record number (RRN?)
Position 397 of the File Information Data Structure (INFDS).
Example from the manual
DCL-F MYFILE DISK(*EXT) INFDS(DBFBK);
DCL-DS DBFBK;
FDBK_SIZE INT(10) POS(367); // Current line num
JOIN_BITS INT(10) POS(371); // JFILE bits
LOCK_RCDS INT(5) POS(377); // Nbr locked rcds
POS_BITS CHAR(1) POS(385); // File pos bits
DLT_BITS CHAR(1) POS(384); // Rcd deleted bits
NUM_KEYS INT(5) POS(387); // Num keys (bin)
KEY_LEN INT(5) POS(393); // Key length
MBR_NUM INT(5) POS(395); // Member number
DB_RRN INT(10) POS(397); // Relative-rcd-num
KEY CHAR(2000) POS(401); // Key value (max size 2000)
END-DS;
open the file with InfDs(InfDSk)
option, and InfDSk defined with :
dcl-ds InfDSk qualified ;
RRN uns(10) pos(397) ;
end-ds ;
The record number RRN (or recno) is available with : InfDSk.RRN
Instead of using RRN, in a keyed-accessed file, I prefer CHAIN to a specific datastructure and write the DS afterwards...
Get full 10 digits of RRN with SQL.
exec sql declare x1 cursor for select rrn(a) rn, a.* from myfile/mlib a;
exec sql open x1;
exec sql fetch next from x1 into :myds;
DANGER Data structure methods only returns four bytes 397-400 physical files with more than 64k records don't work.
On previous versions before the integer data types we're used.