I need to write a new record at a specific position (ex: 3 out of 20) in a RRN (relative record number) processed PF. Specifically it's a multi-member PF.
How can I do that?
I need to write a new record at a specific position (ex: 3 out of 20) in a RRN (relative record number) processed PF. Specifically it's a multi-member PF.
How can I do that?
Here is an interesting discussion about commenting out code vs using a source-code-management (SCM) system.
You can't.
You can rewrite an existing record. But when writing a new record, the DB decides where it gets put.
If you have a file with 5 records, rrn# 1-5. And you delete records 2 & 3. You can't later add a record #3 again.
If the file is defined REUSEDLT(*NO), then it goes at the end. If the file is REUSEDLT(*YES), then the DB may reuse a deleted record or it may add it to the end of the file.
The default-description for a Source Physical File (PF-SRC) [i.e. the system-supplied definition, as created by the Create Source Physical File (CRTSRCPF) command] has a Source Sequence (SRCSEQ) field for line-numbering that allows for insertion of lines by tenths and hundredths, as an offset from any integer line-numbering value as SrcSeq. Having inserted new record(s) with line-numbering values between the values of existing line-numbers, those rows can be re-sequenced using the Reorganize Physical File Member (RGZPFM) with specification of a keyed Source Logical File (LF-SRC) that has defined SRCSEQ as the key over the physical source member; i.e. per specification of that LF on the Key File (KEYFILE) parameter for the reorganize request, optionally with the value of *SRCSEQ for the Source Update Options (SRCOPT) to effect the desired Source Sequence Numbering (SRCSEQ) defaulted or explicitly specified on that reorganize request.
The full effect could be achieved instead by performing [atomically]: a copy of the original source data into a temporary file, making the insert(s) of the offset-line-number record(s) [i.e. new SeqNbr between existing records] into the temporary copy, making updates in the temporary copy to the SrcDta for any particular old SeqNbr values, clearing the original source, then copying the ordered source data from the since-updated temporary copy into the original source member. In effect, mimicking the "way any source editor" per @user2338816 enables changing the data while also allowing for inserted lines.
I saw this comment you posted to another answer:
I'd just shift the RRN from the lowest record by one and then add the new one.
Not sure if this is relevant, but you could copy a record (by RRN) to the end of a file - you could even change this so it insert into another file? (like a source history file)
INSERT INTO YOURFILE
SELECT * FROM YOURFILE WHERE RRN(YOURFILE) = 40
And then update that record same record
UPDATE UCWSDTLS SET SRCDTA = 'Whatever' WHERE RRN(UCWSDTLS) = 40
Hope this is somewhat helpful