Using Program Described Printer File in RPGLE

This article will explain how to use program described printer file in RPGLE program in O-Specs.
Using Program Described Printer File in RPGLE, internal printer file, printer file, prtf, program described prtf, using internal prtf in rpg program, o-specs in rpg, o-specs printer file, o-specs prtf, ibmi, as400, as400andsqltricks
Using Program Described Printer File in RPGLE

Introduction to Program Described Printer files in IBM i

A printer file (records and fields) defined within an HLL application program is called a program described printer file. This can be used only within the program and the layout source(records and fields) would be defined in O-SPECS of the RPG program.

Using CRTPRTF command

CRTPRTF command is used to create the program described printer file object by not specifying any external source member and only specifying the lines and their width using keyword PAGESIZE and also specifying the overflow indicator using keyword OVRFLW.

CRTPRTF FILE(EASYCLASS1/PRTF11) PAGESIZE(66 132) OVRFLW(60)

Example using system-defined printer file QSYSPRT in RPGLE program

Let's see the example Using the program described printer file in O-specs in the RPGLE program.

     FPF1       IF   E           K DISK                       
     FQSYSPRT   O    F  132        PRINTER OFLIND(*IN01)      
      /Free                                                   
         EXCEPT HEADER;                                       
         setll *loval PF1;                                    
         read PF1;                                            
         dow not%eof(pf1);                                    
           if *in01 = *ON;                                    
             EXCEPT DUMMY;                                    
             EXCEPT HEADER;                                   
             *IN01 = *OFF;                                    
           endif;                                             
             EXCEPT DETAIL;                                   
           read PF1;                                          
         enddo;                                               
         EXCEPT FOOTER;                                       
         *inlr =  *ON;                                        
         return;                                              
      /End-Free
     OQSYSPRT   E            HEADER                                         
     O                                           12 'PAGE NUMBER'           
     O                       PAGE                18                         
     O                                           45 'PROGRAM DESCRIBED PRTF'
     O                                           75 'DATE'                  
     O                       UDATE         Y     85                         
     O          E            HEADER      1                                  
     O                                           15 'FLD1'                  
     O                                           25 'FLD2'                  
     O          E            DETAIL      1                                  
     O                       FLD1                15                         
     O                       FLD2                25                         
     O          E            FOOTER      1                                  
     O                                           50 'END'                   
     O          E            DUMMY       7                                  
     O                                           50 '   '                        

Let's discuss the explanation of the above code line by line as below.

     FPF1       IF   E           K DISK

Here, the Externally described keyed physical file named PF1 has defined F specs in Input mode.

FQSYSPRT   O    F  132        PRINTER OFLIND(*IN01) 

Here, the system-defined printer file QSYSPRT has been defined as a program described as having a record length of 132 and associated with the overflow indicator *IN01 using OFLIND keyword.

 EXCEPT HEADER;

Here, we are printing header record format on the first page of the printer file as defined in the O SPECS.

    setll *loval PF1;                                    
         read PF1;        

Here, first the pointer set to lower limit on PF1 and then the record gets read.

         dow not%eof(pf1);                                    
           if *in01 = *ON;                                    
             EXCEPT DUMMY;                                    
             EXCEPT HEADER;                                   
             *IN01 = *OFF;                                    
           endif;                                             
             EXCEPT DETAIL;                                   
           read PF1;                                          
         enddo;

Here, we are reading records from file PF1 in a loop until they reached the end of the file. Within the loop, we check overflow indicator *IN01 sets to ON then only write the dummy record format and header record format and also reset the overflow indicator *IN01. Always write the detailed record format within the loop so that all the records from file PF1 get printed.

     EXCEPT FOOTER;                                       
         *inlr =  *ON;                                        
         return;       

Here, we write the footer once all the details are printed. At last setting *INLR to ON and return from the program.

OQSYSPRT   E            HEADER                                         
     O                                           12 'PAGE NUMBER'           
     O                       PAGE                18                         
     O                                           45 'PROGRAM DESCRIBED PRTF'
     O                                           75 'DATE'                  
     O                       UDATE         Y     85                         
     O          E            HEADER      1                                  
     O                                           15 'FLD1'                  
     O                                           25 'FLD2'                  
     O          E            DETAIL      1                                  
     O                       FLD1                15                         
     O                       FLD2                25                         
     O          E            FOOTER      1                                  
     O                                           50 'END'                   
     O          E            DUMMY       7                                  
     O                                           50 '   '                        

