Ch7 Printer File Functions
Ch7 Printer File Functions
7
The Report Functions
This chapter introduces the two functions used to produce reports. These are:
You will use these functions to define the two following reports:
Objectives You will be producing a report that lists all the horses
recorded in your database. In addition, the report will
give the total number of horses recorded and the total
value of all the horses. The following steps are involved:
Defining the Starting from the Edit Functions panel for the HORSE
Print File file, specify the Print Horses function. A Print File
Function (PRTFIL) function is defined the same way as other
functions. Type Print Horses for the Function name,
PRTFIL for the Function type, and ? in the access path
field to view a list of existing access paths as shown.
Specifying a Use the Edit File Details panel for the HORSE file to
New Access Path create a new access path that will cause the report to
print horse details in alphabetical order by Horse name,
rather than in Horse code order. To achieve this,
specify a new access path of type RSQ called Horse
name order.
Press Enter.
Edit Access You used the Edit Access Path Details panel earlier in
Path Details this tutorial to specify a RSQ access path. You will use
the same process here to specify a new key order on
the access path format.
Press Enter.
The New Key Specify an alternative key order. For this type of access
Order path, you can choose any field except a virtual field as
a key field. Use Horse name as the key.
Generating and At the Edit File Details panel, request batch generation
Compiling the and compilation for the newly defined access path
New Access Path using the J option.
Selecting the Now that you have created the required access path,
Access Path select it for use with the Print Horses function.
Press Enter.
The Report After you select the access path, COOL:2E creates the
Design Print Horses function and returns to the Edit Functions
panel. From here you can display the report layout. To
do so, type S against the function as shown.
Press Enter.
The Default Initially, the report layout will look like the one shown
Report Layout here.
You can modify the report layout the same way you
modified the device designs of the earlier functions.
The editors for the report layout and the panel design
are very similar. However, a report is by default 132
characters across and extends vertically past the
bottom of the panel. You can press the Roll Up key to
roll the panel by half a panel at a time.
Displaying the The report formats are shown on the Display Report
Report Formats Formats panel. To access this panel, press F17 from
the device design (report layout).
Dropping In this step you will remove the Horse name heading
Formats from a and total formats. To remove a format, you can either
Report Design hide it or drop it completely. If you hide a format it will
still be logically present. In this example, you will drop
both formats completely.
Adding Function In this step, you will add two function fields to the Final
Fields totals format (ZTL).
Press Enter
Defining New The first new function field, Total horse value, will
Function Fields provide a total of all the Horse value fields on the detail
format. A function field of type SUM is used for this
purpose. Recall that you used a function field of this
type previously to calculate theTotal Number of finishers
in a race.
Press Enter
Specifying When you pressed Enter, the two new function fields
Function were created. Press Roll Up twice to view the two new
Parameters function fields.
Press Enter.
Press Enter.
Press F3 to exit.
Selecting the You have finished defining the two new function fields.
Function Fields You must now select them to appear on the Final totals
format.
Press Enter.
Confirming the The Edit Action - Function Details window will prompt
Function Details you to confirm details of the function parameters. This
panel shows the contexts from which the values of the
parameters will be taken: NXT (next report format) and
CUR (current report format).
Adding the Total The Total horse value function field is now present on
Number of the Final totals format. To add the other function field
Horses Function position the cursor (❚) on the Final totals format as
Field shown.
Press Enter.
Exercise Both function fields are now present on the Edit Report
Format Details panel of the Final totals format. Check
this yourself by pressing F17 from the report device
design and typing Z against the Final totals format on
the Display Report Formats panel. Press F13 to return
to the report device design.
The Report The report layout should now look like the one below,
Design with with the function fields displayed on the Final totals
Function Fields format. The words Final totals are a constant and can
be removed.
Completing the In this step, to make the report easier to read, you will
Report specify a blank line between records and hide the
Horse code, Dam code, and Sire code fields. In
addition, you will change the Horse name field from
hidden to output. By default, the Horse name field is
hidden because it was originally present on the Horse
name header format. Since the Horse name header
format has been dropped, it now makes sense to have
the Horse name appear on the Detail line format.
Press F5.
The Modified The report device design should now look like the one
Report Device shown below. Since you have hidden some fields on
Design the Detail format, the design no longer exceeds the 132
character size limit.
The Completed Update the report device design by moving fields and
Report Layout changing labels and label spacings until the design
meets your needs. Here’s an example.
Generating and You have now finished specifying the Print Horses
Compiling the function. Type J next to this function on the Edit
Function Functions panel and press Enter to request batch
generation of the Print File and program that will
implement the function.
call myaspfr ’’
Final totals
** END OF REPORT **
Defining the To define a Print Object function, start from the Edit
Print Object Database Relations panel and go to the Edit Functions
Function panel on the RACE ENTRY file.
Press Enter.
Adding a Print Specify the Print Object function by typing Print Race
Race Entries Entries for the function name, PRTOBJ for the function
Function type, and ? to display the available access paths as
shown.
Specifying a The Edit File Details panel shows the existing access
Query Access paths for the RACE ENTRY file. You will create a new
Path access path for the Print Race Entries function.
Displaying the Press Enter to display the Edit Access Path Details
Access Path panel. Next, type Z against the displayed format and
Format Entries press Enter to access the Edit Access Path Format
Entries panel.
Compiling the The access path you have just defined must be
QRY Access generated and compiled before running the application.
Path You have the option to add it to the job list now. To do
so, type J next to the QRY access path.
Press Enter.
Selecting the Now that you have defined the QRY access path, you
Access Path for need to select it for the Print Race Entries function. To
the Function do so, type X next to the QRY access path as shown.
Press Enter.
Displaying the Now that you have created the PRTOBJ function,
Report Device check the device design to see whether the default
Design options meet requirements. To access the device
design, type S next to the Print Race Entries PRTOBJ
function from the Edit Functions panel as shown.
Press Enter.
The Default Initially, the report device design should look like the
Report Device one shown below.
Design
3. Hide all fields that are not required and adjust labels
and label spacings until the design resembles the
one shown below.
Exiting the Save your design by accepting the defaults on the Exit
Device Design Function Definition panel
Combining the You have just finished defining the two report functions.
Report Functions Press F3 to exit the Edit Functions panel for the RACE
ENTRY file and return to the Edit Database Relations
panel.
Press Enter.
Embedding the The Edit Device Structure panel represents the layout
Print Race of the report in terms of the formats from which it is
Entries Function constructed. This display is only available for functions
of type PRTFIL or PRTOBJ. It has facilities for
embedding PRTOBJ functions within the report and
moving and copying them.
Press Enter.
Selecting the The Display Print Functions panel is now shown. This
PRTOBJ panel displays a list of all the Print Object functions that
Function are available for inclusion in the Print File function. In
this case there is just one, Print Race Entries. Type X
to select the Print Race Entries function as shown.
Press Enter.
Press F3 to exit.
Displaying the Examine the effect of the new device structure on the
Report Device layout of the Print Horses report device design. Type S
Design next to the Print Horses function on the Edit Functions
panel as shown.
Press Enter.
The New Report The modified report device design is shown with the
Device Design fields resulting from the embedded Print Object
function.
View the Rest of You can display the rest of the report device design by
the Report pressing Page Down (or Roll Up depending upon your
Device Design keyboard).
✍ Note: If your report device design does not look like that
shown above, adjust it until it looks similar. Do not
be concerned with exceeding the panel limits. For
reports, COOL:2E allows 132 characters per line.
Modifying the You are restricted in the placement of the fields from
Combined the Print Object function. Place the cursor on any
Report Device PRTOBJ field and press F10. All the PRTOBJ fields are
Design moved in a single block. In other words, you cannot
manipulate the PRTOBJ fields individually from this
panel. You are only allowed to alter the indentation of
the whole PRTOBJ function relative to the left-hand
margin of the PRTFIL function in which it is embedded.
It is possible to specify individual formats of the
PRTOBJ. You can specify an absolute indentation that
is fixed relative to the left-hand margin of the report,
regardless of any adjustments made to the indentation
of the PRTOBJ as a whole.
Press Enter.
Specifying You have now combined the two report functions and
Parameters have a suitable report design. However, the function is
not yet fully defined. If you generate and compile the
program now, it would print all the race entries in the
RACE ENTRY file after every horse. You need to pass
a restrictor parameter from the Print Horses function to
the Print Race Entries function so that only the race
entries that apply to each horse are printed after each
horse’s details.
Press Enter.
Press Enter.
The Print Details You embedded the PRTOBJ function after the detail
Construct line format. To reach the equivalent point in the action
diagram, type Z against the hidden construct,
...PRTOBJ calls after print of detail format, as shown.
Press Enter.
Editing the Print You have now reached the point in the action diagram
Race Entries where the PRTOBJ is embedded. Type Z against the
Function hidden construct, ...Embedded PRTOBJ : Print Race
Entries, as shown.
Press Enter.
The Action You can type ? in the Subfile selector of the Action
Diagram Editor Diagram Editor to display a list of allowed values.
Subfile Selector
Values Type ? as shown.
Press Enter.
Press Enter.
Press Enter.
Press Enter.
Exit Action Exit the action diagram and save the design you have
Diagram just completed. To exit the action diagram quickly, press
F13.
Generating and You have now finished defining the Print Horses
Compiling the function. Accept the default values on the Exit Function
Functions Definition panel and change the N on the Submit
generation option to Y. This will save the function and
add it to the joblist for generation. Then select the
Submit model create request (YSBMMDLCRT) option
from the Display Services menu (F17) to submit the
generation and compilation for the function and the
Query access path.
Testing the Once the program has compiled, call it from any
Program command line. Various messages relating to the
execution of the Query access path (via the OS/400
Open Query File (OPNQRYF)) command are displayed
while the report is produced. A sample report listing
data entered with the Edit Horse and Edit Race and
Entries programs follows.
Final totals
Total number of horses : 3
Total horse value . . . : 11500.00
* * END OF REPORT * *