IBM i e-Book
A Developer’s Guide to Mastering IBM i Concepts
IBM i Index
Report Program Generator (RPG)
Printer Files
There are two different types of printer files:
- Program defined printer file
- Externally described printer file
1. Program defined printer file
A program described printer file is a printer file that is defined inside an application program. This indicates that the data division has internally defined descriptions for the file, record, and field. This approach involves hard-coding report specifications into the program, which are then included in the compiled object of the program.
Program:
Sample Code:
/Free Dcl-F SalAcc Usage(*input:*output) keyed; Dcl-F QPrint Printer(132) Usage(*output) Oflind(*In90); Except Header; Setll *Loval SalAcc; Read(n) SalAcc; Dow Not %Eof(SalAcc); If *In90 = *On; Except Header; Endif; Except Detail; Read(n) SalAcc; Enddo; Except Footer; *Inlr = *On; /End-Free OQPRINT E HEADER O 6 'PAGE' O Page 10 O 47 'SALARY ACCOUNT REPORT' O 65 'DATE' O Udate Y 75 O E HEADER 1 O 08 'EMPID' O 25 'DEPTCODE' O 40 'ACCOUNT NO' O 65 'SALARY STATUS' O E DETAIL 1 O EMPID 10 O DEPTCODE 22 O ACCOUNT_NO42 O STATUS 62 O E FOOTER 1 O 42 '******END OF REPORT******'
The program described printer file layout in O-SPECS shows how the records and their fields are supposed to print in the printer file.
In O-specs Press F4 define the QPRINT as an internal printer file and define a number of record formats. Defined Type E, by using the EXCEPT opcode as E(Exception) in O-specs, all record formats would be printed. First, we used the HEADER record format as EXCEPTNAME.
In O-specs assign the text “Page”, “SALARY ACCOUNT REPORT”, and “DATE” which will end at position 6, 47, and 65 respectively.
Defined the PAGE as field name at end position 10. Used PAGE system value to automatically set the page number for the printer file
we used the UDATE to get the six-digit date (mmddyy) and the edit code Y to format it using MM/DD/YY. Which will end at position 75.
The second record format is HEADER again, and it will only print the columns that contain “EMPID,” “DEPTCODE,” “ACCOUNT NO,” and “SALARY STATUS” at the end position that is specified. 1 is defined with HEADER to add one space before printing the second header record format.
We directly referred to the physical file fields EMPID, DEPTCODE, ACCOUNT_NO, and STATUS to be printed in the third record format, DETAIL, also 1 is defined with DETAIL which allows for one space before printing.
After printing all the details, we print the end of the report using the fourth record format, called FOOTER. 1 is defined with FOOTER to add one space before printing the second header record format.
Result
Advantages of Program-Defined Printer Files:
- The program is easy to maintain because the printer file specifications are directly embedded within it.
- During compilation, program and printer file changes are synchronized.
- There are no external dependencies because the printer file and the program are self-contained.
2. Externally described printer file
Any program that uses printer files that contain report specifications can define them externally. This indicates that a printer file’s report specifications are presented independently of any programs and combined into a printer file object.
Two ways to design an Externally described printer file:
- Design Externally described printer file using STRSEU.Create Source Member with type PRTF using STRSEU command.
This DDS entry’s designed screen is displayed below. Against this DDS source member, we choose option-19 in order to view the designed screen. - Design Externally described printer file using STRRLU:Step 1: Write STRRLU on the Command line then Press F4. Fill the Source Physical file, library, and source member name DEMOPRTF and press enter.Step 2: Insert line using then DR to define record format then VF to view field and press enter.
Step 3: On FLD1 write ‘SALARY ACCOUNT REPORT’ and press enter.
Step 4: Repeat step (2) to add more record format and field.
Step 5: Similarly, On FLD1 of RCD002 define the column as ‘EMPID’, ‘DEPTCODE’, ‘ACCOUNT NO’, and ‘SALARY STATUS’ and then press enter.
Step 6: On FLD1 Press F10 and give option 1 to add the fields from the database file SALACC and press enter. The selected field will show up at the bottom of the screen. Set the cursor at the FLD1 line where you want to add the field and Press Enter. The field definition will be placed there.
Step 7: Repeat step (2) and then Press F11 to define the field on FLD1 of RCD004 record format.
Step 8: Press SHIFT F6 + F10 to rename the record format. Rename RCD001 = HEADER, RCD002 = HEADER1, RCD003 = DETAIL, and RCD004 = FOOTER.
Example:
Program:
Sample Code:
Dcl-F SalAcc Usage(*input:*output) keyed; Dcl-F SalPrtf@ Printer Usage(*output) Oflind(*In90); Write Header1; Write Header2; Setll *Loval SalAcc; Read SalAcc; Dow Not %Eof(SalAcc); If *In90 = *On; Reset *IN90; Endif; Write Detail; Read SalAcc; Enddo; Write Footer; *Inlr = *On;
Result:
Advantages of Externally Described Printer Files:
- It’s not necessary to recompile the programs that use the printer file whenever changes are made. Such flexibility is very helpful when you need to change report layouts without having an impact on currently running programs.
- You can achieve better modularity and maintainability by separating report specifications from program logic.
- The same printer file can be shared by multiple programs, reducing redundancy and providing consistency.
- Data Description Specifications (DDS) for printer files with external descriptions can be created and reports can be generated using software tools.