2

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?

Charles
  • 21,637
  • 1
  • 20
  • 44
Yusha
  • 1,496
  • 2
  • 14
  • 30

3 Answers3

6

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;
Charles
  • 21,637
  • 1
  • 20
  • 44
1

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...

Dam
  • 986
  • 1
  • 14
  • 20
  • You do realize that you can use a RRN with or without a datastructure. The RRN is used to choose a specific record much like a key in a keyed access file. It has nothing to do with where the retrieved data is stored (data structure or not). – jmarkmurphy Jul 11 '17 at 12:36
  • Does the above example get the full 10 positions or just the first 4 bytes (64K) records? – danny117 Jul 11 '17 at 14:41
  • The 4-byte or 10-digit unsigned value in positions 397-400 of the INFDS can have a value up to 4,294,967,295. – Barbara Morris Jul 11 '17 at 16:10
  • your right @jmarkmurphy, my comment was misleading. I wanted to say in relation with the original question "I can store that position and get back to it later?", that I think using RRN is not the right method if the file has, and is processed by a key. If I want to go back to a position, I keep the key (in a DS or whatever), and re-do a chain / update . I feel unsafe about keeping RRN, what if another process changes the file while you're processing it ? Of course, it depends on usage and context, if the file has no key, you have no choice, but generally speaking, I tend to avoid using RRN :-) – Dam Jul 11 '17 at 20:03
  • RRN is a fixed value once a record is written. it will always have the same RRN until it is deleted. Even if someone deletes or reuses a record physically ahead of the RRN in question. The one exception to this is if the file is reorged, but that requires exclusive locks, so it won't mess with your cached RRN's as long as use them in the same job that you retrieved them. – jmarkmurphy Jul 12 '17 at 13:32
-1

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.

danny117
  • 5,581
  • 1
  • 26
  • 35
  • 4 byte integer returned in the DS **is** 10 digits...can have a value of up to 4,294,967,295. – Charles Jul 12 '17 at 16:58
  • Even if you are assuming the old binary data type, they support 9 digits, so you could index 999,999,999 records not 64K. – jmarkmurphy Jul 18 '17 at 16:01
  • I just know at one place I was at evertime the orders were more than 65k in one day there was a problem. Maybe the ds there was defined incorrectly. It was RPG II code. – danny117 Jul 18 '17 at 16:57