0

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?

LppEdd
  • 20,274
  • 11
  • 84
  • 139
  • The answers in a topic are difficult to comprehend when they lead down a trail that completely diverges from the original topic subject and text of the OP. The text buried in a comment in one of the _answers_ should be inserted in the OP: _I'll try to be clear on what I need to do. I have to automate the process of replacing characters in source files (that's why multi-member), but also keeping the previous version of the record, by commenting it. How would you do that? I'd just shift the RRN from the lowest record by one and then add the new one._ – CRPence Aug 01 '16 at 19:02

4 Answers4

2

Here is an interesting discussion about commenting out code vs using a source-code-management (SCM) system.

Why unused code should be deleted?

Community
  • 1
  • 1
Barbara Morris
  • 3,195
  • 8
  • 10
  • Hi Barbara! It's my company standard, can't change it ; ) We keep track of everything (like a change history in Eclipse RCP). – LppEdd Jul 13 '16 at 19:25
  • 1
    @LppEdd, Nice thing about standards. They are not written in stone. They can and should change with the times. Unfortunately, RPG shops are often the least likely to "upgrade" their coding. But it can be done. I've gotten RPG standards changed in a billion dollar fortune 600 company. – Charles Jul 14 '16 at 16:55
1

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.

Charles
  • 21,637
  • 1
  • 20
  • 44
  • Hi Charles! I'll try to be clear on what I need to do. I have to automate the process of replacing characters in source files (that's why multi-member), but also keeping the previous version of the record, by commenting it. How would you do that? I'd just shift the RRN from the lowest record by one and then add the new one. – LppEdd Jul 12 '16 at 21:08
  • 3
    @LppEdd You do it the same way any source editor does it. Read the records into an array and add the new row when you write the modified array back out to the member. All records are always written back out after clearing the member. Modifications are made to the array in memory. – user2338816 Jul 13 '16 at 02:30
  • Just to give you a little "update". At that time I had basically just started working (first job), and I was tasked with changing a lot of printer files. Since it was boring, I thought why not create something automatic? In the end I used JT400 (https://github.com/lppedd/j) instead of relying on RPG code. – LppEdd Feb 11 '19 at 22:18
1

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.

CRPence
  • 1,259
  • 7
  • 12
  • Hi! In the end I used the technique you mentioned, but via JT400! I copied all the records in a List, added what I wanted, and then created a new member with SequentialFile. – LppEdd Aug 01 '16 at 22:03
0

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

Barry
  • 448
  • 5
  • 10