Search code examples
ibm-midrangerpgle

Can you use RPG to append additional lines to a printer file?


Is there a way of appending additional lines to the end of a printer file? Most of the techniques that I have used to create printer files (RPG O specs, write to externally defined file) cause you to have one output file per program. I would like to write some number of lines in one program or procedure, then have another program or procedure open the file and write additional lines.

The specific use case is to have an "order header" that is the same for several reports with the line item data underneath being report specific. I suppose I could keep this all in one large program with the report variations being in separate RPG subroutines, but I like the modularity of calling for a general purpose header from several different programs and probably also additional reports in the future.

The architecture of the system may prevent this type of technique since I am not clear on how to either keep the file open and pass it or to open a closed file that has already been put into an out queue. I have used CPYSPLF in the past and while I probably could use that to read what was previously written, it seems pointless to create a file, close it, copy it to QTEMP, read it, then re-write it to another file, and then delete the first printer file. Perhaps there is some other way that I am not thinking of.


Solution

  • Yes, this is certainly do-able...
    Modern Way
    Take advantage of the LIKEFILE keyword to pass the opened printer file as a parameter. see https://www.itjungle.com/2012/03/21/fhg032112-story01/

    Old school way
    Create a CL program that issues an OVRPRTF FILE(PRNTFILE) SCHEDULE(*FILEEND) SHARE(*YES) then calls PGM1 and PGM2; PGM1 will need to leave the PRTF open, so don't set on *LR in PGM1.

    Here's an article: https://www.itjungle.com/2011/05/11/fhg051111-story02/