Sample Report
The following example demonstrates a simple report using Report-Writer. This report specification was created with a text editor, stored within the database with the sreport command, and run with the report command.
The report shows a titled listing of data from an existing table, edat in a database. The jobcat column is displayed only once for each job category value.
/* Sample report */
.NAME jobcat
.OUTPUT jobcat.out
.DATA edat
.SORT jobcat, name
.HEADER REPORT
.NEWLINE 2
.CENTER
.PRINT 'Sample Report'
.NEWLINE 2
.HEADER jobcat
.TFORMAT jobcat(' zzzz ')
.DETAIL
.PRINT jobcat(b8), name(c15), dept,
code, age, sales(f12.3)
.NEWLINE
The report output looks like this:
Sample Report
10 Adams,Joe toy 0 22 10500.000
Green,James toy 0 34 43645.000
Smith,Tony acct 0 48 8690.000
20 Davis,Miles music 0 56 234987.000
Tanhous,Karl music 0 20 18765.000
30 Jones,Mary acct 1 34 34599.000
Maney,Sikkim none 1 51 15333.000
Mellon,Tim toy 0 24 45098.000
Mellon,Tim any 0 44 67876.000
Norris,Bill acct 0 22 23988.000
This list briefly explains each statement's function:
• The .name statement gives a name to the report, which is placed in the Reports Catalog by the sreport facility and is used by the report command to locate the report specifications.
• The .data statement identifies an existing table or view in the database that contains the data to report.
• The .sort statement indicates the order the data is to be displayed on the report.
• The .header report statement begins the section of Report-Writer statements to be performed at the start of the report.
• The .newline, .center, and .print statements are used in positioning and printing a title.
• The .header jobcat statement begins the section of Report-Writer statements to be performed any time the value in the jobcat column changes. The .tformat statement is used to temporarily change the normal print format of the jobcat column on the next printing of jobcat, which occurs in the .detail section.
Normally jobcat is not printed. Its format is (b8), which means "print 8 blank spaces." The .tformat statement makes a change to the format to enable a one‑time printing of this value, so the actual value of the jobcat column is output. The .detail statement begins the specification of Report-Writer statements to be performed on each row in the data table.
The .print statement within the detail section prints out the values of the columns in the formats given after the column names, or the default format for that type of data item, if no format is specified. The chapter "Report-Writer Expressions and Formats" describes the format specifications that appear in the parentheses following the column names in detail.
This table shows the table definition data on which the report was run:
This table shows the data for the sample report:
Last modified date: 08/28/2024