Link to home
Start Free TrialLog in
Avatar of MGothelf
MGothelfFlag for United States of America

asked on

iSeries: Capture RPG printer output as a string

I have an iSeries RPG program that writes a report using a printer file that has a dozen different record formats.  I need a way to repeat the printing of each page, without having to read through the data files a second or third time, and my solution is to capture the printer output and write to a file as a string of 132 characters.  I would like to avoid having to write a dozen routines to parse each record format as it is written and just save the 132 character buffer.  Is there a way to do this?
Avatar of daveslater
daveslater
Flag of United States of America image

Hi
you could use a Multi Occurance Data structure

the basic code is.



D ExtDs           ds                                                          
D  fld1                         10                                            
D  fld2                         10                                            
D**......                                                                      
D  fldx                         10                                            
                                                                               
D MODS            ds                  Occurs(12) Likeds(ExrDs)                
  /Free                                                                        
       Idx = 0 ;                                                              
       Dow '1' = '1' ;                                                        
          read Myfile ;                                                        
          if %eof ;                                                            
             leave ;                                                          
          endif ;                                                              
           fld1 = FileField1 ;                                                
           fld2 = FileField2 ;                                                
           fldx = FileField3 ;                                                
           idx+=1 ;                                                            
           %occur(Mods) = Idx;                                                
          Mods = ExtDs ;      
    enddo ;                


for idx1 = 1 to Idx ;
           %occur(Mods) = Idx1;                                                
          // move MOds to print file
          write format ;
endFor/


<<--------------------->>
 
Dave
Avatar of MGothelf

ASKER

I am already doing this with data structures in a slightly different way.  

It will not work for me to capture the INPUT fields because I need a solution that is easy to replicate withou having to recreate the data structures and input output logic each time.  The program logic does not allow for your solution because there are over a dozen record formats and different processing logic for each, so I would have to rewrite huge chunks of code.  (Where you say 'write format' would essentially be duplicating the entire program logic).

I need to capture the OUTPUT, that is the 132 character string that is being sent to the printer, so that I could then simply loop through the saved lines and write them out.
Can you post an example!
Are you wanting to duplicate pages in the same SPOOL file or will duplicateing the SPOOL file work?
Avatar of Member_2_276102
Member_2_276102

MGothelf:

It sounds like you have an existing program that had no design that allowed this to happen. And now you're asking for a way to get it done without changing the design.

Do you have the source code? It sounds like you do, because you discuss some of the program elements. So, we can probably assume that source code isn't an issue.

Are you allowed to make changes and re-compile? Again, it sounds like you do; but the question has to be asked.

Finally, are you an experienced developer in this language? There _might_ be a technique or two that you could use, but they'll be much easier to describe if we're fully informed of your level of comfort.

Can you please attach the output from DSPFD yourlib/yourfile TYPE(*RCDFMT) here?

Tom
I have an existing program.  It writes headers and detail lines.  It is now writing to a dot matrix printer that prints a 4-part form.  The user wants to replace with a laser printer, so that I would now have to print page 1 four times followed by page 2 four times etc.

What I have developed is a solution based on a series of 132-byte data structures, each of which stores the data fields that make up a record format in the Printer File.  As each record format is written, I copy the data fields to the appropriate data structure, then store the entire 132-byte data structure in an array of the print lines.

At the end of the normal printing of page 1, then go through the array and print the lines 1 by 1.  I do this 3 times (for page2, page3, page4).

This works OK, but if the layout changes, its a lot of code to maintain in each data structure.  Also, to duplicate this in another program is a bunch of work.

The PRTF is a normal printer file with a standard record length of 132 bytes. What I am hoping to find is a way to grab the 132-bytes that are sent to the printer buffer each time I do a WRITE.
The biggest problem you will have is forms control.
Let the system do that for you.

Here is some code for you.
Call the CL right after the RPG that creates the SPOOL file.  Give it a parm of the printer file name.
This process will be very flexable for you.

I am sure many newbies to RPG will find this code quaint.

Steve
             PGM        PARM(&FILE)
             DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)
             CRTPF      FILE(QTEMP/IN) RCDLEN(133)
             MONMSG     MSGID(CPF0000)
             CRTPF      FILE(QTEMP/OUT) RCDLEN(133)
             MONMSG     MSGID(CPF0000)
             CPYSPLF    FILE(&FILE) TOFILE(QTEMP/IN) SPLNBR(*LAST) +
                          CTLCHAR(*FCFC)
             CLRPFM     FILE(QTEMP/OUT)
             CALL       PGM(QUADRPG)
             OVRPRTF    FILE(QSYSPRT) CTLCHAR(*FCFC)
             CPYF       FROMFILE(QTEMP/OUT) TOFILE(QSYSPRT)
             ENDPGM
 
 
     Fin        ip   f  133        disk
     Fout       o  a f  133        disk
     D a               s            133    dim(100)
     d x               s              3  0
     d max             s              3  0
     d copies          s              3  0 inz(4)
     Iin        jn
     I                                  1    1  fcfc
     I                                  1  133  rec
     C     fcfc          ifeq      '1'
     C                   exsr      writeloop
     C                   endif
     C                   add       1             max
     C                   move      rec           a(max)
     Clr                 exsr      writeloop
     C     writeloop     begsr
     C     max           ifne      0
     C     1             do        copies
     C     1             do        max           x
     C                   except    record
     C                   enddo
     C                   enddo
     C                   clear                   max
     C                   endif
     C                   endsr
     Oout       eadd         record
     O                       a(x)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_276102
Member_2_276102

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Tom.
This solution is very clean and easy to understand. I have not worked with SPECIAL files, but that sounds like the way to go.