TexAS400 Tutorial


Using DDS Specs to Print a Report

As mentioned in the previous topic, there are 3 ways that reports get printed using RPG.

This topic will look at how to print using a print file defined with DDS specs.

In an earlier topic, we saw how to use DDS to define a physical file and a logical file. DDS is also used to define print files and display files. A future topic will discuss display files.

A display and print file are different from a physical file in two ways:
1)   A physical file can have only 1 record definition.
2)   A print file and a display file are really defining different records, not data. I think of print files as a buffer in memory that       describes a print line.

To create the print file, STRPDM and add a member to QDDSSRC in your library. Make sure the TYPE is PRTF.

Add a member named CUSW007. Enter the specs shown in the DDS attachment. Or if you are lazy, copy it from library USER000.


 Columns . . . :    1  71            Edit                       USER000/QDDSSRC
 SEU==>                                                                 CUSW007
 FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0001.00      A* THE NEXT LINE TELLS THE COMPILER TO LOOK IN THIS FILE          
0002.00      A* FOR FIELDS THAT USE THE R FOR REFERENCE                        
0003.00      A                                      REF(CUST)                  
0004.00      A* SKIPB(1) MEANS SKIP TO THE TOP OF THE NEXT PAGE BEFORE         
0005.00      A* PRINTING THE HDG1 RECORD                                       
0006.00      A          R HDG1                                                 
0007.00      A                                      SKIPB(1)                   
0008.00      A                                     2DATE(*YY) EDTCDE(Y)
0009.00      A                                    26'CUSTOMER ORDER REPORT'    
0010.00      A                                    60'PAGE'                     
0011.00      A                                    67PAGNBR                     
0012.00      A* SPACEA(2) MEANS TO SPACE DOWN 2 LINES AFTER THE HDG1 RECORD    
0013.00      A                                      SPACEA(2)                  
0014.00      A*----------------------------------------------------------------
0015.00      A          R HDG2                                                 
0016.00      A                                      SPACEA(1)                  
0017.00      A                                    48'# OPEN'                   
0018.00      A                                    59'AMT OPEN'                 
0019.00      A*----------------------------------------------------------------
0020.00      A          R HDG3                                                 
0021.00      A                                      SPACEA(1)                  
0022.00      A                                     2'CUST #'                   
0023.00      A                                    10'CUSTOMER NAME'            
0024.00      A                                    48'ORDERS'                   
0025.00      A                                    60'ORDERS'                   
0026.00      A                                      SPACEA(2)                  
0027.00      A*----------------------------------------------------------------
0028.00      A          R DETAIL                                               
0029.00      A                                      SPACEA(001)                
0030.00      A            CSNBR          4S 0O     2
0031.00      A            CSNAME        30A  O    10                           
0032.00      A* THE EDTCDE(1) INDICATES TO EDIT THE NUMERIC FIELD USING        
0033.00      A* THE SYSTME DEFINED CODE OF 1. THIS IS WITH COMMAS, DECIMALS    
0034.00      A* AND NEGATIVE SIGN                                              
0035.00      A            CS#OPN    R        O    51EDTCDE(1)
0036.00      A            CS$OPN    R        O    56EDTCDE(1)
0037.00      A*----------------------------------------------------------------
0038.00      A          R TOTAL                                                
0039.00      A                                      SPACEA(001)                
0040.00      A                                    30'TOTAL'                    
0041.00      A            TOTOPN         9S 2O    58EDTCDE(1)                  
        ****************** End of data ****************************************

I have chosen to use the same field names in the print file as the input file that I will read. I could have used different field names, but RPG handles fields with identical names in an interesting way.

If a field is defined in more than one place:
1)   it must be the same length and type in all places.
2)   the most recently assigned value will be used for all occurrences of the field.

So, since we use the same values in the print file as the input, we need only read the input file and write the print records. As before, we still need to take care of headings and page control.

To show you different techniques, I stated the length and type of CSNBR and CSNAME in the DDS. For the other fields, I put in R in the REF column. This tells the compiler to look for the field with this name in the file named at the top in the REF option. It gets the field type and length from the file CUST since that is the file named in the REF parameter. Defined fields using the REF technique are easier and preferred.

If you are familiar with RLU (Report Layout Utility), you could use it to create the DDS for the print file. RLU is confusing to most AS/400 programmers and is not widely used.

When you have entered the DDS, use option 14 to compile it. Since the type is PRTF, the AS/400 compiler knows to execute command CRTPRTF.

Then, enter the RPG or RPG-ILE source code and compile. Notice that the RPG programs use the printer file as the output file.

Call the program from the command line and a print file will be created. Use WRKSPLF to see it.

To view the print report and programming code in RPG, click here.

To view the print report and programming code in RPG-ILE, click here.

 

 

Back to Table of Contents   |   Main Page