Q
Problem solve Get help with specific problems with your technologies, process and projects.

How does one add, update and delete records using the RECNO?

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
file
FMYFILE IF E DISK
INFDS(FILDS)
F*

F**** This name need to match the name specified on the INFDS above
D FILDS
DS
D*** RRN of record last read (will be filled by
OS/400)
D FILRRN 397 400B
0
C*

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
MYFILE
C READ
MYFILE 50
C* MOVE FILE RELATIVE RECORD NUMBER TO HIDDEN FIELD IN SUBFILE
C N50 Z-ADD FILRRN
SFRRN
C*

C* Example of chain using RRN
C MOVEL 1 RRN# 9 0
C RRN# CHAIN MYFILE
75
C* Example of delete using
RRN
C RRN# DELETE MYFILEFM
76


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.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close