This is the layout of the program described printer file in O-SPECS which signifies how the records and their fields would be printed in the printer file.

The first thing is that we defined QSYSPRT as an internal printer file and several record formats have been defined. The first record format is HEADER and we used PAGE system value which automatically sets the page number for the printer file and used UDATE for getting the six-digit date(mmddyy) and used edit code Y with it to format it using mm/dd/yy. The second record format is HEADER again which will only print for the columns such as fld1 and fld2 on the specified end position by specifying one space before printing the second header record format. The third record format is DETAIL and gives one space before its printing and we directly referred to physical file fields fld1 and fld2 to be printed. The fourth record format is FOOTER where we print the end of the report once all the detail has been printed. At last DUMMY record format has been defined which will print the blank value before specifying 7 line spacing since the overflow line number is 60 and printer file QSYSPRT can have 66 lines per page So, using this we will jump to the next page for HEADER printing. Finally, all the record formats would be printed using EXCEPT opcode as E(Exception) used in O-specs.

Compile and Execute the RPG program for program described printer file

  • Take option 14 on the RPGLE source member which triggers the CRTBNDRPG command to create the RPGLE program
  • Using command CALL <program-Name> from the command line to call the program and print the program described printer file(spool).
  • Output: Printed spool

     PAGE NUMBER     1     PROGRAM DESCRIBED PRTF                          DATE   4/02/22    
               FLD1      FLD2                                                                
         b              00006                                                                
         b              00006                                                                
         b              00006                                                                
         b              00006                                                                
         b              00006                                                                
         b              00006                                                                
         b              00006                                                                
         b              00006                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                                                
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                                 
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                             
         c              00007                                                                  
         c              00007                                                                  
                                                                 
     PAGE NUMBER     2     PROGRAM DESCRIBED PRTF                          DATE   4/02/22      
               FLD1      FLD2                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007                                                                  
         c              00007              
         c              00007                                                            
         c              00007                                                            
         A              00005                                                            
         A              00005                                                            
         A              00005                                                            
         A              00005                                                            
         A              00005                                                            
         A              00005                                                            
         A              00005                                                            
         A              00005                                                            
                                                   END                                   
            
    

    Using user-created program described printer file in RPGLE program

  • First, create a printer file using the CRTPRTF command as below:
  • CRTPRTF FILE(EASYCLASS1/PGMPRTF) PAGESIZE(66 132) OVRFLW(60)
  • Then use the above-created PRTF as the program described(internal) prtf in RPGLE program by specifying its record length.
  •      FPF1       IF   E           K DISK                      
         FPGMPRTF   O    F  132        PRINTER OFLIND(*IN01)     
          /Free                                                  
             EXCEPT HEADER;                                      
             setll *loval PF1;                                   
             read PF1;                                           
             dow not%eof(pf1);                                   
               if *in01 = *ON;                                   
                 EXCEPT DUMMY;                                   
                 EXCEPT HEADER;                                  
                 *IN01 = *OFF;                                   
               endif;                                            
                 EXCEPT DETAIL;                                  
               read PF1;                                         
             enddo;                                              
             EXCEPT FOOTER;                                      
             *inlr =  *ON;                                       
             return;                                             
          /End-Free  
         OPGMPRTF   E            HEADER                                          
         O                                           12 'PAGE NUMBER'            
         O                       PAGE                18                          
         O                                           45 'PROGRAM DESCRIBED PRTF' 
         O                                           75 'DATE'                   
         O                       UDATE         Y     85                          
         O          E            HEADER      1                                   
         O                                           15 'FLD1'                   
         O                                           25 'FLD2'                   
         O          E            DETAIL      1                                   
         O                       FLD1                15                          
         O                       FLD2                25                          
         O          E            FOOTER      1                                   
         O                                           50 'END'                    
         O          E            DUMMY       7                                   
         O                                           50 '   '                    
    

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain