I'm using the RECNO keyword with a Physical file. The PF has duplicate records. I need to know how to add, update and delete records using the RECNO field. How do I update the duplicate records in the PF thru' a subfile/single record format? Also, I need to know how to delete and add records to the PF using the RECNO keyword.
The following is a restriction to be aware of when processing by relative record number. This is quoted right out of the RPG programmers guide. "When you update or add a record to a file by relative record number, the record must already have a place in the member. For an update, that place must be a valid existing record; for a new record, that place must be a deleted record."
If you are using this approach in order to re-use deleted space in your file, an easier alternative is to let OS/400 do that for you by changing your physical file to re-use deleted records. I would also suggest adding a logical file so that you could more easily check for and prevent duplicate data records.
As far as relating the record in your subfile to the relative record number in your file, I would suggest that your program populate a hidden field to your subfile that contains the relative record number you just read. You can get the relative record numbers by using the file information data structure in your program. Following is some sample RPGIV code that demonstrates some of the techniques you were asking about.
F**** Use file information Data structure on
FMYFILE IF E DISK
F**** This name need to match the name specified on the INFDS above
D*** RRN of record last read (will be filled by
D FILRRN 397 400B
C* IF YOU ARE READING A FILE FROM BEG TO END, DO A SETLL TO ENSURE
C* THAT INFDS INFO IS ACCURATE
C 1 SETLL
C* MOVE FILE RELATIVE RECORD NUMBER TO HIDDEN FIELD IN SUBFILE
C N50 Z-ADD FILRRN
C* Example of chain using RRN
C MOVEL 1 RRN# 9 0
C RRN# CHAIN MYFILE
C* Example of delete using
C RRN# DELETE MYFILEFM
Dig Deeper on RPG iSeries programming
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.